Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3149228
D10581.id35582.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D10581.id35582.diff
View Options
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
@@ -53,3 +53,5 @@
+accessToken: string,
+username: string,
};
+
+export const ONE_TIME_KEYS_NUMBER = 10;
diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js
--- a/lib/types/redux-types.js
+++ b/lib/types/redux-types.js
@@ -43,6 +43,7 @@
CalendarThreadFilter,
SetCalendarDeletedFilterPayload,
} from './filter-types.js';
+import type { IdentityRegisterResult } from './identity-service-types.js';
import type { IntegrityStore } from './integrity-types.js';
import type {
KeyserverStore,
@@ -373,6 +374,21 @@
+payload: RegisterResult,
+loadingInfo: LoadingInfo,
}
+ | {
+ +type: 'IDENTITY_REGISTER_STARTED',
+ +payload?: void,
+ +loadingInfo: LoadingInfo,
+ }
+ | {
+ +type: 'IDENTITY_REGISTER_FAILED',
+ +payload: Error,
+ +loadingInfo: LoadingInfo,
+ }
+ | {
+ +type: 'IDENTITY_REGISTER_SUCCESS',
+ +payload: IdentityRegisterResult,
+ +loadingInfo: LoadingInfo,
+ }
| {
+type: 'CHANGE_KEYSERVER_USER_PASSWORD_STARTED',
+payload?: void,
diff --git a/native/account/registration/registration-server-call.js b/native/account/registration/registration-server-call.js
--- a/native/account/registration/registration-server-call.js
+++ b/native/account/registration/registration-server-call.js
@@ -6,11 +6,14 @@
import {
keyserverRegisterActionTypes,
keyserverRegister,
+ useIdentityRegister,
+ identityRegisterActionTypes,
} from 'lib/actions/user-actions.js';
import type { LogInStartingPayload } from 'lib/types/account-types.js';
import { useServerCall } from 'lib/utils/action-utils.js';
import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
import { useDispatch } from 'lib/utils/redux-utils.js';
+import { usingCommServicesAccessToken } from 'lib/utils/services-utils.js';
import { setURLPrefix } from 'lib/utils/url-utils.js';
import type {
@@ -59,17 +62,63 @@
const logInExtraInfo = useSelector(nativeLogInExtraInfoSelector);
const dispatchActionPromise = useDispatchActionPromise();
- const callRegister = useServerCall(keyserverRegister);
+ const callKeyserverRegister = useServerCall(keyserverRegister);
+ const callIdentityRegister = useIdentityRegister();
- const registerUsernameAccount = React.useCallback(
+ const identityRegisterUsernameAccount = React.useCallback(
+ async (accountSelection: UsernameAccountSelection) => {
+ const identityRegisterPromise = (async () => {
+ try {
+ const result = await callIdentityRegister(
+ accountSelection.username,
+ accountSelection.password,
+ );
+ await setNativeCredentials({
+ username: accountSelection.username,
+ password: accountSelection.password,
+ });
+ return result;
+ } catch (e) {
+ if (e.message === 'username reserved') {
+ Alert.alert(
+ 'Username reserved',
+ 'This username is currently reserved. Please contact support@' +
+ 'comm.app if you would like to claim this account.',
+ );
+ } else if (e.message === 'username already exists') {
+ Alert.alert(
+ 'Username taken',
+ 'An account with that username already exists',
+ );
+ } else if (e.message === 'Unsupported version') {
+ Alert.alert(
+ AppOutOfDateAlertDetails.title,
+ AppOutOfDateAlertDetails.message,
+ );
+ } else {
+ Alert.alert('Unknown error', 'Uhh... try again?');
+ }
+ throw e;
+ }
+ })();
+ void dispatchActionPromise(
+ identityRegisterActionTypes,
+ identityRegisterPromise,
+ );
+ await identityRegisterPromise;
+ },
+ [callIdentityRegister, dispatchActionPromise],
+ );
+
+ const keyserverRegisterUsernameAccount = React.useCallback(
async (
accountSelection: UsernameAccountSelection,
keyserverURL: string,
) => {
const extraInfo = await logInExtraInfo();
- const registerPromise = (async () => {
+ const keyserverRegisterPromise = (async () => {
try {
- const result = await callRegister(
+ const result = await callKeyserverRegister(
{
...extraInfo,
username: accountSelection.username,
@@ -109,13 +158,13 @@
})();
void dispatchActionPromise(
keyserverRegisterActionTypes,
- registerPromise,
+ keyserverRegisterPromise,
undefined,
({ calendarQuery: extraInfo.calendarQuery }: LogInStartingPayload),
);
- await registerPromise;
+ await keyserverRegisterPromise;
},
- [logInExtraInfo, callRegister, dispatchActionPromise],
+ [logInExtraInfo, callKeyserverRegister, dispatchActionPromise],
);
const siweServerCall = useSIWEServerCall();
@@ -130,8 +179,16 @@
return;
}
const { accountSelection, avatarData, keyserverURL } = input;
- if (accountSelection.accountType === 'username') {
- await registerUsernameAccount(accountSelection, keyserverURL);
+ if (
+ accountSelection.accountType === 'username' &&
+ !usingCommServicesAccessToken
+ ) {
+ await keyserverRegisterUsernameAccount(
+ accountSelection,
+ keyserverURL,
+ );
+ } else if (accountSelection.accountType === 'username') {
+ await identityRegisterUsernameAccount(accountSelection);
} else {
try {
await siweServerCall(accountSelection, {
@@ -157,7 +214,13 @@
}
},
),
- [currentStep, registerUsernameAccount, siweServerCall, dispatch],
+ [
+ currentStep,
+ keyserverRegisterUsernameAccount,
+ identityRegisterUsernameAccount,
+ siweServerCall,
+ dispatch,
+ ],
);
// STEP 2: SETTING AVATAR
diff --git a/native/identity-service/identity-service-context-provider.react.js b/native/identity-service/identity-service-context-provider.react.js
--- a/native/identity-service/identity-service-context-provider.react.js
+++ b/native/identity-service/identity-service-context-provider.react.js
@@ -2,12 +2,14 @@
import * as React from 'react';
+import { getOneTimeKeyArray } from 'lib/shared/crypto-utils.js';
import { IdentityClientContext } from 'lib/shared/identity-client-context.js';
import type {
IdentityServiceClient,
OutboundKeyInfoResponse,
UserLoginResponse,
} from 'lib/types/identity-service-types.js';
+import { ONE_TIME_KEYS_NUMBER } from 'lib/types/identity-service-types.js';
import { getCommServicesAuthMetadataEmitter } from '../event-emitters/csa-auth-metadata-emitter.js';
import { commCoreModule, commRustModule } from '../native-modules.js';
@@ -87,6 +89,42 @@
}
return resultObject;
},
+ registerUser: async (username: string, password: string) => {
+ await commCoreModule.initializeCryptoAccount();
+ const [
+ {
+ notificationIdentityPublicKeys,
+ primaryIdentityPublicKeys,
+ signature,
+ },
+ notificationsOneTimeKeys,
+ primaryOneTimeKeys,
+ prekeys,
+ ] = await Promise.all([
+ commCoreModule.getUserPublicKey(),
+ commCoreModule.getNotificationsOneTimeKeys(ONE_TIME_KEYS_NUMBER),
+ commCoreModule.getPrimaryOneTimeKeys(ONE_TIME_KEYS_NUMBER),
+ commCoreModule.generateAndGetPrekeys(),
+ ]);
+ const keyPayload = JSON.stringify({
+ notificationIdentityPublicKeys,
+ primaryIdentityPublicKeys,
+ });
+ const registrationResult = await commRustModule.registerUser(
+ username,
+ password,
+ keyPayload,
+ signature,
+ prekeys.contentPrekey,
+ prekeys.contentPrekeySignature,
+ prekeys.notifPrekey,
+ prekeys.notifPrekeySignature,
+ getOneTimeKeyArray(primaryOneTimeKeys),
+ getOneTimeKeyArray(notificationsOneTimeKeys),
+ );
+ const { userID, accessToken } = JSON.parse(registrationResult);
+ return { accessToken, userID, username };
+ },
};
}, [getAuthMetadata]);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 5, 1:43 PM (15 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2425948
Default Alt Text
D10581.id35582.diff (8 KB)
Attached To
Mode
D10581: [native] identityRegisterUsernameAccount function
Attached
Detach File
Event Timeline
Log In to Comment