Skip to content

Commit

Permalink
chore(encryption): lint
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Jul 5, 2022
1 parent 37d765a commit 0cbd982
Show file tree
Hide file tree
Showing 32 changed files with 245 additions and 140 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 5 additions & 2 deletions packages/encryption/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@
"prebuild": "yarn clean",
"build": "tsc -p tsconfig.json",
"lint": "eslint . --ext .ts",
"format": "prettier --write src",
"test": "jest"
},
"devDependencies": {
"@standardnotes/config": "2.4.3",
"@types/jest": "^27.4.1",
"@types/node": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^5.30.0",
"@typescript-eslint/eslint-plugin": "*",
"eslint": "*",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^27.5.1",
"prettier": "*",
"ts-jest": "^27.1.3",
"typescript": "^4.7.4"
"typescript": "*"
},
"dependencies": {
"@standardnotes/common": "^1.23.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/encryption/src/Domain/Backups/BackupFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BackupFileDecryptedContextualPayload, BackupFileEncryptedContextualPayload } from '@standardnotes/models'
import { AnyKeyParamsContent, ProtocolVersion } from '@standardnotes/common'
import { BackupFileDecryptedContextualPayload, BackupFileEncryptedContextualPayload } from '@standardnotes/models'

export type BackupFile = {
version?: ProtocolVersion
Expand Down
34 changes: 17 additions & 17 deletions packages/encryption/src/Domain/Backups/BackupFileDecryptor.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import {
AnyKeyParamsContent,
compareVersions,
ContentType,
ProtocolVersion,
leftVersionGreaterThanOrEqualToRight,
compareVersions,
ProtocolVersion,
} from '@standardnotes/common'
import { BackupFile } from './BackupFile'
import { BackupFileType } from './BackupFileType'
import { extendArray } from '@standardnotes/utils'
import { EncryptionService } from '../Service/Encryption/EncryptionService'
import {
PayloadInterface,
CreateDecryptedItemFromPayload,
CreatePayloadSplit,
DecryptedPayload,
DecryptedPayloadInterface,
ItemsKeyContent,
EncryptedPayload,
EncryptedPayloadInterface,
isEncryptedPayload,
isDecryptedPayload,
isEncryptedTransferPayload,
EncryptedPayload,
DecryptedPayload,
isDecryptedTransferPayload,
CreateDecryptedItemFromPayload,
isEncryptedPayload,
isEncryptedTransferPayload,
ItemsKeyContent,
ItemsKeyInterface,
CreatePayloadSplit,
PayloadInterface,
} from '@standardnotes/models'
import { ClientDisplayableError } from '@standardnotes/responses'
import { extendArray } from '@standardnotes/utils'
import { isItemsKey, SNItemsKey } from '../Keys/ItemsKey/ItemsKey'
import { ContentTypeUsesRootKeyEncryption } from '../Keys/RootKey/Functions'
import { CreateAnyKeyParams } from '../Keys/RootKey/KeyParamsFunctions'
import { SNRootKeyParams } from '../Keys/RootKey/RootKeyParams'
import { SNRootKey } from '../Keys/RootKey/RootKey'
import { ContentTypeUsesRootKeyEncryption } from '../Keys/RootKey/Functions'
import { isItemsKey, SNItemsKey } from '../Keys/ItemsKey/ItemsKey'
import { SNRootKeyParams } from '../Keys/RootKey/RootKeyParams'
import { EncryptionService } from '../Service/Encryption/EncryptionService'
import { BackupFile } from './BackupFile'
import { BackupFileType } from './BackupFileType'

export async function DecryptBackupFile(
file: BackupFile,
Expand Down
6 changes: 3 additions & 3 deletions packages/encryption/src/Domain/Keys/ItemsKey/ItemsKey.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ContentType, ProtocolVersion } from '@standardnotes/common'
import {
ConflictStrategy,
ItemsKeyContent,
DecryptedItem,
DecryptedPayloadInterface,
DecryptedItemInterface,
DecryptedPayloadInterface,
HistoryEntryInterface,
ItemsKeyContent,
ItemsKeyInterface,
RootKeyInterface,
} from '@standardnotes/models'
import { ContentType, ProtocolVersion } from '@standardnotes/common'

export function isItemsKey(x: ItemsKeyInterface | RootKeyInterface): x is ItemsKeyInterface {
return x.content_type === ContentType.ItemsKey
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DecryptedItemMutator, ItemsKeyMutatorInterface, ItemsKeyContent } from '@standardnotes/models'
import { DecryptedItemMutator, ItemsKeyContent, ItemsKeyMutatorInterface } from '@standardnotes/models'

export class ItemsKeyMutator extends DecryptedItemMutator<ItemsKeyContent> implements ItemsKeyMutatorInterface {
set isDefault(isDefault: boolean) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ContentType } from '@standardnotes/common'
import { RegisterItemClass, DecryptedItemMutator, ItemsKeyContent } from '@standardnotes/models'
import { DecryptedItemMutator, ItemsKeyContent, RegisterItemClass } from '@standardnotes/models'
import { SNItemsKey } from './ItemsKey'
import { ItemsKeyMutator } from './ItemsKeyMutator'

Expand Down
4 changes: 2 additions & 2 deletions packages/encryption/src/Domain/Keys/RootKey/Functions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SNRootKey } from './RootKey'
import { ContentType, ProtocolVersion } from '@standardnotes/common'
import {
DecryptedPayload,
FillItemContentSpecialized,
Expand All @@ -7,7 +7,7 @@ import {
RootKeyContentSpecialized,
} from '@standardnotes/models'
import { UuidGenerator } from '@standardnotes/utils'
import { ContentType, ProtocolVersion } from '@standardnotes/common'
import { SNRootKey } from './RootKey'

export function CreateNewRootKey(content: RootKeyContentSpecialized): SNRootKey {
const uuid = UuidGenerator.GenerateUuid()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { KeyParamsResponse } from '@standardnotes/responses'
import {
AnyKeyParamsContent,
KeyParamsContent001,
KeyParamsContent002,
KeyParamsContent003,
KeyParamsContent004,
AnyKeyParamsContent,
} from '@standardnotes/common'
import { SNRootKeyParams } from './RootKeyParams'
import { KeyParamsResponse } from '@standardnotes/responses'
import { ProtocolVersionForKeyParams } from './ProtocolVersionForKeyParams'
import { SNRootKeyParams } from './RootKeyParams'

/**
* 001, 002:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { V001Algorithm, V002Algorithm } from '../../Algorithm'
import { KeyParamsData } from '@standardnotes/responses'
import { AnyKeyParamsContent, ProtocolVersion } from '@standardnotes/common'
import { KeyParamsData } from '@standardnotes/responses'
import { V001Algorithm, V002Algorithm } from '../../Algorithm'

export function ProtocolVersionForKeyParams(response: KeyParamsData | AnyKeyParamsContent): ProtocolVersion {
if (response.version) {
Expand Down
10 changes: 5 additions & 5 deletions packages/encryption/src/Domain/Keys/RootKey/RootKey.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { SNRootKeyParams } from './RootKeyParams'
import { ProtocolVersion } from '@standardnotes/common'
import {
RootKeyInterface,
RootKeyContent,
DecryptedItem,
DecryptedPayloadInterface,
RootKeyContentInStorage,
NamespacedRootKeyInKeychain,
RootKeyContent,
RootKeyContentInStorage,
RootKeyInterface,
} from '@standardnotes/models'
import { ProtocolVersion } from '@standardnotes/common'
import { timingSafeEqual } from '@standardnotes/sncrypto-common'
import { SNRootKeyParams } from './RootKeyParams'

/**
* A root key is a local only construct that houses the key used for the encryption
Expand Down
4 changes: 2 additions & 2 deletions packages/encryption/src/Domain/Keys/RootKey/RootKeyParams.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
AnyKeyParamsContent,
KeyParamsContent001,
KeyParamsContent002,
KeyParamsContent003,
KeyParamsContent004,
AnyKeyParamsContent,
ProtocolVersion,
KeyParamsOrigination,
ProtocolVersion,
} from '@standardnotes/common'
import { RootKeyParamsInterface } from '@standardnotes/models'
import { pickByCopy } from '@standardnotes/utils'
Expand Down
22 changes: 11 additions & 11 deletions packages/encryption/src/Domain/Operator/001/Operator001.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { ContentType, KeyParamsOrigination, ProtocolVersion, ProtocolVersionLength } from '@standardnotes/common'
import { Create001KeyParams } from '../../Keys/RootKey/KeyParamsFunctions'
import { firstHalfOfString, secondHalfOfString, splitString, UuidGenerator } from '@standardnotes/utils'
import { AsynchronousOperator } from '../Operator'
import {
CreateDecryptedItemFromPayload,
ItemsKeyContent,
ItemsKeyInterface,
FillItemContent,
ItemContent,
DecryptedPayload,
DecryptedPayloadInterface,
FillItemContent,
ItemContent,
ItemsKeyContent,
ItemsKeyInterface,
PayloadTimestampDefaults,
} from '@standardnotes/models'
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
import { firstHalfOfString, secondHalfOfString, splitString, UuidGenerator } from '@standardnotes/utils'
import { V001Algorithm } from '../../Algorithm'
import { isItemsKey } from '../../Keys/ItemsKey/ItemsKey'
import { CreateNewRootKey } from '../../Keys/RootKey/Functions'
import { Create001KeyParams } from '../../Keys/RootKey/KeyParamsFunctions'
import { SNRootKey } from '../../Keys/RootKey/RootKey'
import { SNRootKeyParams } from '../../Keys/RootKey/RootKeyParams'
import { V001Algorithm } from '../../Algorithm'
import { DecryptedParameters, EncryptedParameters, ErrorDecryptingParameters } from '../../Types/EncryptedParameters'
import { RootKeyEncryptedAuthenticatedData } from '../../Types/RootKeyEncryptedAuthenticatedData'
import { ItemAuthenticatedData } from '../../Types/ItemAuthenticatedData'
import { LegacyAttachedData } from '../../Types/LegacyAttachedData'
import { isItemsKey } from '../../Keys/ItemsKey/ItemsKey'
import { CreateNewRootKey } from '../../Keys/RootKey/Functions'
import { RootKeyEncryptedAuthenticatedData } from '../../Types/RootKeyEncryptedAuthenticatedData'
import { AsynchronousOperator } from '../Operator'

const NO_IV = '00000000000000000000000000000000'

Expand Down
20 changes: 10 additions & 10 deletions packages/encryption/src/Domain/Operator/002/Operator002.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Create002KeyParams } from '../../Keys/RootKey/KeyParamsFunctions'
import { SNProtocolOperator001 } from '../001/Operator001'
import { SNRootKey } from '../../Keys/RootKey/RootKey'
import { SNRootKeyParams } from '../../Keys/RootKey/RootKeyParams'
import { UuidGenerator } from '@standardnotes/utils'
import { V002Algorithm } from '../../Algorithm'
import * as Common from '@standardnotes/common'
import * as Models from '@standardnotes/models'
import { ItemContent, PayloadTimestampDefaults } from '@standardnotes/models'
import * as Utils from '@standardnotes/utils'
import { UuidGenerator } from '@standardnotes/utils'
import { V002Algorithm } from '../../Algorithm'
import { isItemsKey } from '../../Keys/ItemsKey/ItemsKey'
import { CreateNewRootKey } from '../../Keys/RootKey/Functions'
import { Create002KeyParams } from '../../Keys/RootKey/KeyParamsFunctions'
import { SNRootKey } from '../../Keys/RootKey/RootKey'
import { SNRootKeyParams } from '../../Keys/RootKey/RootKeyParams'
import { DecryptedParameters, EncryptedParameters, ErrorDecryptingParameters } from '../../Types/EncryptedParameters'
import { RootKeyEncryptedAuthenticatedData } from '../../Types/RootKeyEncryptedAuthenticatedData'
import { ItemAuthenticatedData } from '../../Types/ItemAuthenticatedData'
import { LegacyAttachedData } from '../../Types/LegacyAttachedData'
import { isItemsKey } from '../../Keys/ItemsKey/ItemsKey'
import { CreateNewRootKey } from '../../Keys/RootKey/Functions'
import { ItemContent, PayloadTimestampDefaults } from '@standardnotes/models'
import { RootKeyEncryptedAuthenticatedData } from '../../Types/RootKeyEncryptedAuthenticatedData'
import { SNProtocolOperator001 } from '../001/Operator001'

/**
* @deprecated
Expand Down
12 changes: 6 additions & 6 deletions packages/encryption/src/Domain/Operator/003/Operator003.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { splitString, UuidGenerator } from '@standardnotes/utils'
import { ContentType, KeyParamsOrigination, ProtocolVersion } from '@standardnotes/common'
import {
CreateDecryptedItemFromPayload,
DecryptedPayload,
FillItemContent,
ItemsKeyContent,
ItemsKeyInterface,
FillItemContent,
PayloadTimestampDefaults,
} from '@standardnotes/models'
import { SNRootKey } from '../../Keys/RootKey/RootKey'
import { splitString, UuidGenerator } from '@standardnotes/utils'
import { V003Algorithm } from '../../Algorithm'
import { CreateNewRootKey } from '../../Keys/RootKey/Functions'
import { Create003KeyParams } from '../../Keys/RootKey/KeyParamsFunctions'
import { SNProtocolOperator002 } from '../002/Operator002'
import { ContentType, KeyParamsOrigination, ProtocolVersion } from '@standardnotes/common'
import { SNRootKey } from '../../Keys/RootKey/RootKey'
import { SNRootKeyParams } from '../../Keys/RootKey/RootKeyParams'
import { CreateNewRootKey } from '../../Keys/RootKey/Functions'
import { SNProtocolOperator002 } from '../002/Operator002'

/**
* @legacy
Expand Down
16 changes: 8 additions & 8 deletions packages/encryption/src/Domain/Operator/004/Operator004.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ContentType, KeyParamsOrigination, ProtocolVersion } from '@standardnotes/common'
import { Create004KeyParams } from '../../Keys/RootKey/KeyParamsFunctions'
import { SynchronousOperator } from '../Operator'
import * as Models from '@standardnotes/models'
import {
CreateDecryptedItemFromPayload,
FillItemContent,
Expand All @@ -10,17 +9,18 @@ import {
PayloadTimestampDefaults,
} from '@standardnotes/models'
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
import { SNRootKey } from '../../Keys/RootKey/RootKey'
import { SNRootKeyParams } from '../../Keys/RootKey/RootKeyParams'
import { V004Algorithm } from '../../Algorithm'
import * as Models from '@standardnotes/models'
import * as Utils from '@standardnotes/utils'
import { V004Algorithm } from '../../Algorithm'
import { isItemsKey } from '../../Keys/ItemsKey/ItemsKey'
import { ContentTypeUsesRootKeyEncryption, CreateNewRootKey } from '../../Keys/RootKey/Functions'
import { Create004KeyParams } from '../../Keys/RootKey/KeyParamsFunctions'
import { SNRootKey } from '../../Keys/RootKey/RootKey'
import { SNRootKeyParams } from '../../Keys/RootKey/RootKeyParams'
import { DecryptedParameters, EncryptedParameters, ErrorDecryptingParameters } from '../../Types/EncryptedParameters'
import { RootKeyEncryptedAuthenticatedData } from '../../Types/RootKeyEncryptedAuthenticatedData'
import { ItemAuthenticatedData } from '../../Types/ItemAuthenticatedData'
import { LegacyAttachedData } from '../../Types/LegacyAttachedData'
import { isItemsKey } from '../../Keys/ItemsKey/ItemsKey'
import { RootKeyEncryptedAuthenticatedData } from '../../Types/RootKeyEncryptedAuthenticatedData'
import { SynchronousOperator } from '../Operator'

type V004StringComponents = [version: string, nonce: string, ciphertext: string, authenticatedData: string]

Expand Down
2 changes: 1 addition & 1 deletion packages/encryption/src/Domain/Operator/Functions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ProtocolVersion } from '@standardnotes/common'
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
import { SNProtocolOperator001 } from '../Operator/001/Operator001'
import { SNProtocolOperator002 } from '../Operator/002/Operator002'
import { SNProtocolOperator003 } from '../Operator/003/Operator003'
import { SNProtocolOperator004 } from '../Operator/004/Operator004'
import { AsynchronousOperator, SynchronousOperator } from '../Operator/Operator'
import { ProtocolVersion } from '@standardnotes/common'

export function createOperatorForVersion(
version: ProtocolVersion,
Expand Down
6 changes: 3 additions & 3 deletions packages/encryption/src/Domain/Operator/Operator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ItemsKeyInterface, RootKeyInterface } from '@standardnotes/models'
import { KeyParamsOrigination } from '@standardnotes/common'
import * as Models from '@standardnotes/models'
import { ItemsKeyInterface, RootKeyInterface } from '@standardnotes/models'
import { SNRootKey } from '../Keys/RootKey/RootKey'
import { SNRootKeyParams } from '../Keys/RootKey/RootKeyParams'
import { KeyParamsOrigination } from '@standardnotes/common'
import { DecryptedParameters, EncryptedParameters, ErrorDecryptingParameters } from '../Types/EncryptedParameters'
import { RootKeyEncryptedAuthenticatedData } from '../Types/RootKeyEncryptedAuthenticatedData'
import { ItemAuthenticatedData } from '../Types/ItemAuthenticatedData'
import { LegacyAttachedData } from '../Types/LegacyAttachedData'
import { RootKeyEncryptedAuthenticatedData } from '../Types/RootKeyEncryptedAuthenticatedData'

/**w
* An operator is responsible for performing crypto operations, such as generating keys
Expand Down
2 changes: 1 addition & 1 deletion packages/encryption/src/Domain/Operator/OperatorManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
import { ProtocolVersion, ProtocolVersionLatest } from '@standardnotes/common'
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
import { createOperatorForVersion } from './Functions'
import { AsynchronousOperator, SynchronousOperator } from './Operator'

Expand Down
4 changes: 2 additions & 2 deletions packages/encryption/src/Domain/Operator/OperatorWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { isAsyncOperator } from './Functions'
import { OperatorManager } from './OperatorManager'
import * as Models from '@standardnotes/models'
import {
DecryptedParameters,
EncryptedParameters,
encryptedParametersFromPayload,
ErrorDecryptingParameters,
} from '../Types/EncryptedParameters'
import { isAsyncOperator } from './Functions'
import { OperatorManager } from './OperatorManager'

export async function encryptPayload(
payload: Models.DecryptedPayloadInterface,
Expand Down

0 comments on commit 0cbd982

Please sign in to comment.