feat(encryption): refactor circular dependencies on services
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { SnjsVersion } from './../Version'
|
||||
import {
|
||||
HttpService,
|
||||
HttpServiceInterface,
|
||||
@@ -10,13 +9,11 @@ import {
|
||||
} from '@standardnotes/api'
|
||||
import * as Common from '@standardnotes/common'
|
||||
import * as ExternalServices from '@standardnotes/services'
|
||||
import * as Encryption from '@standardnotes/encryption'
|
||||
import * as Models from '@standardnotes/models'
|
||||
import * as Responses from '@standardnotes/responses'
|
||||
import * as InternalServices from '../Services'
|
||||
import * as Utils from '@standardnotes/utils'
|
||||
import * as Settings from '@standardnotes/settings'
|
||||
import * as Files from '@standardnotes/files'
|
||||
import { Subscription } from '@standardnotes/security'
|
||||
import { UuidString, ApplicationEventPayload } from '../Types'
|
||||
import { applicationEventForSyncEvent } from '@Lib/Application/Event'
|
||||
@@ -36,11 +33,19 @@ import {
|
||||
DeinitSource,
|
||||
AppGroupManagedApplication,
|
||||
ApplicationInterface,
|
||||
EncryptionService,
|
||||
EncryptionServiceEvent,
|
||||
FilesBackupService,
|
||||
FileService,
|
||||
} from '@standardnotes/services'
|
||||
import { SNLog } from '../Log'
|
||||
import { FilesClientInterface } from '@standardnotes/files'
|
||||
import { ComputePrivateWorkspaceIdentifier } from '@standardnotes/encryption'
|
||||
import { useBoolean } from '@standardnotes/utils'
|
||||
import { BackupFile, DecryptedItemInterface, EncryptedItemInterface, ItemStream } from '@standardnotes/models'
|
||||
import { ClientDisplayableError } from '@standardnotes/responses'
|
||||
|
||||
import { SnjsVersion } from './../Version'
|
||||
import { SNLog } from '../Log'
|
||||
import { Challenge, ChallengeResponse } from '../Services'
|
||||
import { ApplicationConstructorOptions, FullyResolvedApplicationOptions } from './Options/ApplicationOptions'
|
||||
import { ApplicationOptionsDefaults } from './Options/Defaults'
|
||||
@@ -78,7 +83,7 @@ export class SNApplication
|
||||
private deprecatedHttpService!: InternalServices.SNHttpService
|
||||
private declare httpService: HttpServiceInterface
|
||||
private payloadManager!: InternalServices.PayloadManager
|
||||
public protocolService!: Encryption.EncryptionService
|
||||
public protocolService!: EncryptionService
|
||||
private diskStorageService!: InternalServices.DiskStorageService
|
||||
private inMemoryStore!: ExternalServices.KeyValueStoreInterface<string>
|
||||
/**
|
||||
@@ -104,11 +109,11 @@ export class SNApplication
|
||||
private settingsService!: InternalServices.SNSettingsService
|
||||
private mfaService!: InternalServices.SNMfaService
|
||||
private listedService!: InternalServices.ListedService
|
||||
private fileService!: Files.FileService
|
||||
private fileService!: FileService
|
||||
private mutatorService!: InternalServices.MutatorService
|
||||
private integrityService!: ExternalServices.IntegrityService
|
||||
private statusService!: ExternalServices.StatusService
|
||||
private filesBackupService?: Files.FilesBackupService
|
||||
private filesBackupService?: FilesBackupService
|
||||
|
||||
private internalEventBus!: ExternalServices.InternalEventBusInterface
|
||||
|
||||
@@ -182,7 +187,7 @@ export class SNApplication
|
||||
this.defineInternalEventHandlers()
|
||||
}
|
||||
|
||||
public get files(): Files.FilesClientInterface {
|
||||
public get files(): FilesClientInterface {
|
||||
return this.fileService
|
||||
}
|
||||
|
||||
@@ -222,7 +227,7 @@ export class SNApplication
|
||||
return this.statusService
|
||||
}
|
||||
|
||||
public get fileBackups(): Files.FilesBackupService | undefined {
|
||||
public get fileBackups(): FilesBackupService | undefined {
|
||||
return this.filesBackupService
|
||||
}
|
||||
|
||||
@@ -231,7 +236,7 @@ export class SNApplication
|
||||
}
|
||||
|
||||
public computePrivateWorkspaceIdentifier(userphrase: string, name: string): Promise<string | undefined> {
|
||||
return Encryption.ComputePrivateWorkspaceIdentifier(this.options.crypto, userphrase, name)
|
||||
return ComputePrivateWorkspaceIdentifier(this.options.crypto, userphrase, name)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1117,7 +1122,7 @@ export class SNApplication
|
||||
}
|
||||
|
||||
private createFileService() {
|
||||
this.fileService = new Files.FileService(
|
||||
this.fileService = new FileService(
|
||||
this.apiService,
|
||||
this.itemManager,
|
||||
this.syncService,
|
||||
@@ -1328,7 +1333,7 @@ export class SNApplication
|
||||
}
|
||||
|
||||
private createProtocolService() {
|
||||
this.protocolService = new Encryption.EncryptionService(
|
||||
this.protocolService = new EncryptionService(
|
||||
this.itemManager,
|
||||
this.payloadManager,
|
||||
this.deviceInterface,
|
||||
@@ -1339,7 +1344,7 @@ export class SNApplication
|
||||
)
|
||||
this.serviceObservers.push(
|
||||
this.protocolService.addEventObserver(async (event) => {
|
||||
if (event === Encryption.EncryptionServiceEvent.RootKeyStatusChanged) {
|
||||
if (event === EncryptionServiceEvent.RootKeyStatusChanged) {
|
||||
await this.notifyEvent(ApplicationEvent.KeyStatusChanged)
|
||||
}
|
||||
}),
|
||||
@@ -1539,7 +1544,7 @@ export class SNApplication
|
||||
}
|
||||
|
||||
private createFilesBackupService(device: ExternalServices.DesktopDeviceInterface): void {
|
||||
this.filesBackupService = new Files.FilesBackupService(
|
||||
this.filesBackupService = new FilesBackupService(
|
||||
this.itemManager,
|
||||
this.apiService,
|
||||
this.protocolService,
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { SNSessionManager } from '../Services/Session/SessionManager'
|
||||
import { ApplicationIdentifier } from '@standardnotes/common'
|
||||
import { ItemManager } from '@Lib/Services/Items/ItemManager'
|
||||
import { EncryptionService } from '@standardnotes/encryption'
|
||||
import { DeviceInterface, InternalEventBusInterface, Environment } from '@standardnotes/services'
|
||||
import { DeviceInterface, InternalEventBusInterface, Environment, EncryptionService } from '@standardnotes/services'
|
||||
import { ChallengeService, SNSingletonManager, SNFeaturesService, DiskStorageService } from '@Lib/Services'
|
||||
|
||||
export type MigrationServices = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { EncryptionService, SNRootKey } from '@standardnotes/encryption'
|
||||
import { SNRootKey } from '@standardnotes/encryption'
|
||||
import { Challenge, ChallengeService } from '../Challenge'
|
||||
import { ListedService } from '../Listed/ListedService'
|
||||
import { ActionResponse, HttpResponse } from '@standardnotes/responses'
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
ChallengeValidation,
|
||||
ChallengeReason,
|
||||
ChallengePrompt,
|
||||
EncryptionService,
|
||||
} from '@standardnotes/services'
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,9 +12,10 @@ import {
|
||||
ApiServiceEvent,
|
||||
MetaReceivedData,
|
||||
DiagnosticInfo,
|
||||
FilesApiInterface,
|
||||
KeyValueStoreInterface,
|
||||
} from '@standardnotes/services'
|
||||
import { FilesApiInterface } from '@standardnotes/files'
|
||||
|
||||
import { ServerSyncPushContextualPayload, SNFeatureRepo, FileContent } from '@standardnotes/models'
|
||||
import * as Responses from '@standardnotes/responses'
|
||||
import { API_MESSAGE_FAILED_OFFLINE_ACTIVATION } from '@Lib/Services/Api/Messages'
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { RootKeyInterface } from '@standardnotes/models'
|
||||
import { EncryptionService } from '@standardnotes/encryption'
|
||||
import { DiskStorageService } from '../Storage/DiskStorageService'
|
||||
import { removeFromArray } from '@standardnotes/utils'
|
||||
import { isValidProtectionSessionLength } from '../Protection/ProtectionService'
|
||||
@@ -14,6 +13,7 @@ import {
|
||||
ChallengeInterface,
|
||||
ChallengePromptInterface,
|
||||
ChallengePrompt,
|
||||
EncryptionService,
|
||||
} from '@standardnotes/services'
|
||||
import { ChallengeResponse } from './ChallengeResponse'
|
||||
import { ChallengeOperation } from './ChallengeOperation'
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { ContentType, Uuid } from '@standardnotes/common'
|
||||
import { EncryptionService } from '@standardnotes/encryption'
|
||||
import { isNullOrUndefined, removeFromArray } from '@standardnotes/utils'
|
||||
import { ItemManager } from '@Lib/Services/Items/ItemManager'
|
||||
import { SNApiService } from '@Lib/Services/Api/ApiService'
|
||||
@@ -7,8 +6,8 @@ import { DiskStorageService } from '@Lib/Services/Storage/DiskStorageService'
|
||||
import { UuidString } from '../../Types/UuidString'
|
||||
import * as Models from '@standardnotes/models'
|
||||
import * as Responses from '@standardnotes/responses'
|
||||
import * as Services from '@standardnotes/services'
|
||||
import { isErrorDecryptingPayload, PayloadTimestampDefaults, SNNote } from '@standardnotes/models'
|
||||
import { AbstractService, EncryptionService, DeviceInterface, InternalEventBusInterface } from '@standardnotes/services'
|
||||
|
||||
/** The amount of revisions per item above which should call for an optimization. */
|
||||
const DefaultItemRevisionsThreshold = 20
|
||||
@@ -28,7 +27,7 @@ const LargeEntryDeltaThreshold = 25
|
||||
* 2. Remote server history. Entries are automatically added by the server and must be
|
||||
* retrieved per item via an API call.
|
||||
*/
|
||||
export class SNHistoryManager extends Services.AbstractService {
|
||||
export class SNHistoryManager extends AbstractService {
|
||||
private removeChangeObserver: () => void
|
||||
|
||||
/**
|
||||
@@ -49,8 +48,8 @@ export class SNHistoryManager extends Services.AbstractService {
|
||||
private storageService: DiskStorageService,
|
||||
private apiService: SNApiService,
|
||||
private protocolService: EncryptionService,
|
||||
public deviceInterface: Services.DeviceInterface,
|
||||
protected override internalEventBus: Services.InternalEventBusInterface,
|
||||
public deviceInterface: DeviceInterface,
|
||||
protected override internalEventBus: InternalEventBusInterface,
|
||||
) {
|
||||
super(internalEventBus)
|
||||
this.removeChangeObserver = this.itemManager.addObserver(ContentType.Note, ({ changed, inserted }) => {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { ContentType } from '@standardnotes/common'
|
||||
import { ItemsKeyInterface } from '@standardnotes/models'
|
||||
import { dateSorted } from '@standardnotes/utils'
|
||||
import { SNRootKeyParams, DecryptItemsKeyByPromptingUser, EncryptionProvider } from '@standardnotes/encryption'
|
||||
import { SNRootKeyParams, EncryptionProvider } from '@standardnotes/encryption'
|
||||
import { DecryptionQueueItem, KeyRecoveryOperationResult } from './Types'
|
||||
import { serverKeyParamsAreSafe } from './Utils'
|
||||
import { ChallengeServiceInterface } from '@standardnotes/services'
|
||||
import { ChallengeServiceInterface, DecryptItemsKeyByPromptingUser } from '@standardnotes/services'
|
||||
import { ItemManager } from '../Items'
|
||||
|
||||
export class KeyRecoveryOperation {
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
import { KeyRecoveryOperation } from './KeyRecoveryOperation'
|
||||
import {
|
||||
SNRootKeyParams,
|
||||
EncryptionService,
|
||||
SNRootKey,
|
||||
KeyParamsFromApiResponse,
|
||||
KeyRecoveryStrings,
|
||||
} from '@standardnotes/encryption'
|
||||
import { SNRootKeyParams, SNRootKey, KeyParamsFromApiResponse, KeyRecoveryStrings } from '@standardnotes/encryption'
|
||||
import { UserService } from '../User/UserService'
|
||||
import {
|
||||
isErrorDecryptingPayload,
|
||||
@@ -37,6 +31,7 @@ import {
|
||||
ChallengeValidation,
|
||||
ChallengeReason,
|
||||
ChallengePrompt,
|
||||
EncryptionService,
|
||||
} from '@standardnotes/services'
|
||||
import {
|
||||
UndecryptableItemsStorage,
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { SNHistoryManager } from './../History/HistoryManager'
|
||||
import { NoteContent, SNNote, FillItemContent, DecryptedPayload, PayloadTimestampDefaults } from '@standardnotes/models'
|
||||
import { EncryptionService } from '@standardnotes/encryption'
|
||||
import { ContentType } from '@standardnotes/common'
|
||||
import { InternalEventBusInterface } from '@standardnotes/services'
|
||||
import { EncryptionService, InternalEventBusInterface } from '@standardnotes/services'
|
||||
import {
|
||||
ChallengeService,
|
||||
MutatorService,
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { ChallengeService } from '../Challenge'
|
||||
import { EncryptionService } from '@standardnotes/encryption'
|
||||
import { DiskStorageService } from '../Storage/DiskStorageService'
|
||||
import { SNProtectionService } from './ProtectionService'
|
||||
import { InternalEventBus, InternalEventBusInterface, ChallengeReason } from '@standardnotes/services'
|
||||
import {
|
||||
InternalEventBus,
|
||||
InternalEventBusInterface,
|
||||
ChallengeReason,
|
||||
EncryptionService,
|
||||
} from '@standardnotes/services'
|
||||
import { UuidGenerator } from '@standardnotes/utils'
|
||||
import {
|
||||
DecryptedPayload,
|
||||
|
||||
@@ -2,7 +2,6 @@ import { Challenge } from './../Challenge/Challenge'
|
||||
import { ChallengeService } from './../Challenge/ChallengeService'
|
||||
import { SNLog } from '@Lib/Log'
|
||||
import { DecryptedItem } from '@standardnotes/models'
|
||||
import { EncryptionService } from '@standardnotes/encryption'
|
||||
import { DiskStorageService } from '@Lib/Services/Storage/DiskStorageService'
|
||||
import { isNullOrUndefined } from '@standardnotes/utils'
|
||||
import {
|
||||
@@ -15,6 +14,7 @@ import {
|
||||
ChallengeReason,
|
||||
ChallengePrompt,
|
||||
ChallengeValidation,
|
||||
EncryptionService,
|
||||
} from '@standardnotes/services'
|
||||
import { ProtectionsClientInterface } from './ClientInterface'
|
||||
import { ContentType } from '@standardnotes/common'
|
||||
|
||||
@@ -9,19 +9,14 @@ import {
|
||||
ChallengeKeyboardType,
|
||||
ChallengeReason,
|
||||
ChallengePromptTitle,
|
||||
EncryptionService,
|
||||
} from '@standardnotes/services'
|
||||
import { Base64String } from '@standardnotes/sncrypto-common'
|
||||
import { ClientDisplayableError } from '@standardnotes/responses'
|
||||
import { CopyPayloadWithContentOverride } from '@standardnotes/models'
|
||||
import { isNullOrUndefined } from '@standardnotes/utils'
|
||||
import { JwtSession } from './Sessions/JwtSession'
|
||||
import {
|
||||
KeyParamsFromApiResponse,
|
||||
SNRootKeyParams,
|
||||
SNRootKey,
|
||||
EncryptionService,
|
||||
CreateNewRootKey,
|
||||
} from '@standardnotes/encryption'
|
||||
import { KeyParamsFromApiResponse, SNRootKeyParams, SNRootKey, CreateNewRootKey } from '@standardnotes/encryption'
|
||||
import { SessionStrings, SignInStrings } from '../Api/Messages'
|
||||
import { RemoteSession, RawStorageValue } from './Sessions/Types'
|
||||
import { Session } from './Sessions/Session'
|
||||
|
||||
@@ -26,7 +26,6 @@ import { ServerSyncResponse } from '@Lib/Services/Sync/Account/Response'
|
||||
import { ServerSyncResponseResolver } from '@Lib/Services/Sync/Account/ResponseResolver'
|
||||
import { SyncSignal, SyncStats } from '@Lib/Services/Sync/Signals'
|
||||
import { UuidString } from '../../Types/UuidString'
|
||||
import * as Encryption from '@standardnotes/encryption'
|
||||
import {
|
||||
PayloadSource,
|
||||
CreateDecryptedItemFromPayload,
|
||||
@@ -73,9 +72,15 @@ import {
|
||||
SyncQueueStrategy,
|
||||
SyncServiceInterface,
|
||||
DiagnosticInfo,
|
||||
EncryptionService,
|
||||
} from '@standardnotes/services'
|
||||
import { OfflineSyncResponse } from './Offline/Response'
|
||||
import { KeyedDecryptionSplit, SplitPayloadsByEncryptionType } from '@standardnotes/encryption'
|
||||
import {
|
||||
CreateDecryptionSplitWithKeyLookup,
|
||||
CreateEncryptionSplitWithKeyLookup,
|
||||
KeyedDecryptionSplit,
|
||||
SplitPayloadsByEncryptionType,
|
||||
} from '@standardnotes/encryption'
|
||||
import { CreatePayloadFromRawServerItem } from './Account/Utilities'
|
||||
import { ApplicationSyncOptions } from '@Lib/Application/Options/OptionalOptions'
|
||||
|
||||
@@ -131,7 +136,7 @@ export class SNSyncService
|
||||
constructor(
|
||||
private itemManager: ItemManager,
|
||||
private sessionManager: SNSessionManager,
|
||||
private protocolService: Encryption.EncryptionService,
|
||||
private protocolService: EncryptionService,
|
||||
private storageService: DiskStorageService,
|
||||
private payloadManager: PayloadManager,
|
||||
private apiService: SNApiService,
|
||||
@@ -226,7 +231,7 @@ export class SNSyncService
|
||||
isDecryptedPayload,
|
||||
) as DecryptedPayloadInterface<ItemsKeyContent>[]
|
||||
|
||||
const itemsKeysSplit: Encryption.KeyedDecryptionSplit = {
|
||||
const itemsKeysSplit: KeyedDecryptionSplit = {
|
||||
usesRootKeyWithKeyLookup: {
|
||||
items: encryptedItemsKeysPayloads,
|
||||
},
|
||||
@@ -301,7 +306,7 @@ export class SNSyncService
|
||||
}
|
||||
}
|
||||
|
||||
const split: Encryption.KeyedDecryptionSplit = {
|
||||
const split: KeyedDecryptionSplit = {
|
||||
usesItemsKeyWithKeyLookup: {
|
||||
items: encrypted,
|
||||
},
|
||||
@@ -440,9 +445,9 @@ export class SNSyncService
|
||||
): Promise<ServerSyncPushContextualPayload[]> {
|
||||
const payloadSplit = CreatePayloadSplit(payloads)
|
||||
|
||||
const encryptionSplit = Encryption.SplitPayloadsByEncryptionType(payloadSplit.decrypted)
|
||||
const encryptionSplit = SplitPayloadsByEncryptionType(payloadSplit.decrypted)
|
||||
|
||||
const keyLookupSplit = Encryption.CreateEncryptionSplitWithKeyLookup(encryptionSplit)
|
||||
const keyLookupSplit = CreateEncryptionSplitWithKeyLookup(encryptionSplit)
|
||||
|
||||
const encryptedResults = await this.protocolService.encryptSplit(keyLookupSplit)
|
||||
|
||||
@@ -973,7 +978,7 @@ export class SNSyncService
|
||||
? (CreateDecryptedItemFromPayload(previouslyProcessedItemsKey) as ItemsKeyInterface)
|
||||
: undefined
|
||||
|
||||
const keyedSplit: Encryption.KeyedDecryptionSplit = {}
|
||||
const keyedSplit: KeyedDecryptionSplit = {}
|
||||
if (itemsKey) {
|
||||
keyedSplit.usesItemsKey = {
|
||||
items: [encrypted],
|
||||
@@ -1162,9 +1167,9 @@ export class SNSyncService
|
||||
|
||||
const payloadSplit = CreateNonDecryptedPayloadSplit(receivedPayloads)
|
||||
|
||||
const encryptionSplit = Encryption.SplitPayloadsByEncryptionType(payloadSplit.encrypted)
|
||||
const encryptionSplit = SplitPayloadsByEncryptionType(payloadSplit.encrypted)
|
||||
|
||||
const keyedSplit = Encryption.CreateDecryptionSplitWithKeyLookup(encryptionSplit)
|
||||
const keyedSplit = CreateDecryptionSplitWithKeyLookup(encryptionSplit)
|
||||
|
||||
const decryptionResults = await this.protocolService.decryptSplit(keyedSplit)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Challenge } from '../Challenge'
|
||||
import { ChallengeService } from '../Challenge/ChallengeService'
|
||||
import { EncryptionService, SNRootKey, SNRootKeyParams } from '@standardnotes/encryption'
|
||||
import { SNRootKey, SNRootKeyParams } from '@standardnotes/encryption'
|
||||
import { HttpResponse, SignInResponse, User } from '@standardnotes/responses'
|
||||
import { ItemManager } from '@Lib/Services/Items/ItemManager'
|
||||
import { KeyParamsOrigination } from '@standardnotes/common'
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
InternalEventBusInterface,
|
||||
UserClientInterface,
|
||||
StoragePersistencePolicies,
|
||||
EncryptionService,
|
||||
} from '@standardnotes/services'
|
||||
import { SNApiService } from './../Api/ApiService'
|
||||
import { SNProtectionService } from '../Protection/ProtectionService'
|
||||
|
||||
Reference in New Issue
Block a user