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 @@ -1,5 +1,6 @@ // @flow +import invariant from 'invariant'; import * as React from 'react'; import { @@ -417,6 +418,20 @@ ); } +const identityGenerateNonceActionTypes = 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; + invariant(identityClient, 'Identity client should be set'); + return React.useCallback(() => { + return identityClient.generateNonce(); + }, [identityClient]); +} + function mergeUserInfos( ...userInfoArrays: Array<$ReadOnlyArray> ): UserInfo[] { @@ -792,4 +807,6 @@ useKeyserverAuth, identityRegisterActionTypes, useIdentityRegister, + identityGenerateNonceActionTypes, + 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 @@ -437,6 +437,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,7 @@ identityAuthResultValidator, ); }, + generateNonce: 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,11 @@ return assertWithValidator(identityAuthResult, identityAuthResultValidator); }; + + generateNonce: () => Promise = async () => { + const result = await this.unauthClient.generateNonce(new Empty()); + return result.getNonce(); + }; } export { IdentityServiceClientWrapper };