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 and islathehut committed Nov 15, 2024
1 parent fc8b3e5 commit a4a8c69
Show file tree
Hide file tree
Showing 43 changed files with 906 additions and 680 deletions.
2 changes: 1 addition & 1 deletion 3rd-party/auth
Submodule auth updated 0 files
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

* Adds basic sigchain functions ([#2649](https://github.com/TryQuiet/quiet/pull/2649))

### 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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"prepare": "husky",
"lint-staged": "lerna run lint-staged",
"build:auth": "cd ./3rd-party/auth && pnpm install && pnpm build",
"bootstrap": "npm run build:auth && lerna bootstrap"
"bootstrap": "npm run build:auth && lerna bootstrap",
"watch": "lerna watch -- lerna run build --since"
},
"engines": {
"node": "18.12.1",
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 a4a8c69

Please sign in to comment.