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 @@ -417,6 +417,22 @@ ); } +const identityGenerateNonceTypes = Object.freeze({ + started: 'IDENTITY_GENERATE_NONCE_STARTED', + success: 'IDENTITY_GENERATE_NONCE_SUCCESS', + failed: 'IDENTITY_GENERATE_NONCE_FAILED', +}); +function useIdentityGenerateNonce(): () => Promise { + const client = React.useContext(IdentityClientContext); + const identityClient = client?.identityClient; + return React.useCallback(() => { + if (!identityClient) { + throw new Error('Identity service client is not initialized'); + } + return identityClient.generateNonce(); + }, [identityClient]); +} + function mergeUserInfos( ...userInfoArrays: Array<$ReadOnlyArray> ): UserInfo[] { @@ -792,4 +808,6 @@ useKeyserverAuth, identityRegisterActionTypes, useIdentityRegister, + identityGenerateNonceTypes, + useIdentityGenerateNonce, }; 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 @@ -66,6 +66,7 @@ +getOutboundKeysForUser: ( userID: string, ) => Promise; + +generateNonce: () => Promise; } export type IdentityServiceAuthLayer = { 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 @@ -407,6 +407,22 @@ +payload: IdentityAuthResult, +loadingInfo: LoadingInfo, } + | { + +type: 'IDENTITY_GENERATE_NONCE_STARTED', + +payload?: void, + +loadingInfo: LoadingInfo, + } + | { + +type: 'IDENTITY_GENERATE_NONCE_FAILED', + +error: true, + +payload: Error, + +loadingInfo: LoadingInfo, + } + | { + +type: 'IDENTITY_GENERATE_NONCE_SUCCESS', + +payload?: void, + +loadingInfo: LoadingInfo, + } | { +type: 'CHANGE_KEYSERVER_USER_PASSWORD_STARTED', +payload?: void, 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 @@ -264,6 +264,9 @@ identityAuthResultValidator, ); }, + generateNonce: async () => { + return commRustModule.generateNonce(); + }, }), [getAuthMetadata], ); diff --git a/web/grpc/identity-service-client-wrapper.js b/web/grpc/identity-service-client-wrapper.js --- a/web/grpc/identity-service-client-wrapper.js +++ b/web/grpc/identity-service-client-wrapper.js @@ -313,6 +313,14 @@ return assertWithValidator(identityAuthResult, identityAuthResultValidator); }; + + generateNonce: () => Promise = async () => { + if (!this.unauthClient) { + throw new Error('Identity service client is not initialized'); + } + const result = await this.unauthClient.generateNonce(new Empty()); + return result.getNonce(); + }; } export { IdentityServiceClientWrapper };