Skip to content

Commit

Permalink
chore: fix ContentType usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Karol Sójko committed Jul 12, 2023
1 parent bd906f2 commit 9ff7b09
Show file tree
Hide file tree
Showing 247 changed files with 1,075 additions and 1,047 deletions.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"typescript": "*"
},
"dependencies": {
"@standardnotes/common": "^1.48.3",
"@standardnotes/domain-core": "^1.12.0",
"@standardnotes/common": "^1.50.0",
"@standardnotes/domain-core": "^1.22.0",
"@standardnotes/models": "workspace:*",
"@standardnotes/responses": "workspace:*",
"@standardnotes/security": "^1.7.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@electron/remote": "^2.0.9",
"@standardnotes/domain-core": "^1.18.0",
"@standardnotes/domain-core": "^1.22.0",
"@standardnotes/electron-clear-data": "1.1.1",
"@standardnotes/web": "workspace:*",
"axios": "^1.1.3",
Expand Down
3 changes: 2 additions & 1 deletion packages/encryption/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"typescript": "*"
},
"dependencies": {
"@standardnotes/common": "^1.48.3",
"@standardnotes/common": "^1.50.0",
"@standardnotes/domain-core": "^1.22.0",
"@standardnotes/models": "workspace:*",
"@standardnotes/responses": "workspace:*",
"@standardnotes/sncrypto-common": "workspace:*",
Expand Down
5 changes: 3 additions & 2 deletions packages/encryption/src/Domain/Keys/ItemsKey/ItemsKey.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ContentType, ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import {
ConflictStrategy,
DecryptedItem,
Expand All @@ -10,7 +11,7 @@ import {
} from '@standardnotes/models'

export function isItemsKey(x: unknown): x is ItemsKeyInterface {
return (x as ItemsKeyInterface).content_type === ContentType.ItemsKey
return (x as ItemsKeyInterface).content_type === ContentType.TYPES.ItemsKey
}

/**
Expand Down
8 changes: 6 additions & 2 deletions packages/encryption/src/Domain/Keys/ItemsKey/Registration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ContentType } from '@standardnotes/common'
import { DecryptedItemMutator, ItemsKeyContent, RegisterItemClass } from '@standardnotes/models'
import { ContentType } from '@standardnotes/domain-core'
import { SNItemsKey } from './ItemsKey'
import { ItemsKeyMutator } from './ItemsKeyMutator'

RegisterItemClass(ContentType.ItemsKey, SNItemsKey, ItemsKeyMutator as unknown as DecryptedItemMutator<ItemsKeyContent>)
RegisterItemClass(
ContentType.TYPES.ItemsKey,
SNItemsKey,
ItemsKeyMutator as unknown as DecryptedItemMutator<ItemsKeyContent>,
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ContentType, ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import {
ConflictStrategy,
DecryptedItem,
Expand All @@ -10,7 +11,7 @@ import {
} from '@standardnotes/models'

export function isKeySystemItemsKey(x: unknown): x is KeySystemItemsKeyInterface {
return (x as KeySystemItemsKeyInterface).content_type === ContentType.KeySystemItemsKey
return (x as KeySystemItemsKeyInterface).content_type === ContentType.TYPES.KeySystemItemsKey
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ContentType } from '@standardnotes/common'
import { DecryptedItemMutator, KeySystemItemsKeyContent, RegisterItemClass } from '@standardnotes/models'
import { ContentType } from '@standardnotes/domain-core'

import { KeySystemItemsKey } from './KeySystemItemsKey'
import { KeySystemItemsKeyMutator } from './KeySystemItemsKeyMutator'

RegisterItemClass(
ContentType.KeySystemItemsKey,
ContentType.TYPES.KeySystemItemsKey,
KeySystemItemsKey,
KeySystemItemsKeyMutator as unknown as DecryptedItemMutator<KeySystemItemsKeyContent>,
)
5 changes: 3 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 { ContentType, ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '@standardnotes/common'
import {
DecryptedPayload,
FillItemContentSpecialized,
Expand All @@ -9,13 +9,14 @@ import {
} from '@standardnotes/models'
import { UuidGenerator } from '@standardnotes/utils'
import { SNRootKey } from './RootKey'
import { ContentType } from '@standardnotes/domain-core'

export function CreateNewRootKey<K extends RootKeyInterface>(content: RootKeyContentSpecialized): K {
const uuid = UuidGenerator.GenerateUuid()

const payload = new DecryptedPayload<RootKeyContent>({
uuid: uuid,
content_type: ContentType.RootKey,
content_type: ContentType.TYPES.RootKey,
content: FillRootKeyContent(content),
...PayloadTimestampDefaults(),
})
Expand Down
5 changes: 3 additions & 2 deletions packages/encryption/src/Domain/Operator/001/Operator001.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContentType, KeyParamsOrigination, ProtocolVersion, ProtocolVersionLength } from '@standardnotes/common'
import { KeyParamsOrigination, ProtocolVersion, ProtocolVersionLength } from '@standardnotes/common'
import {
CreateDecryptedItemFromPayload,
DecryptedPayload,
Expand Down Expand Up @@ -32,6 +32,7 @@ import { PublicKeySet } from '../Types/PublicKeySet'
import { AsymmetricDecryptResult } from '../Types/AsymmetricDecryptResult'
import { AsymmetricSignatureVerificationDetachedResult } from '../Types/AsymmetricSignatureVerificationDetachedResult'
import { AsyncOperatorInterface } from '../OperatorInterface/AsyncOperatorInterface'
import { ContentType } from '@standardnotes/domain-core'

const NO_IV = '00000000000000000000000000000000'

Expand Down Expand Up @@ -71,7 +72,7 @@ export class SNProtocolOperator001 implements OperatorInterface, AsyncOperatorIn
public createItemsKey(): ItemsKeyInterface {
const payload = new DecryptedPayload({
uuid: UuidGenerator.GenerateUuid(),
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
content: this.generateNewItemsKeyContent(),
...PayloadTimestampDefaults(),
})
Expand Down
3 changes: 2 additions & 1 deletion packages/encryption/src/Domain/Operator/002/Operator002.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Common from '@standardnotes/common'
import * as Models from '@standardnotes/models'
import { ContentType } from '@standardnotes/domain-core'
import { ItemContent, PayloadTimestampDefaults } from '@standardnotes/models'
import * as Utils from '@standardnotes/utils'
import { UuidGenerator } from '@standardnotes/utils'
Expand Down Expand Up @@ -44,7 +45,7 @@ export class SNProtocolOperator002 extends SNProtocolOperator001 {
public override createItemsKey(): Models.ItemsKeyInterface {
const payload = new Models.DecryptedPayload({
uuid: UuidGenerator.GenerateUuid(),
content_type: Common.ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
content: this.generateNewItemsKeyContent(),
...PayloadTimestampDefaults(),
})
Expand Down
5 changes: 3 additions & 2 deletions packages/encryption/src/Domain/Operator/003/Operator003.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContentType, KeyParamsOrigination, ProtocolVersion } from '@standardnotes/common'
import { KeyParamsOrigination, ProtocolVersion } from '@standardnotes/common'
import {
CreateDecryptedItemFromPayload,
DecryptedPayload,
Expand All @@ -14,6 +14,7 @@ import { CreateNewRootKey } from '../../Keys/RootKey/Functions'
import { Create003KeyParams } from '../../Keys/RootKey/KeyParamsFunctions'
import { SNRootKeyParams } from '../../Keys/RootKey/RootKeyParams'
import { SNProtocolOperator002 } from '../002/Operator002'
import { ContentType } from '@standardnotes/domain-core'

/**
* @legacy
Expand Down Expand Up @@ -46,7 +47,7 @@ export class SNProtocolOperator003 extends SNProtocolOperator002 {
const content = this.generateNewItemsKeyContent()
const payload = new DecryptedPayload({
uuid: UuidGenerator.GenerateUuid(),
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
content: FillItemContent(content),
...PayloadTimestampDefaults(),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ describe('operator 004', () => {
it('should generateEncryptedParameters', () => {
const payload = {
uuid: '123',
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
content: { foo: 'bar' } as unknown as jest.Mocked<ItemContent>,
...PayloadTimestampDefaults(),
} as jest.Mocked<DecryptedPayload>

const key = new SNItemsKey(
new DecryptedPayload<ItemsKeyContent>({
uuid: 'key-456',
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
content: {
itemsKey: 'secret',
version: ProtocolVersion.V004,
Expand All @@ -56,7 +56,7 @@ describe('operator 004', () => {
key_system_identifier: undefined,
shared_vault_uuid: undefined,
content: '004:random-string:<e>{"foo"|"bar"}<e>:base64-{"u"|"123","v"|"004"}:base64-{}',
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
enc_item_key: '004:random-string:<e>random-string<e>:base64-{"u"|"123","v"|"004"}:base64-{}',
version: '004',
})
Expand Down
5 changes: 3 additions & 2 deletions packages/encryption/src/Domain/Operator/004/Operator004.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
RootKeyInterface,
KeySystemRootKeyParamsInterface,
} from '@standardnotes/models'
import { ContentType, KeyParamsOrigination, ProtocolVersion } from '@standardnotes/common'
import { KeyParamsOrigination, ProtocolVersion } from '@standardnotes/common'
import { HexString, PkcKeyPair, PureCryptoInterface, Utf8String } from '@standardnotes/sncrypto-common'
import { V004Algorithm } from '../../Algorithm'
import { SNRootKeyParams } from '../../Keys/RootKey/RootKeyParams'
Expand Down Expand Up @@ -48,6 +48,7 @@ import { AsymmetricSignatureVerificationDetachedResult } from '../Types/Asymmetr
import { AsymmetricSignatureVerificationDetachedUseCase } from './UseCase/Asymmetric/AsymmetricSignatureVerificationDetached'
import { DeriveKeySystemRootKeyUseCase } from './UseCase/KeySystem/DeriveKeySystemRootKey'
import { SyncOperatorInterface } from '../OperatorInterface/SyncOperatorInterface'
import { ContentType } from '@standardnotes/domain-core'

export class SNProtocolOperator004 implements OperatorInterface, SyncOperatorInterface {
constructor(protected readonly crypto: PureCryptoInterface) {}
Expand Down Expand Up @@ -76,7 +77,7 @@ export class SNProtocolOperator004 implements OperatorInterface, SyncOperatorInt
public createItemsKey(): ItemsKeyInterface {
const payload = new DecryptedPayload({
uuid: UuidGenerator.GenerateUuid(),
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
content: this.generateNewItemsKeyContent(),
key_system_identifier: undefined,
shared_vault_uuid: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
} from '@standardnotes/models'
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
import { V004Algorithm } from '../../../../Algorithm'
import { ContentType, ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'

export class CreateKeySystemItemsKeyUseCase {
constructor(private readonly crypto: PureCryptoInterface) {}
Expand All @@ -31,7 +32,7 @@ export class CreateKeySystemItemsKeyUseCase {

const transferPayload: DecryptedTransferPayload = {
uuid: dto.uuid,
content_type: ContentType.KeySystemItemsKey,
content_type: ContentType.TYPES.KeySystemItemsKey,
key_system_identifier: dto.keySystemIdentifier,
shared_vault_uuid: dto.sharedVaultUuid,
content: content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
PayloadTimestampDefaults,
KeySystemRootKeyParamsInterface,
} from '@standardnotes/models'
import { ContentType, ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'

export class DeriveKeySystemRootKeyUseCase {
constructor(private readonly crypto: PureCryptoInterface) {}
Expand Down Expand Up @@ -44,7 +45,7 @@ export class DeriveKeySystemRootKeyUseCase {

const payload = new DecryptedPayload<KeySystemRootKeyContent>({
uuid: uuid,
content_type: ContentType.KeySystemRootKey,
content_type: ContentType.TYPES.KeySystemRootKey,
content: FillItemContentSpecialized(content),
...PayloadTimestampDefaults(),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('generate authenticated data use case', () => {
it('should include key params if payload being encrypted is an items key', () => {
const payload = {
uuid: '123',
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
} as jest.Mocked<DecryptedPayloadInterface>

const keyParams = CreateAnyKeyParams({
Expand All @@ -42,7 +42,7 @@ describe('generate authenticated data use case', () => {
it('should include root key params if payload is a key system items key', () => {
const payload = {
uuid: '123',
content_type: ContentType.KeySystemItemsKey,
content_type: ContentType.TYPES.KeySystemItemsKey,
shared_vault_uuid: 'shared-vault-uuid-123',
key_system_identifier: 'key-system-identifier-123',
} as jest.Mocked<DecryptedPayloadInterface>
Expand All @@ -52,7 +52,7 @@ describe('generate authenticated data use case', () => {
keyParams: {
seed: 'seed-123',
},
content_type: ContentType.KeySystemRootKey,
content_type: ContentType.TYPES.KeySystemRootKey,
token: '123',
} as jest.Mocked<KeySystemRootKeyInterface>

Expand All @@ -70,15 +70,15 @@ describe('generate authenticated data use case', () => {
it('should include key system identifier and shared vault uuid', () => {
const payload = {
uuid: '123',
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
shared_vault_uuid: 'shared-vault-uuid-123',
key_system_identifier: 'key-system-identifier-123',
} as jest.Mocked<DecryptedPayloadInterface>

const itemsKey = {
creationTimestamp: 123,
keyVersion: ProtocolVersion.V004,
content_type: ContentType.KeySystemItemsKey,
content_type: ContentType.TYPES.KeySystemItemsKey,
} as jest.Mocked<KeySystemItemsKey>

const authenticatedData = usecase.execute(payload, itemsKey)
Expand All @@ -94,11 +94,11 @@ describe('generate authenticated data use case', () => {
it('should include only uuid and version if non-keysystem item with items key', () => {
const payload = {
uuid: '123',
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
} as jest.Mocked<DecryptedPayloadInterface>

const itemsKey = {
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
} as jest.Mocked<ItemsKeyInterface>

const authenticatedData = usecase.execute(payload, itemsKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('generate decrypted parameters usecase', () => {
itemsKey = {
uuid: 'items-key-id',
itemsKey: 'items-key',
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
} as jest.Mocked<ItemsKeyInterface>
})

Expand All @@ -28,7 +28,7 @@ describe('generate decrypted parameters usecase', () => {
content: {
text: plaintext,
},
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
} as unknown as jest.Mocked<DecryptedPayloadInterface>

const encryptedParametersUsecase = new GenerateEncryptedParametersUseCase(crypto)
Expand Down

0 comments on commit 9ff7b09

Please sign in to comment.