fix: extract encryption type split functions
This commit is contained in:
@@ -40,7 +40,7 @@ import {
|
||||
isEncryptedPayload,
|
||||
RootKeyInterface,
|
||||
} from '@standardnotes/models'
|
||||
import { SplitPayloadsByEncryptionType } from '../../Split/EncryptionTypeSplit'
|
||||
import { SplitPayloadsByEncryptionType } from '../../Split/Functions'
|
||||
import { ClientDisplayableError } from '@standardnotes/responses'
|
||||
import { isNotUndefined } from '@standardnotes/utils'
|
||||
import { DiagnosticInfo } from '@standardnotes/services'
|
||||
|
||||
@@ -1,27 +1,6 @@
|
||||
import { DecryptedPayloadInterface, EncryptedPayloadInterface } from '@standardnotes/models'
|
||||
import { ItemContentTypeUsesRootKeyEncryption } from '../Keys/RootKey/Functions'
|
||||
|
||||
export interface EncryptionTypeSplit<T = EncryptedPayloadInterface | DecryptedPayloadInterface> {
|
||||
rootKeyEncryption?: T[]
|
||||
itemsKeyEncryption?: T[]
|
||||
}
|
||||
|
||||
export function SplitPayloadsByEncryptionType<T extends EncryptedPayloadInterface | DecryptedPayloadInterface>(
|
||||
payloads: T[],
|
||||
): EncryptionTypeSplit<T> {
|
||||
const usesRootKey: T[] = []
|
||||
const usesItemsKey: T[] = []
|
||||
|
||||
for (const item of payloads) {
|
||||
if (ItemContentTypeUsesRootKeyEncryption(item.content_type)) {
|
||||
usesRootKey.push(item)
|
||||
} else {
|
||||
usesItemsKey.push(item)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
rootKeyEncryption: usesRootKey.length > 0 ? usesRootKey : undefined,
|
||||
itemsKeyEncryption: usesItemsKey.length > 0 ? usesItemsKey : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
23
packages/encryption/src/Domain/Split/Functions.ts
Normal file
23
packages/encryption/src/Domain/Split/Functions.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { DecryptedPayloadInterface, EncryptedPayloadInterface } from '@standardnotes/models'
|
||||
import { ItemContentTypeUsesRootKeyEncryption } from '../Keys/RootKey/Functions'
|
||||
import { EncryptionTypeSplit } from './EncryptionTypeSplit'
|
||||
|
||||
export function SplitPayloadsByEncryptionType<T extends EncryptedPayloadInterface | DecryptedPayloadInterface>(
|
||||
payloads: T[],
|
||||
): EncryptionTypeSplit<T> {
|
||||
const usesRootKey: T[] = []
|
||||
const usesItemsKey: T[] = []
|
||||
|
||||
for (const item of payloads) {
|
||||
if (ItemContentTypeUsesRootKeyEncryption(item.content_type)) {
|
||||
usesRootKey.push(item)
|
||||
} else {
|
||||
usesItemsKey.push(item)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
rootKeyEncryption: usesRootKey.length > 0 ? usesRootKey : undefined,
|
||||
itemsKeyEncryption: usesItemsKey.length > 0 ? usesItemsKey : undefined,
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ export * from './Service/RootKey/KeyMode'
|
||||
export * from './Service/RootKey/RootKeyEncryption'
|
||||
export * from './Split/EncryptionSplit'
|
||||
export * from './Split/EncryptionTypeSplit'
|
||||
export * from './Split/Functions'
|
||||
export * from './Types/EncryptedParameters'
|
||||
export * from './Types/ItemAuthenticatedData'
|
||||
export * from './Types/LegacyAttachedData'
|
||||
|
||||
Reference in New Issue
Block a user