diff --git a/CHANGELOG.md b/CHANGELOG.md index a0be3fa7d1..0315ca8cb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ [unreleased] +* Filter CSRs - remove old csrs and replace with new for each pubkey + * Fixed mobile bugs - joining by QR code and not showing username taken screen for user who has unique name * Use context menu for information about unregistered username instead screen diff --git a/packages/backend/src/nest/storage/storage.service.spec.ts b/packages/backend/src/nest/storage/storage.service.spec.ts index a4e0fb0ada..c9e4201e27 100644 --- a/packages/backend/src/nest/storage/storage.service.spec.ts +++ b/packages/backend/src/nest/storage/storage.service.spec.ts @@ -1,6 +1,6 @@ import { LazyModuleLoader } from '@nestjs/core' import { Test, TestingModule } from '@nestjs/testing' -import { createUserCert, keyFromCertificate, parseCertificate } from '@quiet/identity' +import { createUserCert, keyFromCertificate, loadCSR, parseCertificate } from '@quiet/identity' import { prepareStore, getFactory, @@ -579,6 +579,37 @@ describe('StorageService', () => { }, ]) }) + + it.only('getCsrs - remove old csrs and replace with new for each pubkey', async () => { + await storageService.init(peerId) + const allCsrs = [ + 'MIIDITCCAsYCAQAwSTFHMEUGA1UEAxM+anR3c3hxMnZ1dWthY3JodWhvdnAzd2JxbzRxNXc0d2s3Nm1qbWJ3cXk3eGNma2FsdmRxb3hhYWQub25pb24wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQE2q6iS+WCmIVCSFI2AjHrW6ujUdrceD5T2xkcTJBTn0y50WphcupUajCRgkXaTBkTsGNJ3qWRZAKX7CiuehBJoIICGTAuBgkqhkiG9w0BCQ4xITAfMB0GA1UdDgQWBBQuE5JgPY/BYBpgG5pnjMkEEIkrGjCCAUcGCSqGSIb3DQEJDDGCATgEggE0BDlx84glBl72q82F2a+y8iTVKM8IMiXYYrmNyhFPj6XsfVQpvLhNviZ5zHdMBWbFj44vTSUIasNP9I9eCWSEAaEJqjngEh18WCRS/XbvQxI/8qB5pzcfghvM8BCgSLbSEjK2GMYVhCXmRH1YGHIZu0+Ii9pe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UEsXOV1G0kOcv2uthpaV7NSlWd4jtRDHidLrd/X/iJWHMsmi4KyLM/p7dCGEqk24aobLfJA9cYN540Q0Sp93tJAXw3Y3Gh5CUwItNolhMk/rVpS3niKIpxjMk2OtLrV0epBKhMVV7jDqKsxZX9I0gDMNTRdixIEXbKHacVY4dSP9iNY+9T26yxGKBM6ah0KHxTY5rODLV29+ll/+wftIGsixYNJoo5HUEmZnWRSPVKri50scOJAI4C6l9HJfNgEBoNFEwFgYKKwYBBAGDjBsCATEIEwZrYWNwZXIwPQYJKwYBAgEPAwEBMTATLlFtY01LdlpWNWJZcEZ4eW9TRFlUcE1RY2VBdnRDa2taZnQ2TlRDVVB0VVAyTXkwRwYDVR0RMUATPnU3bmtoMjRwb210bDc1b2FhYm13eXRrdHUzYzZseGlvbmdiM2JtY2prbmVwZmVhdzJpNmR3ZGFkLm9uaW9uMAoGCCqGSM49BAMCA0gAMEUCIFsTfZsGWX3g44QnEksCh0naujBG60DuNNh83YHcl12FAiEAm9qALhC6ctx9JvakesWQhtDT4WFAGyEkuIB5Xtw68eg=', + ] + + const mockGetAllEventLogEntries = jest.fn() + // @ts-ignore - Property 'getAllEventLogEntries' is protected + storageService.getAllEventLogEntries = mockGetAllEventLogEntries + mockGetAllEventLogEntries.mockReturnValue(allCsrs) + + const filteredCsrs = await storageService.getCsrs() + + expect(filteredCsrs.length).toEqual(allCsrs.length - 1) + + expect(filteredCsrs).toEqual([ + 'MIIDITCCAsYCAQAwSTFHMEUGA1UEAxM+anR3c3hxMnZ1dWthY3JodWhvdnAzd2JxbzRxNXc0d2s3Nm1qbWJ3cXk3eGNma2FsdmRxb3hhYWQub25pb24wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQE2q6iS+WCmIVCSFI2AjHrW6ujUdrceD5T2xkcTJBTn0y50WphcupUajCRgkXaTBkTsGNJ3qWRZAKX7CiuehBJoIICGTAuBgkqhkiG9w0BCQ4xITAfMB0GA1UdDgQWBBQuE5JgPY/BYBpgG5p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sImfE+Nd0R1jCCAUcGCSqGSIb3DQEJDDGCATgEggE0EEQQfvnnjicwQYHZLzsPiRaoQtS8rP4q4cqjLBA6zJcibd88zpWKFH5oNkUaVaZi64iiX0bCCEmJFX+nQWJdtuhMd4/ut+6vW5cj/DWMAak5q3fi7gQ2lSsDfd702Ter0uNJToSbm7X1NlYm/WXCtLeUEsXOV1G0kOcv2uthpaV7NSlWd4jtRDHidLrd/X/iJWHMsmi4KyLM/p7dCGEqk24aobLfJA9cYN540Q0Sp93tJAXw3Y3Gh5CUwItNolhMk/rVpS3niKIpxjMk2OtLrV0epBKhMVV7jDqKsxZX9I0gDMNTRdixIEXbKHacVY4dSP9iNY+9T26yxGKBM6ah0KHxTY5rODLV29+ll/+wftIGsixYNJoo5HUEmZnWRSPVKri50scOJAI4C6l9HJfNgEBoNFEwFgYKKwYBBAGDjBsCATEIEwZrYWNwZXIwPQYJKwYBAgEPAwEBMTATLlFtY01LdlpWNWJZcEZ4eW9TRFlUcE1RY2VBdnRDa2taZnQ2TlRDVVB0VVAyTXkwRwYDVR0RMUATPnU3bmtoMjRwb210bDc1b2FhYm13eXRrdHUzYzZseGlvbmdiM2JtY2prbmVwZmVhdzJpNmR3ZGFkLm9uaW9uMAoGCCqGSM49BAMCA0gAMEUCIFsTfZsGWX3g44QnEksCh0naujBG60DuNNh83YHcl12FAiEAm9qALhC6ctx9JvakesWQhtDT4WFAGyEkuIB5Xtw68eg=', + ]) + }) }) describe('Files deletion', () => { diff --git a/packages/backend/src/nest/storage/storage.service.ts b/packages/backend/src/nest/storage/storage.service.ts index 62f1d6ba88..51c71e68d6 100644 --- a/packages/backend/src/nest/storage/storage.service.ts +++ b/packages/backend/src/nest/storage/storage.service.ts @@ -9,6 +9,7 @@ import { verifyUserCert, parseCertificationRequest, getReqFieldValue, + loadCSR, } from '@quiet/identity' import type { IPFS } from 'ipfs-core' import OrbitDB from 'orbit-db' @@ -399,9 +400,11 @@ export class StorageService extends EventEmitter { }) this.certificatesRequests.events.on('replicated', async () => { this.logger('REPLICATED: CSRs') - const allCsrs = this.getAllEventLogEntries(this.certificatesRequests) + + const filteredCsrs = await this.getCsrs() + const allCertificates = this.getAllEventLogEntries(this.certificates) - this.emit(StorageEvents.REPLICATED_CSR, { csrs: allCsrs, certificates: allCertificates }) + this.emit(StorageEvents.REPLICATED_CSR, { csrs: filteredCsrs, certificates: allCertificates }) await this.updatePeersList() }) this.certificatesRequests.events.on('write', async (_address, entry) => { @@ -419,6 +422,28 @@ export class StorageService extends EventEmitter { this.logger('STORAGE: Finished creating certificatesRequests db') } + public async getCsrs(): Promise { + // @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options' + await this.certificatesRequests.load({ fetchEntryTimeout: 15000 }) + const allCsrs = this.getAllEventLogEntries(this.certificatesRequests) + const filteredCsrsMap: Map = new Map() + + await Promise.all( + allCsrs.map(async csr => { + const parsedCsr = await loadCSR(csr) + const pubKey = keyFromCertificate(parsedCsr) + + if (filteredCsrsMap.has(pubKey)) { + filteredCsrsMap.delete(pubKey) + } + + filteredCsrsMap.set(pubKey, csr) + }) + ) + + return [...filteredCsrsMap.values()] + } + public async loadAllChannels() { this.logger('Getting all channels') // @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options' diff --git a/packages/mobile/src/components/ConfirmationBox/ConfirmationBox.component.tsx b/packages/mobile/src/components/ConfirmationBox/ConfirmationBox.component.tsx index a36cb02dd9..109710333b 100644 --- a/packages/mobile/src/components/ConfirmationBox/ConfirmationBox.component.tsx +++ b/packages/mobile/src/components/ConfirmationBox/ConfirmationBox.component.tsx @@ -1,7 +1,6 @@ import React, { CSSProperties, FC, useEffect, useRef, useState } from 'react' import { Animated, View, Image, Platform, StyleProp, ViewStyle } from 'react-native' import { ConfirmationBoxProps } from './ConfirmationBox.types' - import { Typography } from '../Typography/Typography.component' import { defaultPalette } from '../../styles/palettes/default.palette' diff --git a/packages/mobile/src/components/JoinCommunity/JoinCommunity.stories.tsx b/packages/mobile/src/components/JoinCommunity/JoinCommunity.stories.tsx index 721031ab4f..b9343b8437 100644 --- a/packages/mobile/src/components/JoinCommunity/JoinCommunity.stories.tsx +++ b/packages/mobile/src/components/JoinCommunity/JoinCommunity.stories.tsx @@ -1,7 +1,6 @@ import { storiesOf } from '@storybook/react-native' import React from 'react' import { storybookLog } from '../../utils/functions/storybookLog/storybookLog.function' - import { JoinCommunity } from './JoinCommunity.component' storiesOf('JoinCommunity', module).add('Default', () => (