diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js --- a/lib/actions/user-actions.js +++ b/lib/actions/user-actions.js @@ -21,7 +21,11 @@ UpdateUserAvatarResponse, } from '../types/avatar-types.js'; import type { RawEntryInfo, CalendarQuery } from '../types/entry-types.js'; -import type { IdentityServiceClient } from '../types/identity-service-types'; +import type { + UserLoginResponse, + IdentityServiceClient, + IdentityServiceNativeClient, +} from '../types/identity-service-types'; import type { RawMessageInfo, MessageTruncationStatuses, @@ -220,6 +224,56 @@ }; }; +const identityRegisterActionTypes = Object.freeze({ + started: 'IDENTITY_REGISTER_STARTED', + success: 'IDENTITY_REGISTER_SUCCESS', + failed: 'IDENTITY_REGISTER_FAILED', +}); +function useIdentityRegister( + client: IdentityServiceNativeClient, + username: string, + password: string, + keyPayload: string, + keyPayloadSignature: string, + contentPrekey: string, + contentPrekeySignature: string, + notifPrekey: string, + notifPrekeySignature: string, + contentOneTimeKeys: $ReadOnlyArray, + notifOneTimeKeys: $ReadOnlyArray, +): () => Promise { + const identityRegister = React.useCallback(async () => { + const registrationResult = await client.registerUser( + username, + password, + keyPayload, + keyPayloadSignature, + contentPrekey, + contentPrekeySignature, + notifPrekey, + notifPrekeySignature, + contentOneTimeKeys, + notifOneTimeKeys, + ); + const { userID, accessToken } = JSON.parse(registrationResult); + return { accessToken, userId: userID }; + }, [ + client, + contentOneTimeKeys, + contentPrekey, + contentPrekeySignature, + keyPayload, + keyPayloadSignature, + notifOneTimeKeys, + notifPrekey, + notifPrekeySignature, + password, + username, + ]); + + return identityRegister; +} + function mergeUserInfos( ...userInfoArrays: Array<$ReadOnlyArray> ): UserInfo[] { @@ -561,4 +615,6 @@ setAccessTokenActionType, deleteIdentityAccountActionTypes, useDeleteIdentityAccount, + identityRegisterActionTypes, + useIdentityRegister, }; diff --git a/lib/types/identity-service-types.js b/lib/types/identity-service-types.js --- a/lib/types/identity-service-types.js +++ b/lib/types/identity-service-types.js @@ -27,6 +27,22 @@ ) => Promise; } +// Native-specific client methods +export interface IdentityServiceNativeClient { + +registerUser: ( + username: string, + password: string, + keyPayload: string, + keyPayloadSignature: string, + contentPrekey: string, + contentPrekeySignature: string, + notifPrekey: string, + notifPrekeySignature: string, + contentOneTimeKeys: $ReadOnlyArray, + notifOneTimeKeys: $ReadOnlyArray, + ) => Promise; +} + export type IdentityServiceAuthLayer = { +userID: string, +deviceID: string,