-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/prevent_repositoy_attribute_duplicates
- Loading branch information
Showing
23 changed files
with
390 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
BACKBONE_VERSION=6.22.0 | ||
BACKBONE_VERSION=6.23.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/runtime/src/extensibility/facades/transport/IdentityRecoveryKitsFacade.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Result } from "@js-soft/ts-utils"; | ||
import { Inject } from "@nmshd/typescript-ioc"; | ||
import { TokenDTO } from "../../../types"; | ||
import { | ||
CheckForExistingIdentityRecoveryKitResponse, | ||
CheckForExistingIdentityRecoveryKitUseCase, | ||
CreateIdentityRecoveryKitRequest, | ||
CreateIdentityRecoveryKitUseCase | ||
} from "../../../useCases"; | ||
|
||
export class IdentityRecoveryKitsFacade { | ||
public constructor( | ||
@Inject private readonly createIdentityRecoveryKitUseCase: CreateIdentityRecoveryKitUseCase, | ||
@Inject private readonly checkForExistingIdentityRecoveryKitUseCase: CheckForExistingIdentityRecoveryKitUseCase | ||
) {} | ||
|
||
public async createIdentityRecoveryKit(request: CreateIdentityRecoveryKitRequest): Promise<Result<TokenDTO>> { | ||
return await this.createIdentityRecoveryKitUseCase.execute(request); | ||
} | ||
|
||
public async checkForExistingIdentityRecoveryKit(): Promise<Result<CheckForExistingIdentityRecoveryKitResponse>> { | ||
return await this.checkForExistingIdentityRecoveryKitUseCase.execute(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...untime/src/useCases/transport/identityRecoveryKits/CheckForExistingIdentityRecoveryKit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Result } from "@js-soft/ts-utils"; | ||
import { DevicesController } from "@nmshd/transport"; | ||
import { Inject } from "@nmshd/typescript-ioc"; | ||
import { UseCase } from "../../common"; | ||
|
||
export interface CheckForExistingIdentityRecoveryKitResponse { | ||
exists: boolean; | ||
} | ||
|
||
export class CheckForExistingIdentityRecoveryKitUseCase extends UseCase<void, CheckForExistingIdentityRecoveryKitResponse> { | ||
public constructor(@Inject private readonly devicesController: DevicesController) { | ||
super(); | ||
} | ||
|
||
protected async executeInternal(): Promise<Result<CheckForExistingIdentityRecoveryKitResponse>> { | ||
const devices = await this.devicesController.list(); | ||
|
||
return Result.ok({ | ||
exists: devices.some((device) => device.isBackupDevice) | ||
}); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
packages/runtime/src/useCases/transport/identityRecoveryKits/CreateIdentityRecoveryKit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Result } from "@js-soft/ts-utils"; | ||
import { CoreDate } from "@nmshd/core-types"; | ||
import { AccountController, Device, DevicesController, PasswordProtectionCreationParameters, TokenContentDeviceSharedSecret, TokenController } from "@nmshd/transport"; | ||
import { Inject } from "@nmshd/typescript-ioc"; | ||
import { TokenDTO } from "../../../types"; | ||
import { RuntimeErrors, SchemaRepository, TokenAndTemplateCreationValidator, UseCase } from "../../common"; | ||
import { TokenMapper } from "../tokens/TokenMapper"; | ||
|
||
export interface CreateIdentityRecoveryKitRequest { | ||
profileName: string; | ||
passwordProtection: { | ||
/** | ||
* @minLength 1 | ||
*/ | ||
password: string; | ||
passwordIsPin?: true; | ||
}; | ||
} | ||
|
||
class Validator extends TokenAndTemplateCreationValidator<CreateIdentityRecoveryKitRequest> { | ||
public constructor(@Inject schemaRepository: SchemaRepository) { | ||
super(schemaRepository.getSchema("CreateIdentityRecoveryKitRequest")); | ||
} | ||
} | ||
|
||
export class CreateIdentityRecoveryKitUseCase extends UseCase<CreateIdentityRecoveryKitRequest, TokenDTO> { | ||
public constructor( | ||
@Inject private readonly devicesController: DevicesController, | ||
@Inject private readonly tokenController: TokenController, | ||
@Inject private readonly accountController: AccountController, | ||
@Inject validator: Validator | ||
) { | ||
super(validator); | ||
} | ||
|
||
protected async executeInternal(request: CreateIdentityRecoveryKitRequest): Promise<Result<TokenDTO>> { | ||
if (!this.accountController.config.datawalletEnabled) return Result.fail(RuntimeErrors.identityRecoveryKits.datawalletDisabled()); | ||
|
||
const devices = await this.devicesController.list(); | ||
|
||
const backupDevices = devices.filter((device) => device.isBackupDevice); | ||
if (backupDevices.length > 0) await this.removeBackupDevices(backupDevices); | ||
|
||
const newBackupDevice = await this.devicesController.sendDevice({ isAdmin: true, isBackupDevice: true, name: "Backup Device" }); | ||
const sharedSecret = await this.devicesController.getSharedSecret(newBackupDevice.id, request.profileName); | ||
const token = await this.tokenController.sendToken({ | ||
content: TokenContentDeviceSharedSecret.from({ sharedSecret }), | ||
expiresAt: CoreDate.from("9999-12-31"), | ||
ephemeral: false, | ||
passwordProtection: PasswordProtectionCreationParameters.create(request.passwordProtection) | ||
}); | ||
|
||
await this.accountController.syncDatawallet(); | ||
|
||
return Result.ok(TokenMapper.toTokenDTO(token, false)); | ||
} | ||
|
||
private async removeBackupDevices(backupDevices: Device[]) { | ||
for (const backupDevice of backupDevices) { | ||
const matchingTokens = await this.tokenController.getTokens({ | ||
"cache.content.@type": "TokenContentDeviceSharedSecret", | ||
"cache.content.sharedSecret.id": backupDevice.id.toString() | ||
}); | ||
|
||
for (const matchingToken of matchingTokens) { | ||
await this.tokenController.delete(matchingToken); | ||
} | ||
|
||
await this.devicesController.delete(backupDevice); | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/runtime/src/useCases/transport/identityRecoveryKits/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./CheckForExistingIdentityRecoveryKit"; | ||
export * from "./CreateIdentityRecoveryKit"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.