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; +logOut: () => Promise; +getKeyserverKeys: string => Promise; + // Users cannot register from web +registerPasswordUser?: ( username: string, password: string, + fid: ?string, + ) => Promise; + // Users cannot register from web + +registerReservedPasswordUser?: ( + username: string, + password: string, + keyserverMessage: string, + keyserverSignature: string, ) => Promise; +logInPasswordUser: ( username: string, @@ -140,10 +149,20 @@ ) => Promise; +uploadOneTimeKeys: (oneTimeKeys: OneTimeKeysResultValues) => Promise; +generateNonce: () => Promise; + // Users cannot register from web +registerWalletUser?: ( walletAddress: string, siweMessage: string, siweSignature: string, + fid: ?string, + ) => Promise; + // Users cannot register from web + +registerReservedWalletUser?: ( + walletAddress: string, + siweMessage: string, + siweSignature: string, + keyserverMessage: string, + keyserverSignature: string, ) => Promise; +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 @@ -353,6 +353,53 @@ return validatedResult; }, + 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 registrationResult = + await commRustModule.registerReservedPasswordUser( + username, + password, + blobPayload, + signature, + prekeys.contentPrekey, + prekeys.contentPrekeySignature, + prekeys.notifPrekey, + prekeys.notifPrekeySignature, + getOneTimeKeyValues(contentOneTimeKeys), + getOneTimeKeyValues(notificationsOneTimeKeys), + keyserverMessage, + keyserverSignature, + ); + const { userID, accessToken: token } = JSON.parse(registrationResult); + const identityAuthResult = { accessToken: token, userID, username }; + + const validatedResult = assertWithValidator( + identityAuthResult, + identityAuthResultValidator, + ); + + await commCoreModule.setCommServicesAuthMetadata( + validatedResult.userID, + primaryIdentityPublicKeys.ed25519, + validatedResult.accessToken, + ); + + return validatedResult; + }, logInPasswordUser: async (username: string, password: string) => { await commCoreModule.initializeCryptoAccount(); const [{ blobPayload, signature, primaryIdentityPublicKeys }, prekeys] = @@ -435,6 +482,58 @@ return validatedResult; }, + 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 registrationResult = + await commRustModule.registerReservedWalletUser( + siweMessage, + siweSignature, + blobPayload, + signature, + prekeys.contentPrekey, + prekeys.contentPrekeySignature, + prekeys.notifPrekey, + prekeys.notifPrekeySignature, + getOneTimeKeyValues(contentOneTimeKeys), + getOneTimeKeyValues(notificationsOneTimeKeys), + keyserverMessage, + keyserverSignature, + ); + const { userID, accessToken: token } = JSON.parse(registrationResult); + const identityAuthResult = { + accessToken: token, + userID, + username: walletAddress, + }; + + const validatedResult = assertWithValidator( + identityAuthResult, + identityAuthResultValidator, + ); + + await commCoreModule.setCommServicesAuthMetadata( + validatedResult.userID, + primaryIdentityPublicKeys.ed25519, + validatedResult.accessToken, + ); + + return validatedResult; + }, logInWalletUser: async ( walletAddress: string, siweMessage: string,