Skip to content

Commit

Permalink
Merge branch 'main' into feature/uniqueness-of-key-for-relationshipat…
Browse files Browse the repository at this point in the history
…tributes
  • Loading branch information
mergify[bot] authored Dec 10, 2024
2 parents 23747b3 + e3f38c8 commit d17cdba
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 29 deletions.
27 changes: 12 additions & 15 deletions packages/transport/src/modules/accounts/AccountController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { DeviceController } from "../devices/DeviceController";
import { DeviceSecretType } from "../devices/DeviceSecretController";
import { DevicesController } from "../devices/DevicesController";
import { BackbonePutDevicesPushNotificationRequest, DeviceAuthClient } from "../devices/backbone/DeviceAuthClient";
import { DeviceClient } from "../devices/backbone/DeviceClient";
import { Device, DeviceInfo, DeviceType } from "../devices/local/Device";
import { DeviceSecretCredentials } from "../devices/local/DeviceSecretCredentials";
import { DeviceSharedSecret } from "../devices/transmission/DeviceSharedSecret";
Expand Down Expand Up @@ -48,7 +47,6 @@ export class AccountController {
return this._authenticator;
}

public deviceClient: DeviceClient;
public deviceAuthClient: DeviceAuthClient;
public identityClient: IdentityClient;

Expand Down Expand Up @@ -123,7 +121,6 @@ export class AccountController {
this.info = await this.db.getMap("AccountInfo");
this.unpushedDatawalletModifications = await this.db.getCollection(DbCollectionName.UnpushedDatawalletModifications);

this.deviceClient = new DeviceClient(this.config, this._transport.correlator);
this.identityClient = new IdentityClient(this.config, this._transport.correlator);

this._identity = new IdentityController(this);
Expand Down Expand Up @@ -281,7 +278,7 @@ export class AccountController {
const signedChallenge = await this.challenges.createAccountCreationChallenge(identityKeypair);
this._log.trace("Challenge signed. Creating device...");

const [deviceResponseResult, privSync, localAddress, deviceInfo] = await Promise.all([
const [createIdentityResponse, privSync, localAddress, deviceInfo] = await Promise.all([
// Register first device (and identity) on backbone
this.identityClient.createIdentity({
devicePassword: devicePwdD1,
Expand All @@ -299,30 +296,30 @@ export class AccountController {
this.fetchDeviceInfo()
]);

if (deviceResponseResult.isError) {
const error = deviceResponseResult.error;
if (createIdentityResponse.isError) {
const error = createIdentityResponse.error;
if (error.code === "error.platform.unauthorized") {
throw TransportCoreErrors.general.platformClientInvalid();
}
}

const deviceResponse = deviceResponseResult.value;
const createdIdentity = createIdentityResponse.value;

this._log.trace(`Registered identity with address ${deviceResponse.address}, device id is ${deviceResponse.device.id}.`);
this._log.trace(`Registered identity with address ${createdIdentity.address}, device id is ${createdIdentity.device.id}.`);

if (!localAddress.equals(deviceResponse.address)) {
throw new TransportError(`The backbone address '${deviceResponse.address}' does not match the local address '${localAddress.toString()}'.`);
if (!localAddress.equals(createdIdentity.address)) {
throw new TransportError(`The backbone address '${createdIdentity.address}' does not match the local address '${localAddress.toString()}'.`);
}

const identity = Identity.from({
address: CoreAddress.from(deviceResponse.address),
address: CoreAddress.from(createdIdentity.address),
publicKey: identityKeypair.publicKey
});

const deviceId = CoreId.from(deviceResponse.device.id);
const deviceId = CoreId.from(createdIdentity.device.id);

const device = Device.from({
createdAt: CoreDate.from(deviceResponse.createdAt),
createdAt: CoreDate.from(createdIdentity.createdAt),
createdByDevice: deviceId,
id: deviceId,
name: "Device 1",
Expand All @@ -331,7 +328,7 @@ export class AccountController {
publicKey: deviceKeypair.publicKey,
type: deviceInfo.type,
certificate: "",
username: deviceResponse.device.username,
username: createdIdentity.device.username,
datawalletVersion: this._config.supportedDatawalletVersion
});

Expand All @@ -342,7 +339,7 @@ export class AccountController {

const deviceCredentials = DeviceSecretCredentials.from({
id: device.id,
username: deviceResponse.device.username,
username: createdIdentity.device.username,
password: devicePwdD1
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export class DeviceAuthClient extends RESTClientAuthenticate {
protected override _logDirective = RESTClientLogDirective.LogResponse;

public async changeDevicePassword(input: BackbonePutDevicesPasswordRequest): Promise<ClientResult<void>> {
return await this.put<void>("/api/v1/Devices/Self/Password", input, {});
return await this.put<void>("/api/v1/Devices/Self/Password", input);
}

public async createDevice(value: BackbonePostDevicesRequest): Promise<ClientResult<BackbonePostDevicesResponse>> {
return await this.post<BackbonePostDevicesResponse>("/api/v1/Devices", value, {});
return await this.post<BackbonePostDevicesResponse>("/api/v1/Devices", value);
}

public async deleteDevice(deviceId: string): Promise<ClientResult<void>> {
Expand Down
11 changes: 0 additions & 11 deletions packages/transport/src/modules/devices/backbone/DeviceClient.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/transport/src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export * from "./challenges/data/ChallengeSigned";
export * from "./devices/backbone/BackbonePostDevices";
export * from "./devices/backbone/BackboneUpdateDevice";
export * from "./devices/backbone/DeviceAuthClient";
export * from "./devices/backbone/DeviceClient";
export * from "./devices/DeviceController";
export * from "./devices/DevicesController";
export * from "./devices/DeviceSecretController";
Expand Down

0 comments on commit d17cdba

Please sign in to comment.