diff --git a/keyserver/src/endpoints.js b/keyserver/src/endpoints.js --- a/keyserver/src/endpoints.js +++ b/keyserver/src/endpoints.js @@ -150,6 +150,7 @@ roleModificationResultValidator, } from './responders/thread-responders.js'; import { + identityServiceOlmAuthRequestInputValidator, userSubscriptionUpdateResponder, passwordUpdateResponder, sendVerificationEmailResponder, @@ -178,6 +179,7 @@ updatePasswordRequestInputValidator, updateUserAvatarResponderValidator, updateUserSettingsInputValidator, + identityServiceOlmAuthResponder, } from './responders/user-responders.js'; import { codeVerificationResponder, @@ -533,6 +535,12 @@ logInResponseValidator, [], ), + identity_service_olm_auth: createJSONResponder( + identityServiceOlmAuthResponder, + identityServiceOlmAuthRequestInputValidator, + logInResponseValidator, + [], + ), update_user_avatar: createJSONResponder( updateUserAvatarResponder, updateUserAvatarRequestValidator, diff --git a/keyserver/src/responders/user-responders.js b/keyserver/src/responders/user-responders.js --- a/keyserver/src/responders/user-responders.js +++ b/keyserver/src/responders/user-responders.js @@ -23,6 +23,7 @@ UpdatePasswordRequest, UpdateUserSettingsRequest, PolicyAcknowledgmentRequest, + IdentityServiceOlmAuthRequest, } from 'lib/types/account-types.js'; import { userSettingsTypes, @@ -663,6 +664,29 @@ }); } +const UserIdentifierValidator = t.refinement( + t.Object, + x => + ('username' in x && !('walletAddress' in x)) || + ('walletAddress' in x && !('username' in x)), +); + +export const identityServiceOlmAuthRequestInputValidator: TInterface = + tShape({ + identifier: UserIdentifierValidator, + signingPublicKey: t.String, + calendarQuery: entryQueryInputValidator, + deviceTokenUpdateRequest: t.maybe(deviceTokenUpdateRequestInputValidator), + platformDetails: tPlatformDetails, + watchedIDs: t.list(tID), + initialContentEncryptedMessage: t.String, + initialNotificationsEncryptedMessage: t.String, + }); + +async function identityServiceOlmAuthResponder(): Promise { + return 'UNIMPLEMENTED'; +} + export const updatePasswordRequestInputValidator: TInterface = tShape({ code: t.String, @@ -744,4 +768,5 @@ updateUserSettingsResponder, policyAcknowledgmentResponder, updateUserAvatarResponder, + identityServiceOlmAuthResponder, }; 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 @@ -9,6 +9,7 @@ RegisterInfo, UpdateUserSettingsRequest, PolicyAcknowledgmentRequest, + BaseIdentityServiceOlmAuthRequest, } from '../types/account-types.js'; import type { UpdateUserAvatarRequest, @@ -175,6 +176,34 @@ }; }; +const identityServiceOlmAuthActionTypes = Object.freeze({ + started: 'IDENTITY_SERVICE_OLM_AUTH_STARTED', + success: 'IDENTITY_SERVICE_OLM_AUTH_SUCCESS', + failed: 'IDENTITY_SERVICE_OLM_AUTH_FAILED', +}); +const identityServiceOlmAuth = + ( + callServerEndpoint: CallServerEndpoint, + ): (( + baseIdentityServiceOlmAuthPayload: BaseIdentityServiceOlmAuthRequest, + options?: ?CallServerEndpointOptions, + ) => Promise) => + async (baseIdentityServiceOlmAuthPayload, options) => { + const watchedIDs = threadWatcher.getWatchedIDs(); + const response = await callServerEndpoint( + 'identity_service_olm_auth', + { + ...baseIdentityServiceOlmAuthPayload, + watchedIDs, + platformDetails: getConfig().platformDetails, + }, + { + ...options, + }, + ); + return response; + }; + const changeUserPasswordActionTypes = Object.freeze({ started: 'CHANGE_USER_PASSWORD_STARTED', success: 'CHANGE_USER_PASSWORD_SUCCESS', @@ -353,4 +382,6 @@ updateUserAvatar, resetUserStateActionType, setAccessTokenActionType, + identityServiceOlmAuth, + identityServiceOlmAuthActionTypes, }; diff --git a/lib/types/account-types.js b/lib/types/account-types.js --- a/lib/types/account-types.js +++ b/lib/types/account-types.js @@ -159,6 +159,25 @@ +notAcknowledgedPolicies?: $ReadOnlyArray, }; +export type UserIdentifier = + | { username: string, walletAddress?: empty } + | { username?: empty, walletAddress: string }; + +export type BaseIdentityServiceOlmAuthRequest = { + +identifier: UserIdentifier, + +signingPublicKey: string, + +calendarQuery: CalendarQuery, + +deviceTokenUpdateRequest?: ?DeviceTokenUpdateRequest, + +initialContentEncryptedMessage: string, + +initialNotificationsEncryptedMessage: string, +}; + +export type IdentityServiceOlmAuthRequest = { + ...BaseIdentityServiceOlmAuthRequest, + +watchedIDs: $ReadOnlyArray, + +platformDetails: PlatformDetails, +}; + export type UpdatePasswordRequest = { code: string, password: string, diff --git a/lib/types/endpoints.js b/lib/types/endpoints.js --- a/lib/types/endpoints.js +++ b/lib/types/endpoints.js @@ -93,6 +93,7 @@ VERIFY_INVITE_LINK: 'verify_invite_link', SIWE_NONCE: 'siwe_nonce', SIWE_AUTH: 'siwe_auth', + IDENTITY_SERVICE_OLM_AUTH: 'identity_service_olm_auth', UPDATE_USER_AVATAR: 'update_user_avatar', UPLOAD_MEDIA_METADATA: 'upload_media_metadata', SEARCH_MESSAGES: 'search_messages', 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 @@ -952,6 +952,22 @@ +payload: Error, +loadingInfo: LoadingInfo, } + | { + +type: 'IDENTITY_SERVICE_OLM_AUTH_STARTED', + +payload?: LogInStartingPayload, + +loadingInfo: LoadingInfo, + } + | { + +type: 'IDENTITY_SERVICE_OLM_AUTH_SUCCESS', + +payload?: LogInResult, + +loadingInfo: LoadingInfo, + } + | { + +type: 'IDENTITY_SERVICE_OLM_AUTH_FAILED', + +error: true, + +payload: Error, + +loadingInfo: LoadingInfo, + } | { +type: 'RECORD_NOTIF_PERMISSION_ALERT', +payload: { +time: number },