@oxyhq/services 5.16.44 → 5.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -10
- package/lib/commonjs/core/OxyServices.js +1 -1
- package/lib/commonjs/core/index.js +20 -15
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/core/mixins/OxyServices.auth.js +36 -53
- package/lib/commonjs/core/mixins/OxyServices.auth.js.map +1 -1
- package/lib/commonjs/core/mixins/OxyServices.user.js +10 -17
- package/lib/commonjs/core/mixins/OxyServices.user.js.map +1 -1
- package/lib/commonjs/core/services/TokenService.js +27 -13
- package/lib/commonjs/core/services/TokenService.js.map +1 -1
- package/lib/commonjs/crypto/index.js +0 -16
- package/lib/commonjs/crypto/index.js.map +1 -1
- package/lib/commonjs/crypto/keyManager.js +21 -22
- package/lib/commonjs/crypto/keyManager.js.map +1 -1
- package/lib/commonjs/crypto/polyfill.js +1 -10
- package/lib/commonjs/crypto/polyfill.js.map +1 -1
- package/lib/commonjs/crypto/signatureService.js +18 -32
- package/lib/commonjs/crypto/signatureService.js.map +1 -1
- package/lib/commonjs/index.js +13 -134
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/interfaces.js +0 -7
- package/lib/commonjs/models/interfaces.js.map +1 -1
- package/lib/commonjs/node/index.js +1 -10
- package/lib/commonjs/node/index.js.map +1 -1
- package/lib/commonjs/ui/components/BottomSheetRouter.js +1 -9
- package/lib/commonjs/ui/components/BottomSheetRouter.js.map +1 -1
- package/lib/commonjs/ui/context/OxyContext.js +779 -450
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/commonjs/ui/context/hooks/useAuthOperations.js +551 -0
- package/lib/commonjs/ui/context/hooks/useAuthOperations.js.map +1 -0
- package/lib/commonjs/ui/context/hooks/useDeviceManagement.js +73 -0
- package/lib/commonjs/ui/context/hooks/useDeviceManagement.js.map +1 -0
- package/lib/commonjs/ui/context/hooks/useStorage.js +79 -0
- package/lib/commonjs/ui/context/hooks/useStorage.js.map +1 -0
- package/lib/commonjs/ui/hooks/index.js +0 -20
- package/lib/commonjs/ui/hooks/index.js.map +1 -1
- package/lib/commonjs/ui/hooks/mutations/index.js +0 -12
- package/lib/commonjs/ui/hooks/mutations/index.js.map +1 -1
- package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js +23 -74
- package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/index.js +0 -12
- package/lib/commonjs/ui/hooks/queries/index.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/queryKeys.js +1 -3
- package/lib/commonjs/ui/hooks/queries/queryKeys.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/useAccountQueries.js +28 -64
- package/lib/commonjs/ui/hooks/queries/useAccountQueries.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/useServicesQueries.js +6 -4
- package/lib/commonjs/ui/hooks/queries/useServicesQueries.js.map +1 -1
- package/lib/commonjs/ui/hooks/useDeviceManagement.js +73 -0
- package/lib/commonjs/ui/hooks/useDeviceManagement.js.map +1 -0
- package/lib/commonjs/ui/hooks/useProfileEditing.js +5 -3
- package/lib/commonjs/ui/hooks/useProfileEditing.js.map +1 -1
- package/lib/commonjs/ui/hooks/useSessionManagement.js +284 -0
- package/lib/commonjs/ui/hooks/useSessionManagement.js.map +1 -0
- package/lib/commonjs/ui/index.js +2 -10
- package/lib/commonjs/ui/index.js.map +1 -1
- package/lib/commonjs/ui/navigation/routes.js +1 -5
- package/lib/commonjs/ui/navigation/routes.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountCenterScreen.js +4 -9
- package/lib/commonjs/ui/screens/AccountCenterScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountSettingsScreen.js +19 -37
- package/lib/commonjs/ui/screens/AccountSettingsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountSwitcherScreen.js +5 -5
- package/lib/commonjs/ui/screens/AccountSwitcherScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/OxyAuthScreen.js +15 -2
- package/lib/commonjs/ui/screens/OxyAuthScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/PrivacySettingsScreen.js +97 -76
- package/lib/commonjs/ui/screens/PrivacySettingsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/ProfileScreen.js +6 -6
- package/lib/commonjs/ui/screens/ProfileScreen.js.map +1 -1
- package/lib/commonjs/ui/stores/authStore.js +6 -54
- package/lib/commonjs/ui/stores/authStore.js.map +1 -1
- package/lib/commonjs/ui/styles/spacing.js +2 -54
- package/lib/commonjs/ui/styles/spacing.js.map +1 -1
- package/lib/commonjs/ui/utils/avatarUtils.js +12 -9
- package/lib/commonjs/ui/utils/avatarUtils.js.map +1 -1
- package/lib/commonjs/ui/utils/sessionHelpers.js +1 -7
- package/lib/commonjs/ui/utils/sessionHelpers.js.map +1 -1
- package/lib/commonjs/utils/deviceManager.js +177 -0
- package/lib/commonjs/utils/deviceManager.js.map +1 -0
- package/lib/commonjs/utils/errorUtils.js +0 -13
- package/lib/commonjs/utils/errorUtils.js.map +1 -1
- package/lib/commonjs/utils/index.js +7 -0
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/sessionUtils.js +1 -8
- package/lib/commonjs/utils/sessionUtils.js.map +1 -1
- package/lib/commonjs/utils/validationUtils.js +1 -15
- package/lib/commonjs/utils/validationUtils.js.map +1 -1
- package/lib/module/core/OxyServices.js +1 -1
- package/lib/module/core/index.js +4 -6
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/core/mixins/OxyServices.auth.js +36 -53
- package/lib/module/core/mixins/OxyServices.auth.js.map +1 -1
- package/lib/module/core/mixins/OxyServices.user.js +10 -17
- package/lib/module/core/mixins/OxyServices.user.js.map +1 -1
- package/lib/module/core/services/TokenService.js +27 -13
- package/lib/module/core/services/TokenService.js.map +1 -1
- package/lib/module/crypto/index.js +0 -3
- package/lib/module/crypto/index.js.map +1 -1
- package/lib/module/crypto/keyManager.js +21 -22
- package/lib/module/crypto/keyManager.js.map +1 -1
- package/lib/module/crypto/polyfill.js +1 -2
- package/lib/module/crypto/polyfill.js.map +1 -1
- package/lib/module/crypto/signatureService.js +18 -32
- package/lib/module/crypto/signatureService.js.map +1 -1
- package/lib/module/index.js +7 -19
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/interfaces.js +0 -7
- package/lib/module/models/interfaces.js.map +1 -1
- package/lib/module/node/index.js +0 -3
- package/lib/module/node/index.js.map +1 -1
- package/lib/module/ui/components/BottomSheetRouter.js +2 -6
- package/lib/module/ui/components/BottomSheetRouter.js.map +1 -1
- package/lib/module/ui/context/OxyContext.js +779 -450
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/module/ui/context/hooks/useAuthOperations.js +545 -0
- package/lib/module/ui/context/hooks/useAuthOperations.js.map +1 -0
- package/lib/module/ui/context/hooks/useDeviceManagement.js +68 -0
- package/lib/module/ui/context/hooks/useDeviceManagement.js.map +1 -0
- package/lib/module/ui/context/hooks/useStorage.js +74 -0
- package/lib/module/ui/context/hooks/useStorage.js.map +1 -0
- package/lib/module/ui/hooks/index.js +0 -1
- package/lib/module/ui/hooks/index.js.map +1 -1
- package/lib/module/ui/hooks/mutations/index.js +1 -1
- package/lib/module/ui/hooks/mutations/index.js.map +1 -1
- package/lib/module/ui/hooks/mutations/useAccountMutations.js +21 -71
- package/lib/module/ui/hooks/mutations/useAccountMutations.js.map +1 -1
- package/lib/module/ui/hooks/queries/index.js +1 -1
- package/lib/module/ui/hooks/queries/index.js.map +1 -1
- package/lib/module/ui/hooks/queries/queryKeys.js +1 -3
- package/lib/module/ui/hooks/queries/queryKeys.js.map +1 -1
- package/lib/module/ui/hooks/queries/useAccountQueries.js +27 -61
- package/lib/module/ui/hooks/queries/useAccountQueries.js.map +1 -1
- package/lib/module/ui/hooks/queries/useServicesQueries.js +6 -4
- package/lib/module/ui/hooks/queries/useServicesQueries.js.map +1 -1
- package/lib/module/ui/hooks/useDeviceManagement.js +68 -0
- package/lib/module/ui/hooks/useDeviceManagement.js.map +1 -0
- package/lib/module/ui/hooks/useProfileEditing.js +5 -3
- package/lib/module/ui/hooks/useProfileEditing.js.map +1 -1
- package/lib/module/ui/hooks/useSessionManagement.js +279 -0
- package/lib/module/ui/hooks/useSessionManagement.js.map +1 -0
- package/lib/module/ui/index.js +1 -2
- package/lib/module/ui/index.js.map +1 -1
- package/lib/module/ui/navigation/routes.js +1 -5
- package/lib/module/ui/navigation/routes.js.map +1 -1
- package/lib/module/ui/screens/AccountCenterScreen.js +4 -9
- package/lib/module/ui/screens/AccountCenterScreen.js.map +1 -1
- package/lib/module/ui/screens/AccountSettingsScreen.js +19 -37
- package/lib/module/ui/screens/AccountSettingsScreen.js.map +1 -1
- package/lib/module/ui/screens/AccountSwitcherScreen.js +5 -5
- package/lib/module/ui/screens/AccountSwitcherScreen.js.map +1 -1
- package/lib/module/ui/screens/OxyAuthScreen.js +15 -2
- package/lib/module/ui/screens/OxyAuthScreen.js.map +1 -1
- package/lib/module/ui/screens/PrivacySettingsScreen.js +98 -77
- package/lib/module/ui/screens/PrivacySettingsScreen.js.map +1 -1
- package/lib/module/ui/screens/ProfileScreen.js +6 -6
- package/lib/module/ui/screens/ProfileScreen.js.map +1 -1
- package/lib/module/ui/stores/authStore.js +6 -54
- package/lib/module/ui/stores/authStore.js.map +1 -1
- package/lib/module/ui/styles/spacing.js +2 -6
- package/lib/module/ui/styles/spacing.js.map +1 -1
- package/lib/module/ui/utils/avatarUtils.js +12 -9
- package/lib/module/ui/utils/avatarUtils.js.map +1 -1
- package/lib/module/ui/utils/sessionHelpers.js +1 -7
- package/lib/module/ui/utils/sessionHelpers.js.map +1 -1
- package/lib/module/utils/deviceManager.js +171 -0
- package/lib/module/utils/deviceManager.js.map +1 -0
- package/lib/module/utils/errorUtils.js +0 -7
- package/lib/module/utils/errorUtils.js.map +1 -1
- package/lib/module/utils/index.js +1 -2
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/sessionUtils.js +1 -8
- package/lib/module/utils/sessionUtils.js.map +1 -1
- package/lib/module/utils/validationUtils.js +0 -13
- package/lib/module/utils/validationUtils.js.map +1 -1
- package/lib/typescript/core/OxyServices.d.ts +1 -1
- package/lib/typescript/core/index.d.ts +3 -3
- package/lib/typescript/core/index.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.auth.d.ts +21 -44
- package/lib/typescript/core/mixins/OxyServices.auth.d.ts.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.user.d.ts +1 -0
- package/lib/typescript/core/mixins/OxyServices.user.d.ts.map +1 -1
- package/lib/typescript/core/mixins/index.d.ts +8 -15
- package/lib/typescript/core/mixins/index.d.ts.map +1 -1
- package/lib/typescript/core/services/TokenService.d.ts.map +1 -1
- package/lib/typescript/crypto/index.d.ts +0 -1
- package/lib/typescript/crypto/index.d.ts.map +1 -1
- package/lib/typescript/crypto/keyManager.d.ts +2 -15
- package/lib/typescript/crypto/keyManager.d.ts.map +1 -1
- package/lib/typescript/crypto/polyfill.d.ts +1 -2
- package/lib/typescript/crypto/polyfill.d.ts.map +1 -1
- package/lib/typescript/crypto/signatureService.d.ts +0 -13
- package/lib/typescript/crypto/signatureService.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +7 -12
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/models/interfaces.d.ts +36 -5
- package/lib/typescript/models/interfaces.d.ts.map +1 -1
- package/lib/typescript/models/session.d.ts +18 -3
- package/lib/typescript/models/session.d.ts.map +1 -1
- package/lib/typescript/node/index.d.ts +0 -1
- package/lib/typescript/node/index.d.ts.map +1 -1
- package/lib/typescript/ui/components/BottomSheetRouter.d.ts +0 -5
- package/lib/typescript/ui/components/BottomSheetRouter.d.ts.map +1 -1
- package/lib/typescript/ui/components/TextField/Addons/Outline.d.ts +2 -2
- package/lib/typescript/ui/components/TextField/helpers.d.ts +2 -2
- package/lib/typescript/ui/components/TextField/types.d.ts +0 -1
- package/lib/typescript/ui/components/TextField/types.d.ts.map +1 -1
- package/lib/typescript/ui/context/OxyContext.d.ts +28 -5
- package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/ui/context/hooks/useAuthOperations.d.ts +59 -0
- package/lib/typescript/ui/context/hooks/useAuthOperations.d.ts.map +1 -0
- package/lib/typescript/ui/context/hooks/useDeviceManagement.d.ts +27 -0
- package/lib/typescript/ui/context/hooks/useDeviceManagement.d.ts.map +1 -0
- package/lib/typescript/ui/context/hooks/useStorage.d.ts +22 -0
- package/lib/typescript/ui/context/hooks/useStorage.d.ts.map +1 -0
- package/lib/typescript/ui/hooks/index.d.ts +0 -1
- package/lib/typescript/ui/hooks/index.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/mutations/index.d.ts +1 -1
- package/lib/typescript/ui/hooks/mutations/index.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/mutations/useAccountMutations.d.ts +8 -19
- package/lib/typescript/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/mutations/useServicesMutations.d.ts +1 -1
- package/lib/typescript/ui/hooks/mutations/useServicesMutations.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/queries/index.d.ts +1 -1
- package/lib/typescript/ui/hooks/queries/index.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/queries/queryKeys.d.ts +0 -2
- package/lib/typescript/ui/hooks/queries/queryKeys.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/queries/useAccountQueries.d.ts +5 -17
- package/lib/typescript/ui/hooks/queries/useAccountQueries.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/queries/useServicesQueries.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/useDeviceManagement.d.ts +27 -0
- package/lib/typescript/ui/hooks/useDeviceManagement.d.ts.map +1 -0
- package/lib/typescript/ui/hooks/useProfileEditing.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/useSessionManagement.d.ts +41 -0
- package/lib/typescript/ui/hooks/useSessionManagement.d.ts.map +1 -0
- package/lib/typescript/ui/index.d.ts +0 -1
- package/lib/typescript/ui/index.d.ts.map +1 -1
- package/lib/typescript/ui/navigation/routes.d.ts +1 -1
- package/lib/typescript/ui/navigation/routes.d.ts.map +1 -1
- package/lib/typescript/ui/screens/AccountCenterScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/AccountSettingsScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/OxyAuthScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/PrivacySettingsScreen.d.ts.map +1 -1
- package/lib/typescript/ui/stores/authStore.d.ts +1 -8
- package/lib/typescript/ui/stores/authStore.d.ts.map +1 -1
- package/lib/typescript/ui/styles/spacing.d.ts +0 -5
- package/lib/typescript/ui/styles/spacing.d.ts.map +1 -1
- package/lib/typescript/ui/utils/avatarUtils.d.ts +4 -1
- package/lib/typescript/ui/utils/avatarUtils.d.ts.map +1 -1
- package/lib/typescript/ui/utils/sessionHelpers.d.ts +0 -1
- package/lib/typescript/ui/utils/sessionHelpers.d.ts.map +1 -1
- package/lib/typescript/utils/deviceManager.d.ts +66 -0
- package/lib/typescript/utils/deviceManager.d.ts.map +1 -0
- package/lib/typescript/utils/errorUtils.d.ts +0 -6
- package/lib/typescript/utils/errorUtils.d.ts.map +1 -1
- package/lib/typescript/utils/index.d.ts +2 -0
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/lib/typescript/utils/sessionUtils.d.ts.map +1 -1
- package/lib/typescript/utils/validationUtils.d.ts +0 -8
- package/lib/typescript/utils/validationUtils.d.ts.map +1 -1
- package/package.json +1 -6
- package/src/core/OxyServices.ts +1 -1
- package/src/core/index.ts +5 -8
- package/src/core/mixins/OxyServices.auth.ts +44 -87
- package/src/core/mixins/OxyServices.user.ts +10 -18
- package/src/core/services/TokenService.ts +27 -16
- package/src/crypto/index.ts +1 -3
- package/src/crypto/keyManager.ts +21 -30
- package/src/crypto/polyfill.ts +1 -2
- package/src/crypto/signatureService.ts +19 -43
- package/src/index.ts +6 -41
- package/src/models/interfaces.ts +39 -12
- package/src/models/session.ts +19 -7
- package/src/node/index.ts +0 -3
- package/src/ui/components/BottomSheetRouter.tsx +1 -6
- package/src/ui/components/TextField/Addons/Outline.tsx +2 -2
- package/src/ui/components/TextField/helpers.tsx +2 -2
- package/src/ui/components/TextField/types.tsx +1 -1
- package/src/ui/context/OxyContext.tsx +831 -463
- package/src/ui/context/hooks/useAuthOperations.ts +620 -0
- package/src/ui/context/hooks/useDeviceManagement.ts +108 -0
- package/src/ui/context/hooks/useStorage.ts +104 -0
- package/src/ui/hooks/index.ts +1 -2
- package/src/ui/hooks/mutations/index.ts +0 -2
- package/src/ui/hooks/mutations/useAccountMutations.ts +20 -66
- package/src/ui/hooks/queries/index.ts +0 -2
- package/src/ui/hooks/queries/queryKeys.ts +0 -2
- package/src/ui/hooks/queries/useAccountQueries.ts +19 -53
- package/src/ui/hooks/queries/useServicesQueries.ts +5 -5
- package/src/ui/hooks/useDeviceManagement.ts +108 -0
- package/src/ui/hooks/useProfileEditing.ts +3 -3
- package/src/ui/hooks/useSessionManagement.ts +405 -0
- package/src/ui/index.ts +1 -2
- package/src/ui/navigation/routes.ts +2 -6
- package/src/ui/screens/AccountCenterScreen.tsx +4 -9
- package/src/ui/screens/AccountSettingsScreen.tsx +31 -49
- package/src/ui/screens/AccountSwitcherScreen.tsx +5 -5
- package/src/ui/screens/OxyAuthScreen.tsx +19 -4
- package/src/ui/screens/PrivacySettingsScreen.tsx +101 -67
- package/src/ui/screens/ProfileScreen.tsx +10 -10
- package/src/ui/stores/authStore.ts +8 -48
- package/src/ui/styles/spacing.ts +2 -15
- package/src/ui/utils/avatarUtils.ts +21 -19
- package/src/ui/utils/sessionHelpers.ts +0 -7
- package/src/utils/__tests__/validationUtils.test.ts +1 -16
- package/src/utils/deviceManager.ts +198 -0
- package/src/utils/errorUtils.ts +1 -8
- package/src/utils/index.ts +2 -1
- package/src/utils/sessionUtils.ts +0 -8
- package/src/utils/validationUtils.ts +0 -12
- package/lib/commonjs/adapters/expo/crypto.js +0 -56
- package/lib/commonjs/adapters/expo/crypto.js.map +0 -1
- package/lib/commonjs/adapters/expo/fetch.js +0 -30
- package/lib/commonjs/adapters/expo/fetch.js.map +0 -1
- package/lib/commonjs/adapters/expo/index.js +0 -48
- package/lib/commonjs/adapters/expo/index.js.map +0 -1
- package/lib/commonjs/adapters/expo/storage.js +0 -201
- package/lib/commonjs/adapters/expo/storage.js.map +0 -1
- package/lib/commonjs/adapters/index.js +0 -48
- package/lib/commonjs/adapters/index.js.map +0 -1
- package/lib/commonjs/adapters/node/crypto.js +0 -40
- package/lib/commonjs/adapters/node/crypto.js.map +0 -1
- package/lib/commonjs/adapters/node/fetch.js +0 -62
- package/lib/commonjs/adapters/node/fetch.js.map +0 -1
- package/lib/commonjs/adapters/node/index.js +0 -34
- package/lib/commonjs/adapters/node/index.js.map +0 -1
- package/lib/commonjs/adapters/node/storage.js +0 -163
- package/lib/commonjs/adapters/node/storage.js.map +0 -1
- package/lib/commonjs/core/identity-session/DeviceManager.js +0 -237
- package/lib/commonjs/core/identity-session/DeviceManager.js.map +0 -1
- package/lib/commonjs/core/identity-session/INTEGRATION_GUIDE.md +0 -287
- package/lib/commonjs/core/identity-session/IdentityManager.js +0 -400
- package/lib/commonjs/core/identity-session/IdentityManager.js.map +0 -1
- package/lib/commonjs/core/identity-session/IdentitySessionCore.js +0 -394
- package/lib/commonjs/core/identity-session/IdentitySessionCore.js.map +0 -1
- package/lib/commonjs/core/identity-session/RefreshManager.js +0 -137
- package/lib/commonjs/core/identity-session/RefreshManager.js.map +0 -1
- package/lib/commonjs/core/identity-session/SessionManager.js +0 -427
- package/lib/commonjs/core/identity-session/SessionManager.js.map +0 -1
- package/lib/commonjs/core/identity-session/createIdentitySessionCore.js +0 -24
- package/lib/commonjs/core/identity-session/createIdentitySessionCore.js.map +0 -1
- package/lib/commonjs/core/identity-session/errors.js +0 -176
- package/lib/commonjs/core/identity-session/errors.js.map +0 -1
- package/lib/commonjs/core/identity-session/index.js +0 -80
- package/lib/commonjs/core/identity-session/index.js.map +0 -1
- package/lib/commonjs/core/identity-session/types.js +0 -2
- package/lib/commonjs/core/identity-session/types.js.map +0 -1
- package/lib/commonjs/crypto/README.md +0 -142
- package/lib/commonjs/crypto/core.js +0 -147
- package/lib/commonjs/crypto/core.js.map +0 -1
- package/lib/commonjs/node/signatureService.js +0 -107
- package/lib/commonjs/node/signatureService.js.map +0 -1
- package/lib/commonjs/ui/hooks/auth/index.js +0 -37
- package/lib/commonjs/ui/hooks/auth/index.js.map +0 -1
- package/lib/commonjs/ui/hooks/auth/useUsernameValidation.js +0 -171
- package/lib/commonjs/ui/hooks/auth/useUsernameValidation.js.map +0 -1
- package/lib/commonjs/ui/hooks/useAvatarPicker.js +0 -52
- package/lib/commonjs/ui/hooks/useAvatarPicker.js.map +0 -1
- package/lib/commonjs/ui/hooks/useIdentityTransfer.js +0 -125
- package/lib/commonjs/ui/hooks/useIdentityTransfer.js.map +0 -1
- package/lib/commonjs/ui/hooks/useTransferCodesPersistence.js +0 -81
- package/lib/commonjs/ui/hooks/useTransferCodesPersistence.js.map +0 -1
- package/lib/commonjs/ui/hooks/useTransferQueries.js +0 -85
- package/lib/commonjs/ui/hooks/useTransferQueries.js.map +0 -1
- package/lib/commonjs/ui/stores/transferStore.js +0 -157
- package/lib/commonjs/ui/stores/transferStore.js.map +0 -1
- package/lib/module/adapters/expo/crypto.js +0 -51
- package/lib/module/adapters/expo/crypto.js.map +0 -1
- package/lib/module/adapters/expo/fetch.js +0 -26
- package/lib/module/adapters/expo/fetch.js.map +0 -1
- package/lib/module/adapters/expo/index.js +0 -45
- package/lib/module/adapters/expo/index.js.map +0 -1
- package/lib/module/adapters/expo/storage.js +0 -198
- package/lib/module/adapters/expo/storage.js.map +0 -1
- package/lib/module/adapters/index.js +0 -45
- package/lib/module/adapters/index.js.map +0 -1
- package/lib/module/adapters/node/crypto.js +0 -36
- package/lib/module/adapters/node/crypto.js.map +0 -1
- package/lib/module/adapters/node/fetch.js +0 -57
- package/lib/module/adapters/node/fetch.js.map +0 -1
- package/lib/module/adapters/node/index.js +0 -31
- package/lib/module/adapters/node/index.js.map +0 -1
- package/lib/module/adapters/node/storage.js +0 -159
- package/lib/module/adapters/node/storage.js.map +0 -1
- package/lib/module/core/identity-session/DeviceManager.js +0 -232
- package/lib/module/core/identity-session/DeviceManager.js.map +0 -1
- package/lib/module/core/identity-session/INTEGRATION_GUIDE.md +0 -287
- package/lib/module/core/identity-session/IdentityManager.js +0 -395
- package/lib/module/core/identity-session/IdentityManager.js.map +0 -1
- package/lib/module/core/identity-session/IdentitySessionCore.js +0 -390
- package/lib/module/core/identity-session/IdentitySessionCore.js.map +0 -1
- package/lib/module/core/identity-session/RefreshManager.js +0 -132
- package/lib/module/core/identity-session/RefreshManager.js.map +0 -1
- package/lib/module/core/identity-session/SessionManager.js +0 -422
- package/lib/module/core/identity-session/SessionManager.js.map +0 -1
- package/lib/module/core/identity-session/createIdentitySessionCore.js +0 -21
- package/lib/module/core/identity-session/createIdentitySessionCore.js.map +0 -1
- package/lib/module/core/identity-session/errors.js +0 -170
- package/lib/module/core/identity-session/errors.js.map +0 -1
- package/lib/module/core/identity-session/index.js +0 -17
- package/lib/module/core/identity-session/index.js.map +0 -1
- package/lib/module/core/identity-session/types.js +0 -2
- package/lib/module/core/identity-session/types.js.map +0 -1
- package/lib/module/crypto/README.md +0 -142
- package/lib/module/crypto/core.js +0 -133
- package/lib/module/crypto/core.js.map +0 -1
- package/lib/module/node/signatureService.js +0 -101
- package/lib/module/node/signatureService.js.map +0 -1
- package/lib/module/ui/hooks/auth/index.js +0 -7
- package/lib/module/ui/hooks/auth/index.js.map +0 -1
- package/lib/module/ui/hooks/auth/useUsernameValidation.js +0 -167
- package/lib/module/ui/hooks/auth/useUsernameValidation.js.map +0 -1
- package/lib/module/ui/hooks/useAvatarPicker.js +0 -48
- package/lib/module/ui/hooks/useAvatarPicker.js.map +0 -1
- package/lib/module/ui/hooks/useIdentityTransfer.js +0 -121
- package/lib/module/ui/hooks/useIdentityTransfer.js.map +0 -1
- package/lib/module/ui/hooks/useTransferCodesPersistence.js +0 -77
- package/lib/module/ui/hooks/useTransferCodesPersistence.js.map +0 -1
- package/lib/module/ui/hooks/useTransferQueries.js +0 -80
- package/lib/module/ui/hooks/useTransferQueries.js.map +0 -1
- package/lib/module/ui/stores/transferStore.js +0 -152
- package/lib/module/ui/stores/transferStore.js.map +0 -1
- package/lib/typescript/adapters/expo/crypto.d.ts +0 -17
- package/lib/typescript/adapters/expo/crypto.d.ts.map +0 -1
- package/lib/typescript/adapters/expo/fetch.d.ts +0 -16
- package/lib/typescript/adapters/expo/fetch.d.ts.map +0 -1
- package/lib/typescript/adapters/expo/index.d.ts +0 -23
- package/lib/typescript/adapters/expo/index.d.ts.map +0 -1
- package/lib/typescript/adapters/expo/storage.d.ts +0 -23
- package/lib/typescript/adapters/expo/storage.d.ts.map +0 -1
- package/lib/typescript/adapters/index.d.ts +0 -17
- package/lib/typescript/adapters/index.d.ts.map +0 -1
- package/lib/typescript/adapters/node/crypto.d.ts +0 -17
- package/lib/typescript/adapters/node/crypto.d.ts.map +0 -1
- package/lib/typescript/adapters/node/fetch.d.ts +0 -16
- package/lib/typescript/adapters/node/fetch.d.ts.map +0 -1
- package/lib/typescript/adapters/node/index.d.ts +0 -23
- package/lib/typescript/adapters/node/index.d.ts.map +0 -1
- package/lib/typescript/adapters/node/storage.d.ts +0 -23
- package/lib/typescript/adapters/node/storage.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/DeviceManager.d.ts +0 -64
- package/lib/typescript/core/identity-session/DeviceManager.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/IdentityManager.d.ts +0 -88
- package/lib/typescript/core/identity-session/IdentityManager.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/IdentitySessionCore.d.ts +0 -141
- package/lib/typescript/core/identity-session/IdentitySessionCore.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/RefreshManager.d.ts +0 -36
- package/lib/typescript/core/identity-session/RefreshManager.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/SessionManager.d.ts +0 -104
- package/lib/typescript/core/identity-session/SessionManager.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/createIdentitySessionCore.d.ts +0 -11
- package/lib/typescript/core/identity-session/createIdentitySessionCore.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/errors.d.ts +0 -63
- package/lib/typescript/core/identity-session/errors.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/index.d.ts +0 -14
- package/lib/typescript/core/identity-session/index.d.ts.map +0 -1
- package/lib/typescript/core/identity-session/types.d.ts +0 -196
- package/lib/typescript/core/identity-session/types.d.ts.map +0 -1
- package/lib/typescript/crypto/core.d.ts +0 -56
- package/lib/typescript/crypto/core.d.ts.map +0 -1
- package/lib/typescript/node/signatureService.d.ts +0 -55
- package/lib/typescript/node/signatureService.d.ts.map +0 -1
- package/lib/typescript/ui/hooks/auth/index.d.ts +0 -6
- package/lib/typescript/ui/hooks/auth/index.d.ts.map +0 -1
- package/lib/typescript/ui/hooks/auth/useUsernameValidation.d.ts +0 -32
- package/lib/typescript/ui/hooks/auth/useUsernameValidation.d.ts.map +0 -1
- package/lib/typescript/ui/hooks/useAvatarPicker.d.ts +0 -18
- package/lib/typescript/ui/hooks/useAvatarPicker.d.ts.map +0 -1
- package/lib/typescript/ui/hooks/useIdentityTransfer.d.ts +0 -24
- package/lib/typescript/ui/hooks/useIdentityTransfer.d.ts.map +0 -1
- package/lib/typescript/ui/hooks/useTransferCodesPersistence.d.ts +0 -6
- package/lib/typescript/ui/hooks/useTransferCodesPersistence.d.ts.map +0 -1
- package/lib/typescript/ui/hooks/useTransferQueries.d.ts +0 -26
- package/lib/typescript/ui/hooks/useTransferQueries.d.ts.map +0 -1
- package/lib/typescript/ui/stores/transferStore.d.ts +0 -36
- package/lib/typescript/ui/stores/transferStore.d.ts.map +0 -1
- package/src/adapters/expo/crypto.ts +0 -55
- package/src/adapters/expo/fetch.ts +0 -28
- package/src/adapters/expo/index.ts +0 -51
- package/src/adapters/expo/storage.ts +0 -228
- package/src/adapters/index.ts +0 -48
- package/src/adapters/node/crypto.ts +0 -39
- package/src/adapters/node/fetch.ts +0 -59
- package/src/adapters/node/index.ts +0 -37
- package/src/adapters/node/storage.ts +0 -170
- package/src/core/identity-session/DeviceManager.ts +0 -273
- package/src/core/identity-session/INTEGRATION_GUIDE.md +0 -287
- package/src/core/identity-session/IdentityManager.ts +0 -474
- package/src/core/identity-session/IdentitySessionCore.ts +0 -464
- package/src/core/identity-session/RefreshManager.ts +0 -189
- package/src/core/identity-session/SessionManager.ts +0 -500
- package/src/core/identity-session/createIdentitySessionCore.ts +0 -19
- package/src/core/identity-session/errors.ts +0 -197
- package/src/core/identity-session/index.ts +0 -15
- package/src/core/identity-session/types.ts +0 -188
- package/src/crypto/README.md +0 -142
- package/src/crypto/__tests__/core.test.ts +0 -203
- package/src/crypto/core.ts +0 -142
- package/src/node/signatureService.ts +0 -126
- package/src/ui/hooks/auth/index.ts +0 -9
- package/src/ui/hooks/auth/useUsernameValidation.ts +0 -177
- package/src/ui/hooks/useAvatarPicker.ts +0 -62
- package/src/ui/hooks/useIdentityTransfer.ts +0 -135
- package/src/ui/hooks/useTransferCodesPersistence.ts +0 -80
- package/src/ui/hooks/useTransferQueries.ts +0 -102
- package/src/ui/stores/transferStore.ts +0 -201
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the shared crypto core module
|
|
3
|
-
* These tests verify that signature verification is consistent across platforms
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
verifySignatureCore,
|
|
8
|
-
isValidPublicKey,
|
|
9
|
-
isValidPrivateKey,
|
|
10
|
-
isTimestampFresh,
|
|
11
|
-
buildAuthMessage,
|
|
12
|
-
buildRegistrationMessage,
|
|
13
|
-
buildRequestMessage,
|
|
14
|
-
shortenPublicKey,
|
|
15
|
-
derivePublicKey,
|
|
16
|
-
getEllipticCurve,
|
|
17
|
-
CHALLENGE_TTL_MS,
|
|
18
|
-
MAX_SIGNATURE_AGE_MS,
|
|
19
|
-
} from '../core';
|
|
20
|
-
|
|
21
|
-
describe('Crypto Core Module', () => {
|
|
22
|
-
// Test key pair (for testing only - never use in production)
|
|
23
|
-
const testPrivateKey = '1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef';
|
|
24
|
-
// Public key derived from the private key above
|
|
25
|
-
const testPublicKey = '04bb50e2d89a4ed70663d080659fe0ad4b9bc3e06c17a227433966cb59ceee020decddbf6e00192011648d13b1c00af770c0c1bb609d4d3a5c98a43772e0e18ef4';
|
|
26
|
-
|
|
27
|
-
describe('Public/Private Key Validation', () => {
|
|
28
|
-
it('should validate correct public keys', () => {
|
|
29
|
-
expect(isValidPublicKey(testPublicKey)).toBe(true);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should reject invalid public keys', () => {
|
|
33
|
-
expect(isValidPublicKey('invalid')).toBe(false);
|
|
34
|
-
expect(isValidPublicKey('')).toBe(false);
|
|
35
|
-
expect(isValidPublicKey('1234')).toBe(false);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('should validate correct private keys', () => {
|
|
39
|
-
expect(isValidPrivateKey(testPrivateKey)).toBe(true);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should reject invalid private keys', () => {
|
|
43
|
-
expect(isValidPrivateKey('invalid')).toBe(false);
|
|
44
|
-
expect(isValidPrivateKey('')).toBe(false);
|
|
45
|
-
expect(isValidPrivateKey('1234')).toBe(false);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should derive public key from private key', () => {
|
|
49
|
-
const derived = derivePublicKey(testPrivateKey);
|
|
50
|
-
expect(derived).toBe(testPublicKey);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('Utility Functions', () => {
|
|
55
|
-
it('should shorten public keys correctly', () => {
|
|
56
|
-
const shortened = shortenPublicKey(testPublicKey);
|
|
57
|
-
expect(shortened).toBe('04bb50e2...e0e18ef4');
|
|
58
|
-
expect(shortened.length).toBeLessThan(testPublicKey.length);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should not shorten already short keys', () => {
|
|
62
|
-
const shortKey = '1234567890';
|
|
63
|
-
expect(shortenPublicKey(shortKey)).toBe(shortKey);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('Timestamp Validation', () => {
|
|
68
|
-
it('should accept fresh timestamps', () => {
|
|
69
|
-
const now = Date.now();
|
|
70
|
-
expect(isTimestampFresh(now)).toBe(true);
|
|
71
|
-
expect(isTimestampFresh(now - 1000)).toBe(true); // 1 second ago
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should reject old timestamps', () => {
|
|
75
|
-
const old = Date.now() - (MAX_SIGNATURE_AGE_MS + 1000);
|
|
76
|
-
expect(isTimestampFresh(old)).toBe(false);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should respect custom max age', () => {
|
|
80
|
-
const timestamp = Date.now() - 10000; // 10 seconds ago
|
|
81
|
-
expect(isTimestampFresh(timestamp, 5000)).toBe(false); // max 5 seconds
|
|
82
|
-
expect(isTimestampFresh(timestamp, 15000)).toBe(true); // max 15 seconds
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('Message Building', () => {
|
|
87
|
-
it('should build auth messages correctly', () => {
|
|
88
|
-
const publicKey = 'abc123';
|
|
89
|
-
const challenge = 'challenge456';
|
|
90
|
-
const timestamp = 1234567890;
|
|
91
|
-
|
|
92
|
-
const message = buildAuthMessage(publicKey, challenge, timestamp);
|
|
93
|
-
expect(message).toBe('auth:abc123:challenge456:1234567890');
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should build registration messages correctly', () => {
|
|
97
|
-
const publicKey = 'abc123';
|
|
98
|
-
const timestamp = 1234567890;
|
|
99
|
-
|
|
100
|
-
const message = buildRegistrationMessage(publicKey, timestamp);
|
|
101
|
-
expect(message).toBe('oxy:register:abc123:1234567890');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should build request messages with canonical data', () => {
|
|
105
|
-
const publicKey = 'abc123';
|
|
106
|
-
const timestamp = 1234567890;
|
|
107
|
-
const data = {
|
|
108
|
-
username: 'testuser',
|
|
109
|
-
action: 'update',
|
|
110
|
-
id: 42,
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const message = buildRequestMessage(publicKey, timestamp, data);
|
|
114
|
-
|
|
115
|
-
// Keys should be sorted alphabetically
|
|
116
|
-
expect(message).toContain('action:"update"');
|
|
117
|
-
expect(message).toContain('id:42');
|
|
118
|
-
expect(message).toContain('username:"testuser"');
|
|
119
|
-
expect(message).toContain('request:abc123:1234567890:');
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('should produce consistent canonical strings', () => {
|
|
123
|
-
const publicKey = 'key';
|
|
124
|
-
const timestamp = 1000;
|
|
125
|
-
|
|
126
|
-
// Same data, different order
|
|
127
|
-
const data1 = { b: 2, a: 1, c: 3 };
|
|
128
|
-
const data2 = { c: 3, a: 1, b: 2 };
|
|
129
|
-
|
|
130
|
-
const message1 = buildRequestMessage(publicKey, timestamp, data1);
|
|
131
|
-
const message2 = buildRequestMessage(publicKey, timestamp, data2);
|
|
132
|
-
|
|
133
|
-
expect(message1).toBe(message2);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
describe('Signature Verification Core', () => {
|
|
138
|
-
it('should verify valid signatures', () => {
|
|
139
|
-
const ec = getEllipticCurve();
|
|
140
|
-
const keyPair = ec.keyFromPrivate(testPrivateKey);
|
|
141
|
-
|
|
142
|
-
// Create a test message hash
|
|
143
|
-
const messageHash = 'abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890';
|
|
144
|
-
|
|
145
|
-
// Sign it
|
|
146
|
-
const signature = keyPair.sign(messageHash);
|
|
147
|
-
const signatureHex = signature.toDER('hex');
|
|
148
|
-
|
|
149
|
-
// Verify it
|
|
150
|
-
const isValid = verifySignatureCore(messageHash, signatureHex, testPublicKey);
|
|
151
|
-
expect(isValid).toBe(true);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('should reject invalid signatures', () => {
|
|
155
|
-
const messageHash = 'abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890';
|
|
156
|
-
const invalidSignature = '1234567890abcdef';
|
|
157
|
-
|
|
158
|
-
const isValid = verifySignatureCore(messageHash, invalidSignature, testPublicKey);
|
|
159
|
-
expect(isValid).toBe(false);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('should reject signatures with wrong public key', () => {
|
|
163
|
-
const ec = getEllipticCurve();
|
|
164
|
-
const keyPair = ec.keyFromPrivate(testPrivateKey);
|
|
165
|
-
|
|
166
|
-
const messageHash = 'abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890';
|
|
167
|
-
const signature = keyPair.sign(messageHash);
|
|
168
|
-
const signatureHex = signature.toDER('hex');
|
|
169
|
-
|
|
170
|
-
// Use a different public key
|
|
171
|
-
const wrongPublicKey = '04' + 'a'.repeat(128);
|
|
172
|
-
|
|
173
|
-
const isValid = verifySignatureCore(messageHash, signatureHex, wrongPublicKey);
|
|
174
|
-
expect(isValid).toBe(false);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe('Constants', () => {
|
|
179
|
-
it('should export correct TTL constants', () => {
|
|
180
|
-
expect(CHALLENGE_TTL_MS).toBe(5 * 60 * 1000); // 5 minutes
|
|
181
|
-
expect(MAX_SIGNATURE_AGE_MS).toBe(5 * 60 * 1000); // 5 minutes
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
describe('Elliptic Curve', () => {
|
|
186
|
-
it('should provide secp256k1 curve', () => {
|
|
187
|
-
const ec = getEllipticCurve();
|
|
188
|
-
expect(ec).toBeDefined();
|
|
189
|
-
expect(ec.curve.type).toBe('short');
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it('should generate valid key pairs', () => {
|
|
193
|
-
const ec = getEllipticCurve();
|
|
194
|
-
const keyPair = ec.genKeyPair();
|
|
195
|
-
|
|
196
|
-
const privateKey = keyPair.getPrivate('hex');
|
|
197
|
-
const publicKey = keyPair.getPublic('hex');
|
|
198
|
-
|
|
199
|
-
expect(isValidPrivateKey(privateKey)).toBe(true);
|
|
200
|
-
expect(isValidPublicKey(publicKey)).toBe(true);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
});
|
package/src/crypto/core.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core Cryptographic Functions - Platform Agnostic
|
|
3
|
-
*
|
|
4
|
-
* This module contains the core signature verification logic
|
|
5
|
-
* that is shared between all platforms (React Native, Node.js, Web).
|
|
6
|
-
* Platform-specific implementations (hashing, random generation) are injected.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { ec as EC } from 'elliptic';
|
|
10
|
-
import type { EC as ECType } from 'elliptic';
|
|
11
|
-
|
|
12
|
-
const ec = new EC('secp256k1');
|
|
13
|
-
|
|
14
|
-
// Constants for signature validation
|
|
15
|
-
export const CHALLENGE_TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
16
|
-
export const MAX_SIGNATURE_AGE_MS = 5 * 60 * 1000; // 5 minutes
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Core signature verification using elliptic curve
|
|
20
|
-
* This is platform-agnostic and works everywhere
|
|
21
|
-
*/
|
|
22
|
-
export function verifySignatureCore(
|
|
23
|
-
messageHash: string,
|
|
24
|
-
signature: string,
|
|
25
|
-
publicKey: string
|
|
26
|
-
): boolean {
|
|
27
|
-
try {
|
|
28
|
-
const key = ec.keyFromPublic(publicKey, 'hex');
|
|
29
|
-
return key.verify(messageHash, signature);
|
|
30
|
-
} catch {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Validate that a string is a valid public key
|
|
37
|
-
*/
|
|
38
|
-
export function isValidPublicKey(publicKey: string): boolean {
|
|
39
|
-
// Reject empty strings
|
|
40
|
-
if (!publicKey || publicKey.trim().length === 0) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
ec.keyFromPublic(publicKey, 'hex');
|
|
46
|
-
return true;
|
|
47
|
-
} catch {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Validate that a string is a valid private key
|
|
54
|
-
*/
|
|
55
|
-
export function isValidPrivateKey(privateKey: string): boolean {
|
|
56
|
-
// Reject empty strings
|
|
57
|
-
if (!privateKey || privateKey.trim().length === 0) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Private keys must be 64 hex characters (32 bytes)
|
|
62
|
-
if (!/^[0-9a-fA-F]{64}$/.test(privateKey)) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
const keyPair = ec.keyFromPrivate(privateKey);
|
|
68
|
-
// Verify it can derive a public key and the key is valid
|
|
69
|
-
keyPair.getPublic('hex');
|
|
70
|
-
// Check that the private key is not zero (which would be invalid)
|
|
71
|
-
const priv = keyPair.getPrivate();
|
|
72
|
-
if (!priv || priv.isZero()) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
return true;
|
|
76
|
-
} catch {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Get a shortened display version of a public key
|
|
83
|
-
* Format: first 8 chars...last 8 chars
|
|
84
|
-
*/
|
|
85
|
-
export function shortenPublicKey(publicKey: string): string {
|
|
86
|
-
if (publicKey.length <= 20) return publicKey;
|
|
87
|
-
return `${publicKey.slice(0, 8)}...${publicKey.slice(-8)}`;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Derive public key from a private key (without storing)
|
|
92
|
-
*/
|
|
93
|
-
export function derivePublicKey(privateKey: string): string {
|
|
94
|
-
const keyPair = ec.keyFromPrivate(privateKey);
|
|
95
|
-
return keyPair.getPublic('hex');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Check timestamp freshness
|
|
100
|
-
*/
|
|
101
|
-
export function isTimestampFresh(timestamp: number, maxAgeMs: number = MAX_SIGNATURE_AGE_MS): boolean {
|
|
102
|
-
const now = Date.now();
|
|
103
|
-
return (now - timestamp) <= maxAgeMs;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Build authentication challenge message
|
|
108
|
-
* Format: auth:{publicKey}:{challenge}:{timestamp}
|
|
109
|
-
*/
|
|
110
|
-
export function buildAuthMessage(publicKey: string, challenge: string, timestamp: number): string {
|
|
111
|
-
return `auth:${publicKey}:${challenge}:${timestamp}`;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Build registration message
|
|
116
|
-
* Format: oxy:register:{publicKey}:{timestamp}
|
|
117
|
-
*/
|
|
118
|
-
export function buildRegistrationMessage(publicKey: string, timestamp: number): string {
|
|
119
|
-
return `oxy:register:${publicKey}:${timestamp}`;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Build request signature message
|
|
124
|
-
* Format: request:{publicKey}:{timestamp}:{canonicalString}
|
|
125
|
-
*/
|
|
126
|
-
export function buildRequestMessage(
|
|
127
|
-
publicKey: string,
|
|
128
|
-
timestamp: number,
|
|
129
|
-
data: Record<string, unknown>
|
|
130
|
-
): string {
|
|
131
|
-
const sortedKeys = Object.keys(data).sort();
|
|
132
|
-
const canonicalParts = sortedKeys.map(key => `${key}:${JSON.stringify(data[key])}`);
|
|
133
|
-
const canonicalString = canonicalParts.join('|');
|
|
134
|
-
return `request:${publicKey}:${timestamp}:${canonicalString}`;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Get the elliptic curve instance (for key generation)
|
|
139
|
-
*/
|
|
140
|
-
export function getEllipticCurve(): ECType {
|
|
141
|
-
return ec;
|
|
142
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node.js Signature Service
|
|
3
|
-
*
|
|
4
|
-
* Provides synchronous signature operations for Node.js backend.
|
|
5
|
-
* Uses Node's crypto module for hashing and the shared core for verification.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import crypto from 'crypto';
|
|
9
|
-
import {
|
|
10
|
-
verifySignatureCore,
|
|
11
|
-
isValidPublicKey,
|
|
12
|
-
isTimestampFresh,
|
|
13
|
-
buildAuthMessage,
|
|
14
|
-
buildRegistrationMessage,
|
|
15
|
-
buildRequestMessage,
|
|
16
|
-
shortenPublicKey,
|
|
17
|
-
CHALLENGE_TTL_MS,
|
|
18
|
-
MAX_SIGNATURE_AGE_MS,
|
|
19
|
-
} from '../crypto/core';
|
|
20
|
-
|
|
21
|
-
export class SignatureService {
|
|
22
|
-
/**
|
|
23
|
-
* Generate a random challenge string
|
|
24
|
-
*/
|
|
25
|
-
static generateChallenge(): string {
|
|
26
|
-
return crypto.randomBytes(32).toString('hex');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Compute SHA-256 hash of a message (synchronous)
|
|
31
|
-
*/
|
|
32
|
-
static hashMessage(message: string): string {
|
|
33
|
-
return crypto.createHash('sha256').update(message).digest('hex');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Verify an ECDSA signature (synchronous)
|
|
38
|
-
*
|
|
39
|
-
* @param message - The original message that was signed
|
|
40
|
-
* @param signature - The signature in DER format (hex encoded)
|
|
41
|
-
* @param publicKey - The public key (hex encoded, uncompressed)
|
|
42
|
-
* @returns true if the signature is valid
|
|
43
|
-
*/
|
|
44
|
-
static verifySignature(message: string, signature: string, publicKey: string): boolean {
|
|
45
|
-
const messageHash = SignatureService.hashMessage(message);
|
|
46
|
-
return verifySignatureCore(messageHash, signature, publicKey);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Verify an authentication challenge response
|
|
51
|
-
*
|
|
52
|
-
* @param publicKey - The user's public key
|
|
53
|
-
* @param challenge - The original challenge string
|
|
54
|
-
* @param signature - The signature of the auth message
|
|
55
|
-
* @param timestamp - The timestamp when the signature was created
|
|
56
|
-
* @returns true if the challenge response is valid
|
|
57
|
-
*/
|
|
58
|
-
static verifyChallengeResponse(
|
|
59
|
-
publicKey: string,
|
|
60
|
-
challenge: string,
|
|
61
|
-
signature: string,
|
|
62
|
-
timestamp: number
|
|
63
|
-
): boolean {
|
|
64
|
-
// Check timestamp is not too old
|
|
65
|
-
if (!isTimestampFresh(timestamp, CHALLENGE_TTL_MS)) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Build the message and verify signature
|
|
70
|
-
const message = buildAuthMessage(publicKey, challenge, timestamp);
|
|
71
|
-
return SignatureService.verifySignature(message, signature, publicKey);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Verify a registration signature
|
|
76
|
-
* Signature format: oxy:register:{publicKey}:{timestamp}
|
|
77
|
-
*/
|
|
78
|
-
static verifyRegistrationSignature(
|
|
79
|
-
publicKey: string,
|
|
80
|
-
signature: string,
|
|
81
|
-
timestamp: number
|
|
82
|
-
): boolean {
|
|
83
|
-
// Check timestamp freshness
|
|
84
|
-
if (!isTimestampFresh(timestamp, MAX_SIGNATURE_AGE_MS)) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const message = buildRegistrationMessage(publicKey, timestamp);
|
|
89
|
-
return SignatureService.verifySignature(message, signature, publicKey);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Verify a signed request
|
|
94
|
-
* Used for authenticated API operations
|
|
95
|
-
*/
|
|
96
|
-
static verifyRequestSignature(
|
|
97
|
-
publicKey: string,
|
|
98
|
-
data: Record<string, unknown>,
|
|
99
|
-
signature: string,
|
|
100
|
-
timestamp: number
|
|
101
|
-
): boolean {
|
|
102
|
-
// Check timestamp freshness
|
|
103
|
-
if (!isTimestampFresh(timestamp, MAX_SIGNATURE_AGE_MS)) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const message = buildRequestMessage(publicKey, timestamp, data);
|
|
108
|
-
return SignatureService.verifySignature(message, signature, publicKey);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Validate that a string is a valid public key
|
|
113
|
-
*/
|
|
114
|
-
static isValidPublicKey(publicKey: string): boolean {
|
|
115
|
-
return isValidPublicKey(publicKey);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Get a shortened display version of a public key
|
|
120
|
-
*/
|
|
121
|
-
static shortenPublicKey(publicKey: string): string {
|
|
122
|
-
return shortenPublicKey(publicKey);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export default SignatureService;
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import { useQuery } from '@tanstack/react-query';
|
|
3
|
-
import type { OxyServices } from '../../../core';
|
|
4
|
-
import { handleHttpError, ErrorCodes } from '../../../utils/errorUtils';
|
|
5
|
-
import { useDebounce } from '../../../utils/hookUtils';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Username validation constants
|
|
9
|
-
*/
|
|
10
|
-
export const USERNAME_MIN_LENGTH = 4;
|
|
11
|
-
export const USERNAME_REGEX = /^[a-z0-9]+$/i;
|
|
12
|
-
export const USERNAME_FORMAT_ERROR = 'You can use a-z, 0-9. Minimum length is 4 characters.';
|
|
13
|
-
export const USERNAME_DEBOUNCE_MS = 500;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Username validation result interface
|
|
17
|
-
*/
|
|
18
|
-
export interface UsernameValidationResult {
|
|
19
|
-
isValid: boolean;
|
|
20
|
-
isAvailable: boolean | null; // null = not checked yet
|
|
21
|
-
error: string | null;
|
|
22
|
-
isChecking: boolean;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Validate username format using services validation utilities
|
|
27
|
-
*/
|
|
28
|
-
function validateUsernameFormat(username: string): boolean {
|
|
29
|
-
// Use stricter validation: lowercase alphanumeric only, min 4 chars
|
|
30
|
-
return username.length >= USERNAME_MIN_LENGTH && USERNAME_REGEX.test(username);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Check if an error is a network or timeout error
|
|
35
|
-
*/
|
|
36
|
-
function isNetworkOrTimeoutError(error: unknown): boolean {
|
|
37
|
-
const apiError = handleHttpError(error);
|
|
38
|
-
return (
|
|
39
|
-
apiError.code === ErrorCodes.NETWORK_ERROR ||
|
|
40
|
-
apiError.code === ErrorCodes.TIMEOUT ||
|
|
41
|
-
apiError.code === ErrorCodes.CONNECTION_FAILED
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Extract error message from an unknown error shape
|
|
47
|
-
*/
|
|
48
|
-
function extractAuthErrorMessage(error: unknown, fallbackMessage = 'An error occurred'): string {
|
|
49
|
-
const apiError = handleHttpError(error);
|
|
50
|
-
return apiError.message || fallbackMessage;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Hook for username validation with debouncing and availability checking
|
|
55
|
-
*
|
|
56
|
-
* Uses TanStack Query for efficient API calls with:
|
|
57
|
-
* - Automatic request cancellation when username changes
|
|
58
|
-
* - Built-in caching (same username checked multiple times = cached result)
|
|
59
|
-
* - Request deduplication (multiple components checking same username = single request)
|
|
60
|
-
* - Proper error handling
|
|
61
|
-
*
|
|
62
|
-
* @param username - The username to validate
|
|
63
|
-
* @param oxyServices - OxyServices instance for API calls
|
|
64
|
-
* @returns Username validation state and result
|
|
65
|
-
*/
|
|
66
|
-
export function useUsernameValidation(
|
|
67
|
-
username: string,
|
|
68
|
-
oxyServices: OxyServices | null
|
|
69
|
-
): UsernameValidationResult {
|
|
70
|
-
// Debounce the username input to avoid excessive API calls
|
|
71
|
-
const debouncedUsername = useDebounce(username.trim().toLowerCase(), USERNAME_DEBOUNCE_MS);
|
|
72
|
-
|
|
73
|
-
// Validate format synchronously (no API call needed)
|
|
74
|
-
const isValid = useMemo(() => validateUsernameFormat(username), [username]);
|
|
75
|
-
|
|
76
|
-
// Determine if we should check availability
|
|
77
|
-
const shouldCheckAvailability = useMemo(() => {
|
|
78
|
-
if (!debouncedUsername || debouncedUsername.length < USERNAME_MIN_LENGTH) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
return validateUsernameFormat(debouncedUsername);
|
|
82
|
-
}, [debouncedUsername]);
|
|
83
|
-
|
|
84
|
-
// Use TanStack Query for the API call
|
|
85
|
-
// This provides automatic caching, request cancellation, and deduplication
|
|
86
|
-
const {
|
|
87
|
-
data: availabilityResult,
|
|
88
|
-
isLoading: isChecking,
|
|
89
|
-
error: queryError,
|
|
90
|
-
isFetching,
|
|
91
|
-
} = useQuery({
|
|
92
|
-
queryKey: ['username', 'availability', debouncedUsername],
|
|
93
|
-
queryFn: async () => {
|
|
94
|
-
if (!oxyServices) {
|
|
95
|
-
throw new Error('OxyServices not available');
|
|
96
|
-
}
|
|
97
|
-
return await oxyServices.checkUsernameAvailability(debouncedUsername);
|
|
98
|
-
},
|
|
99
|
-
enabled: shouldCheckAvailability && !!oxyServices,
|
|
100
|
-
staleTime: 5 * 60 * 1000, // Cache for 5 minutes (usernames don't change often)
|
|
101
|
-
gcTime: 30 * 60 * 1000, // Keep in cache for 30 minutes
|
|
102
|
-
retry: (failureCount, error) => {
|
|
103
|
-
// Don't retry on network/timeout errors (user might be offline)
|
|
104
|
-
if (isNetworkOrTimeoutError(error)) {
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
// Retry up to 2 times for other errors
|
|
108
|
-
return failureCount < 2;
|
|
109
|
-
},
|
|
110
|
-
retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 3000),
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// Compute the result based on validation and query state
|
|
114
|
-
return useMemo(() => {
|
|
115
|
-
// If username is too short or invalid format, return early validation
|
|
116
|
-
if (!username || username.length < USERNAME_MIN_LENGTH) {
|
|
117
|
-
return {
|
|
118
|
-
isValid: false,
|
|
119
|
-
isAvailable: null,
|
|
120
|
-
error: null,
|
|
121
|
-
isChecking: false,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (!isValid) {
|
|
126
|
-
return {
|
|
127
|
-
isValid: false,
|
|
128
|
-
isAvailable: false,
|
|
129
|
-
error: USERNAME_FORMAT_ERROR,
|
|
130
|
-
isChecking: false,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// If we're not checking yet (debounce period), show checking state only if user is typing
|
|
135
|
-
const isCurrentlyChecking = isChecking || isFetching;
|
|
136
|
-
|
|
137
|
-
// Handle network/timeout errors gracefully
|
|
138
|
-
if (queryError && isNetworkOrTimeoutError(queryError)) {
|
|
139
|
-
// Allow proceeding if offline/network issue (optimistic)
|
|
140
|
-
return {
|
|
141
|
-
isValid: true,
|
|
142
|
-
isAvailable: true, // Optimistic: allow proceeding
|
|
143
|
-
error: null,
|
|
144
|
-
isChecking: false,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Handle other errors
|
|
149
|
-
if (queryError) {
|
|
150
|
-
return {
|
|
151
|
-
isValid: true,
|
|
152
|
-
isAvailable: false,
|
|
153
|
-
error: extractAuthErrorMessage(queryError, 'Failed to check username availability'),
|
|
154
|
-
isChecking: false,
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// If we have a result, use it
|
|
159
|
-
if (availabilityResult) {
|
|
160
|
-
return {
|
|
161
|
-
isValid: true,
|
|
162
|
-
isAvailable: availabilityResult.available,
|
|
163
|
-
error: availabilityResult.available ? null : (availabilityResult.message || 'Username is already taken'),
|
|
164
|
-
isChecking: false,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Still checking (or waiting for debounce)
|
|
169
|
-
return {
|
|
170
|
-
isValid: true,
|
|
171
|
-
isAvailable: null,
|
|
172
|
-
error: null,
|
|
173
|
-
isChecking: isCurrentlyChecking,
|
|
174
|
-
};
|
|
175
|
-
}, [username, isValid, availabilityResult, isChecking, isFetching, queryError]);
|
|
176
|
-
}
|
|
177
|
-
|