tests: vault tests [no ci]
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { SendOwnContactChangeMessage } from './UseCase/SendOwnContactChangeMessage'
|
||||
import { DeleteContact } from './UseCase/DeleteContact'
|
||||
import { MutatorClientInterface } from './../Mutator/MutatorClientInterface'
|
||||
import { UserKeyPairChangedEventData } from './../Session/UserKeyPairChangedEventData'
|
||||
@@ -42,6 +43,7 @@ export class ContactService
|
||||
private _createOrEditContact: CreateOrEditContact,
|
||||
private _editContact: EditContact,
|
||||
private _validateItemSigner: ValidateItemSigner,
|
||||
private _sendOwnContactChangedMessage: SendOwnContactChangeMessage,
|
||||
eventBus: InternalEventBusInterface,
|
||||
) {
|
||||
super(eventBus)
|
||||
@@ -52,11 +54,36 @@ export class ContactService
|
||||
async handleEvent(event: InternalEventInterface): Promise<void> {
|
||||
if (event.type === SessionEvent.UserKeyPairChanged) {
|
||||
const data = event.payload as UserKeyPairChangedEventData
|
||||
|
||||
await this.selfContactManager.updateWithNewPublicKeySet({
|
||||
encryption: data.current.encryption.publicKey,
|
||||
signing: data.current.signing.publicKey,
|
||||
})
|
||||
void this.sendOwnContactChangeEventToAllContacts(event.payload as UserKeyPairChangedEventData)
|
||||
}
|
||||
}
|
||||
|
||||
private async sendOwnContactChangeEventToAllContacts(data: UserKeyPairChangedEventData): Promise<void> {
|
||||
if (!data.previous) {
|
||||
return
|
||||
}
|
||||
|
||||
const contacts = this._getAllContacts.execute()
|
||||
if (contacts.isFailed()) {
|
||||
return
|
||||
}
|
||||
|
||||
for (const contact of contacts.getValue()) {
|
||||
if (contact.isMe) {
|
||||
continue
|
||||
}
|
||||
|
||||
await this._sendOwnContactChangedMessage.execute({
|
||||
senderOldKeyPair: data.previous.encryption,
|
||||
senderOldSigningKeyPair: data.previous.signing,
|
||||
senderNewKeyPair: data.current.encryption,
|
||||
senderNewSigningKeyPair: data.current.signing,
|
||||
contact,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { AsymmetricMessageServerHash } from '@standardnotes/responses'
|
||||
import {
|
||||
TrustedContactInterface,
|
||||
AsymmetricMessagePayloadType,
|
||||
AsymmetricMessageSenderKeypairChanged,
|
||||
} from '@standardnotes/models'
|
||||
import { PkcKeyPair } from '@standardnotes/sncrypto-common'
|
||||
import { SendMessage } from '../../AsymmetricMessage/UseCase/SendMessage'
|
||||
import { EncryptMessage } from '../../Encryption/UseCase/Asymmetric/EncryptMessage'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
|
||||
export class SendOwnContactChangeMessage implements UseCaseInterface<AsymmetricMessageServerHash> {
|
||||
constructor(private encryptMessage: EncryptMessage, private sendMessage: SendMessage) {}
|
||||
|
||||
async execute(params: {
|
||||
senderOldKeyPair: PkcKeyPair
|
||||
senderOldSigningKeyPair: PkcKeyPair
|
||||
senderNewKeyPair: PkcKeyPair
|
||||
senderNewSigningKeyPair: PkcKeyPair
|
||||
contact: TrustedContactInterface
|
||||
}): Promise<Result<AsymmetricMessageServerHash>> {
|
||||
const message: AsymmetricMessageSenderKeypairChanged = {
|
||||
type: AsymmetricMessagePayloadType.SenderKeypairChanged,
|
||||
data: {
|
||||
recipientUuid: params.contact.contactUuid,
|
||||
newEncryptionPublicKey: params.senderNewKeyPair.publicKey,
|
||||
newSigningPublicKey: params.senderNewSigningKeyPair.publicKey,
|
||||
},
|
||||
}
|
||||
|
||||
const encryptedMessage = this.encryptMessage.execute({
|
||||
message: message,
|
||||
keys: {
|
||||
encryption: params.senderOldKeyPair,
|
||||
signing: params.senderOldSigningKeyPair,
|
||||
},
|
||||
recipientPublicKey: params.contact.publicKeySet.encryption,
|
||||
})
|
||||
|
||||
if (encryptedMessage.isFailed()) {
|
||||
return Result.fail(encryptedMessage.getError())
|
||||
}
|
||||
|
||||
const sendMessageResult = await this.sendMessage.execute({
|
||||
recipientUuid: params.contact.contactUuid,
|
||||
encryptedMessage: encryptedMessage.getValue(),
|
||||
replaceabilityIdentifier: undefined,
|
||||
})
|
||||
|
||||
return sendMessageResult
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,6 @@ export class ValidateItemSigner {
|
||||
const signerPublicKey = signatureResult.publicKey
|
||||
|
||||
const trustedContact = this.findContact.execute({ signingPublicKey: signerPublicKey })
|
||||
|
||||
if (trustedContact.isFailed()) {
|
||||
return ItemSignatureValidationResult.NotTrusted
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user