Page MenuHomePhabricator

D11910.diff
No OneTemporary

D11910.diff

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
@@ -124,9 +124,18 @@
+deletePasswordUser?: (password: string) => Promise<void>;
+logOut: () => Promise<void>;
+getKeyserverKeys: string => Promise<DeviceOlmOutboundKeys>;
+ // Users cannot register from web
+registerPasswordUser?: (
username: string,
password: string,
+ fid: ?string,
+ ) => Promise<IdentityAuthResult>;
+ // Users cannot register from web
+ +registerReservedPasswordUser?: (
+ username: string,
+ password: string,
+ keyserverMessage: string,
+ keyserverSignature: string,
) => Promise<IdentityAuthResult>;
+logInPasswordUser: (
username: string,
@@ -140,10 +149,20 @@
) => Promise<UserDevicesOlmInboundKeys>;
+uploadOneTimeKeys: (oneTimeKeys: OneTimeKeysResultValues) => Promise<void>;
+generateNonce: () => Promise<string>;
+ // Users cannot register from web
+registerWalletUser?: (
walletAddress: string,
siweMessage: string,
siweSignature: string,
+ fid: ?string,
+ ) => Promise<IdentityAuthResult>;
+ // Users cannot register from web
+ +registerReservedWalletUser?: (
+ walletAddress: string,
+ siweMessage: string,
+ siweSignature: string,
+ keyserverMessage: string,
+ keyserverSignature: string,
) => Promise<IdentityAuthResult>;
+logInWalletUser: (
walletAddress: string,
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
@@ -79,6 +79,32 @@
return { deviceID, userID, accessToken };
}, [accessToken]);
+ const processAuthResult = async (
+ authResult: string,
+ username: string,
+ deviceID: string,
+ ) => {
+ const { userID, accessToken: token } = JSON.parse(authResult);
+ const identityAuthResult = {
+ accessToken: token,
+ userID,
+ username,
+ };
+
+ const validatedResult = assertWithValidator(
+ identityAuthResult,
+ identityAuthResultValidator,
+ );
+
+ await commCoreModule.setCommServicesAuthMetadata(
+ validatedResult.userID,
+ deviceID,
+ validatedResult.accessToken,
+ );
+
+ return validatedResult;
+ };
+
const client = React.useMemo<IdentityServiceClient>(
() => ({
deleteWalletUser: async () => {
@@ -343,21 +369,54 @@
fid ?? '',
JSON.stringify(initialDeviceList),
);
- const { userID, accessToken: token } = JSON.parse(registrationResult);
- const identityAuthResult = { accessToken: token, userID, username };
- const validatedResult = assertWithValidator(
- identityAuthResult,
- identityAuthResultValidator,
+ return await processAuthResult(
+ registrationResult,
+ username,
+ primaryIdentityPublicKeys.ed25519,
);
-
- await commCoreModule.setCommServicesAuthMetadata(
- validatedResult.userID,
+ },
+ registerReservedPasswordUser: async (
+ username: string,
+ password: string,
+ keyserverMessage: string,
+ keyserverSignature: string,
+ ) => {
+ await commCoreModule.initializeCryptoAccount();
+ const [
+ { blobPayload, signature, primaryIdentityPublicKeys },
+ { contentOneTimeKeys, notificationsOneTimeKeys },
+ prekeys,
+ ] = await Promise.all([
+ commCoreModule.getUserPublicKey(),
+ commCoreModule.getOneTimeKeys(ONE_TIME_KEYS_NUMBER),
+ commCoreModule.validateAndGetPrekeys(),
+ ]);
+ const initialDeviceList = await createAndSignInitialDeviceList(
primaryIdentityPublicKeys.ed25519,
- validatedResult.accessToken,
);
+ const registrationResult =
+ await commRustModule.registerReservedPasswordUser(
+ username,
+ password,
+ blobPayload,
+ signature,
+ prekeys.contentPrekey,
+ prekeys.contentPrekeySignature,
+ prekeys.notifPrekey,
+ prekeys.notifPrekeySignature,
+ getOneTimeKeyValues(contentOneTimeKeys),
+ getOneTimeKeyValues(notificationsOneTimeKeys),
+ keyserverMessage,
+ keyserverSignature,
+ JSON.stringify(initialDeviceList),
+ );
- return validatedResult;
+ return await processAuthResult(
+ registrationResult,
+ username,
+ primaryIdentityPublicKeys.ed25519,
+ );
},
logInPasswordUser: async (username: string, password: string) => {
await commCoreModule.initializeCryptoAccount();
@@ -376,21 +435,12 @@
prekeys.notifPrekey,
prekeys.notifPrekeySignature,
);
- const { userID, accessToken: token } = JSON.parse(loginResult);
- const identityAuthResult = { accessToken: token, userID, username };
-
- const validatedResult = assertWithValidator(
- identityAuthResult,
- identityAuthResultValidator,
- );
- await commCoreModule.setCommServicesAuthMetadata(
- validatedResult.userID,
+ return await processAuthResult(
+ loginResult,
+ username,
primaryIdentityPublicKeys.ed25519,
- validatedResult.accessToken,
);
-
- return validatedResult;
},
registerWalletUser: async (
walletAddress: string,
@@ -425,25 +475,55 @@
fid ?? '',
JSON.stringify(initialDeviceList),
);
- const { userID, accessToken: token } = JSON.parse(registrationResult);
- const identityAuthResult = {
- accessToken: token,
- userID,
- username: walletAddress,
- };
- const validatedResult = assertWithValidator(
- identityAuthResult,
- identityAuthResultValidator,
+ return await processAuthResult(
+ registrationResult,
+ walletAddress,
+ primaryIdentityPublicKeys.ed25519,
);
-
- await commCoreModule.setCommServicesAuthMetadata(
- validatedResult.userID,
+ },
+ registerReservedWalletUser: async (
+ walletAddress: string,
+ siweMessage: string,
+ siweSignature: string,
+ keyserverMessage: string,
+ keyserverSignature: string,
+ ) => {
+ await commCoreModule.initializeCryptoAccount();
+ const [
+ { blobPayload, signature, primaryIdentityPublicKeys },
+ { contentOneTimeKeys, notificationsOneTimeKeys },
+ prekeys,
+ ] = await Promise.all([
+ commCoreModule.getUserPublicKey(),
+ commCoreModule.getOneTimeKeys(ONE_TIME_KEYS_NUMBER),
+ commCoreModule.validateAndGetPrekeys(),
+ ]);
+ const initialDeviceList = await createAndSignInitialDeviceList(
primaryIdentityPublicKeys.ed25519,
- validatedResult.accessToken,
);
+ const registrationResult =
+ await commRustModule.registerReservedWalletUser(
+ siweMessage,
+ siweSignature,
+ blobPayload,
+ signature,
+ prekeys.contentPrekey,
+ prekeys.contentPrekeySignature,
+ prekeys.notifPrekey,
+ prekeys.notifPrekeySignature,
+ getOneTimeKeyValues(contentOneTimeKeys),
+ getOneTimeKeyValues(notificationsOneTimeKeys),
+ keyserverMessage,
+ keyserverSignature,
+ JSON.stringify(initialDeviceList),
+ );
- return validatedResult;
+ return await processAuthResult(
+ registrationResult,
+ walletAddress,
+ primaryIdentityPublicKeys.ed25519,
+ );
},
logInWalletUser: async (
walletAddress: string,
@@ -466,25 +546,12 @@
prekeys.notifPrekey,
prekeys.notifPrekeySignature,
);
- const { userID, accessToken: token } = JSON.parse(loginResult);
- const identityAuthResult = {
- accessToken: token,
- userID,
- username: walletAddress,
- };
- const validatedResult = assertWithValidator(
- identityAuthResult,
- identityAuthResultValidator,
- );
-
- await commCoreModule.setCommServicesAuthMetadata(
- validatedResult.userID,
+ return await processAuthResult(
+ loginResult,
+ walletAddress,
primaryIdentityPublicKeys.ed25519,
- validatedResult.accessToken,
);
-
- return validatedResult;
},
uploadKeysForRegisteredDeviceAndLogIn: async (
userID: string,

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 3:05 AM (20 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2573635
Default Alt Text
D11910.diff (8 KB)

Event Timeline