-
-
Notifications
You must be signed in to change notification settings - Fork 393
/
CreateUserInputKeySystemRootKey.ts
34 lines (29 loc) · 1.14 KB
/
CreateUserInputKeySystemRootKey.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
import { V004Algorithm } from '../../../../Algorithm'
import {
KeySystemIdentifier,
KeySystemRootKeyInterface,
KeySystemRootKeyParamsInterface,
KeySystemPasswordType,
} from '@standardnotes/models'
import { ProtocolVersion } from '@standardnotes/common'
import { DeriveKeySystemRootKeyUseCase } from './DeriveKeySystemRootKey'
export class CreateUserInputKeySystemRootKey {
constructor(private readonly crypto: PureCryptoInterface) {}
execute(dto: { systemIdentifier: KeySystemIdentifier; userInputtedPassword: string }): KeySystemRootKeyInterface {
const version = ProtocolVersion.V004
const seed = this.crypto.generateRandomKey(V004Algorithm.ArgonSaltSeedLength)
const keyParams: KeySystemRootKeyParamsInterface = {
systemIdentifier: dto.systemIdentifier,
passwordType: KeySystemPasswordType.UserInputted,
creationTimestamp: new Date().getTime(),
seed,
version,
}
const usecase = new DeriveKeySystemRootKeyUseCase(this.crypto)
return usecase.execute({
password: dto.userInputtedPassword,
keyParams,
})
}
}