feat(encryption): refactor circular dependencies on services
This commit is contained in:
@@ -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