refactor: add pkc fields for registration endpoint (#1680)

This commit is contained in:
Mo
2022-09-29 09:13:05 -05:00
committed by GitHub
parent 00075616e6
commit d7a90c4d91
6 changed files with 37 additions and 21 deletions

View File

@@ -24,7 +24,12 @@ describe('UserApiService', () => {
}) })
it('should register a user', async () => { it('should register a user', async () => {
const response = await createService().register('test@test.te', 'testpasswd', keyParams, false) const response = await createService().register({
email: 'test@test.te',
serverPassword: 'testpasswd',
keyParams,
ephemeral: false,
})
expect(response).toEqual({ expect(response).toEqual({
data: { data: {
@@ -52,7 +57,7 @@ describe('UserApiService', () => {
let error = null let error = null
try { try {
await service.register('test@test.te', 'testpasswd', keyParams, false) await service.register({ email: 'test@test.te', serverPassword: 'testpasswd', keyParams, ephemeral: false })
} catch (caughtError) { } catch (caughtError) {
error = caughtError error = caughtError
} }
@@ -67,7 +72,12 @@ describe('UserApiService', () => {
let error = null let error = null
try { try {
await createService().register('test@test.te', 'testpasswd', keyParams, false) await createService().register({
email: 'test@test.te',
serverPassword: 'testpasswd',
keyParams,
ephemeral: false,
})
} catch (caughtError) { } catch (caughtError) {
error = caughtError error = caughtError
} }

View File

@@ -15,12 +15,12 @@ export class UserApiService implements UserApiServiceInterface {
this.registering = false this.registering = false
} }
async register( async register(registerDTO: {
email: string, email: string
serverPassword: string, serverPassword: string
keyParams: RootKeyParamsInterface, keyParams: RootKeyParamsInterface
ephemeral: boolean, ephemeral: boolean
): Promise<UserRegistrationResponse> { }): Promise<UserRegistrationResponse> {
if (this.registering) { if (this.registering) {
throw new ApiCallError(ErrorMessage.RegistrationInProgress) throw new ApiCallError(ErrorMessage.RegistrationInProgress)
} }
@@ -29,10 +29,10 @@ export class UserApiService implements UserApiServiceInterface {
try { try {
const response = await this.userServer.register({ const response = await this.userServer.register({
[ApiEndpointParam.ApiVersion]: ApiVersion.v0, [ApiEndpointParam.ApiVersion]: ApiVersion.v0,
password: serverPassword, password: registerDTO.serverPassword,
email, email: registerDTO.email,
ephemeral, ephemeral: registerDTO.ephemeral,
...keyParams.getPortableValue(), ...registerDTO.keyParams.getPortableValue(),
}) })
this.registering = false this.registering = false

View File

@@ -2,10 +2,10 @@ import { RootKeyParamsInterface } from '@standardnotes/models'
import { UserRegistrationResponse } from '../../Response/User/UserRegistrationResponse' import { UserRegistrationResponse } from '../../Response/User/UserRegistrationResponse'
export interface UserApiServiceInterface { export interface UserApiServiceInterface {
register( register(registerDTO: {
email: string, email: string
serverPassword: string, serverPassword: string
keyParams: RootKeyParamsInterface, keyParams: RootKeyParamsInterface
ephemeral: boolean, ephemeral: boolean
): Promise<UserRegistrationResponse> }): Promise<UserRegistrationResponse>
} }

View File

@@ -8,4 +8,6 @@ export type UserRegistrationRequestParams = AnyKeyParamsContent & {
email: string email: string
ephemeral: boolean ephemeral: boolean
[additionalParam: string]: unknown [additionalParam: string]: unknown
pkcPublicKey?: string
pkcEncryptedPrivateKey?: string
} }

View File

@@ -286,7 +286,7 @@ export class SNSessionManager extends AbstractService<SessionEvent> implements S
const serverPassword = rootKey.serverPassword as string const serverPassword = rootKey.serverPassword as string
const keyParams = rootKey.keyParams const keyParams = rootKey.keyParams
const registerResponse = await this.userApiService.register(email, serverPassword, keyParams, ephemeral) const registerResponse = await this.userApiService.register({ email, serverPassword, keyParams, ephemeral })
if ('error' in registerResponse.data) { if ('error' in registerResponse.data) {
throw new ApiCallError((registerResponse.data as HttpErrorResponseBody).error.message) throw new ApiCallError((registerResponse.data as HttpErrorResponseBody).error.message)

View File

@@ -144,7 +144,11 @@ export async function registerOldUser({ application, email, password, version })
const operator = application.protocolService.operatorManager.operatorForVersion(version) const operator = application.protocolService.operatorManager.operatorForVersion(version)
const accountKey = await operator.createRootKey(email, password, KeyParamsOrigination.Registration) const accountKey = await operator.createRootKey(email, password, KeyParamsOrigination.Registration)
const response = await application.userApiService.register(email, accountKey.serverPassword, accountKey.keyParams) const response = await application.userApiService.register({
email: email,
serverPassword: accountKey.serverPassword,
keyParams: accountKey.keyParams,
})
/** Mark all existing items as dirty. */ /** Mark all existing items as dirty. */
await application.itemManager.changeItems(application.itemManager.items, (m) => { await application.itemManager.changeItems(application.itemManager.items, (m) => {
m.dirty = true m.dirty = true