Skip to content

Commit

Permalink
2602 Move Identity model to backend (#2617)
Browse files Browse the repository at this point in the history
* replace network refs in conn-man with identity

* move identity and usercsr creation to backend

* use backend identity when creating community

* fix user certs not being updated

* rm identity from initcommunitypayload

* Refactor storage service to handle CSR saving errors before init

* add identity directly

* add identity directly in createNetwork

* move identity creation after invite code parsing

* fix deep linking test

* fix loadingPanel.test.tsx

fix types in CREATE_USER_CSR chain

fix loadPanel test better

remove mocked socket test

fix community.create test

add identity type for usercsr init

* fix last desktop rtl tests

* fix registerUsername.saga.test

* skip backwards compatibility tests not on linux

* skip outdate integration tests

* fix conn-serv.spec.test

* fix dialing tests

* remove unused socket actions

* remove my personal scripts

* exclude local address from libp2p peers

* update mobile deep link snapshot

* don't resave csr when community is opened from storage

* rm extraneous logging and imports

* add identities to migration

* fix key type

* cherry pick storybook fix

* ensure csr is saved when updating username

* update changelog

* fix state-manager tests

* make missing identity when launching community from storage a warning

* fix log comment

* update package.lock

* put update in chores section

* add back in build:auth

* use the correct implementation of build:auth
  • Loading branch information
adrastaea authored Nov 1, 2024
1 parent 434dfda commit 7a27956
Show file tree
Hide file tree
Showing 42 changed files with 904 additions and 678 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [unreleased]

### Chores

* Moved some responsibilities of identity management to the backend ([#2617](https://github.com/TryQuiet/quiet/pull/2617))

### Fixes

* Fixed memory leak associated with autoUpdater ([#2606](https://github.com/TryQuiet/quiet/issues/2606))
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"e2e:linux:run": "lerna run --scope e2e-tests test --",
"prepare": "husky",
"lint-staged": "lerna run lint-staged",
"watch": "lerna watch -- lerna run build --since",
"build:auth": "cd ./3rd-party/auth && pnpm install && pnpm build"
},
"engines": {
Expand Down
22 changes: 21 additions & 1 deletion packages/backend/src/nest/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ export const getPorts = async (): Promise<Ports> => {
}
}

/**
* Generate a random onion address
* @param length Length of the onion address, provided for testing invalid lengths (default: 56)
* @returns Random onion address
**/
export function generateRandomOnionAddress(length: number = 56): string {
const charset = 'abcdefghijklmnopqrstuvwxyz' // Lowercase letters only
const charsetLength = charset.length
let randomString = ''

const randomValues = new Uint32Array(length)
crypto.getRandomValues(randomValues)

for (let i = 0; i < length; i++) {
randomString += charset[randomValues[i] % charsetLength]
}

return randomString + '.onion'
}

export class DummyIOServer extends Server {
emit(event: string, ...args: any[]): boolean {
logger.info(`Emitting ${event} with args:`, args)
Expand Down Expand Up @@ -203,7 +223,7 @@ export const rootPermsData: PermsData = {
tmp.setGracefulCleanup()

export const testBootstrapMultiaddrs = [
createLibp2pAddress('abcd.onion', 'QmfLUJcDSLVYnNqSPSRK4mKG8MGw51m9K2v59k3yq1C8s4'),
createLibp2pAddress(generateRandomOnionAddress(56), 'QmfLUJcDSLVYnNqSPSRK4mKG8MGw51m9K2v59k3yq1C8s4'),
]

export const libp2pInstanceParams = async (): Promise<Libp2pNodeParams> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,8 @@ describe('ConnectionsManagerService', () => {
}
await localDbService.setCommunity(actualCommunity)
await localDbService.setCurrentCommunityId(community.id)
// TODO: Revisit this when we move the Identity model to the backend, since
// this network data lives in that model.
const network = {
peerId: userIdentity.peerId,
hiddenService: userIdentity.hiddenService,
}
await localDbService.setNetworkInfo(network)

await localDbService.setIdentity(userIdentity)

await connectionsManagerService.closeAllServices()

Expand All @@ -119,10 +114,7 @@ describe('ConnectionsManagerService', () => {
await connectionsManagerService.init()

const localPeerAddress = createLibp2pAddress(userIdentity.hiddenService.onionAddress, userIdentity.peerId.id)
const updatedLaunchCommunityPayload = {
community: { ...actualCommunity, peerList: [localPeerAddress, remotePeer] },
network,
}
const updatedLaunchCommunityPayload = { ...actualCommunity, peerList: [localPeerAddress, remotePeer] }

expect(launchCommunitySpy).toHaveBeenCalledWith(updatedLaunchCommunityPayload)
})
Expand All @@ -137,20 +129,13 @@ describe('ConnectionsManagerService', () => {
it('community is only launched once', async () => {
await localDbService.setCommunity(community)
await localDbService.setCurrentCommunityId(community.id)
const launchCommunityPayload = {
community: community,
network: {
peerId: userIdentity.peerId,
hiddenService: userIdentity.hiddenService,
},
}

//@ts-ignore
const launchSpy = jest.spyOn(connectionsManagerService, 'launch').mockResolvedValue('address')

await Promise.all([
connectionsManagerService.launchCommunity(launchCommunityPayload),
connectionsManagerService.launchCommunity(launchCommunityPayload),
connectionsManagerService.launchCommunity(community),
connectionsManagerService.launchCommunity(community),
])

expect(launchSpy).toBeCalledTimes(1)
Expand All @@ -159,13 +144,8 @@ describe('ConnectionsManagerService', () => {
it('Bug reproduction - Error on startup - Error: TOR: Connection already established - Trigger launchCommunity from backend and state manager', async () => {
await localDbService.setCommunity(community)
await localDbService.setCurrentCommunityId(community.id)
// TODO: Revisit this when we move the Identity model to the backend, since
// this network data lives in that model.
const network = {
peerId: userIdentity.peerId,
hiddenService: userIdentity.hiddenService,
}
await localDbService.setNetworkInfo(network)

await localDbService.setIdentity(userIdentity)

const peerid = 'QmaEvCkpUG7GxhgvMkk8wxurfi1ehjHhSUNRksWTmXN2ix'
await localDbService.put(LocalDBKeys.PEERS, {
Expand Down
Loading

0 comments on commit 7a27956

Please sign in to comment.