Skip to content

Commit

Permalink
Share the same constants and enums with identity
Browse files Browse the repository at this point in the history
  • Loading branch information
islathehut committed Nov 25, 2024
1 parent c91145e commit 23b0a50
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
CertFieldsTypes,
createRootCA,
createUserCsr,
configCrypto,
getCertFieldValue,
getPubKey,
loadCertificate,
Expand Down Expand Up @@ -77,7 +78,6 @@ import { DateTime } from 'luxon'
import { createLogger } from '../common/logger'
import { createFromJSON } from '@libp2p/peer-id-factory'
import { PeerId } from '@libp2p/interface'
import { config } from '@quiet/state-manager'

@Injectable()
export class ConnectionsManagerService extends EventEmitter implements OnModuleInit {
Expand Down Expand Up @@ -446,16 +446,16 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI
}
const _pubKey = await pubKeyFromCsr(identity.userCsr.userCsr)
const publicKey = await getPubKey(_pubKey)
const privateKey = await loadPrivateKey(identity.userCsr.userKey, config.signAlg)
const privateKey = await loadPrivateKey(identity.userCsr.userKey, configCrypto.signAlg)

const existingKeyPair: CryptoKeyPair = { privateKey, publicKey }

createUserCsrPayload = {
nickname,
commonName: identity.hiddenService.onionAddress,
peerId: identity.peerId.id,
signAlg: config.signAlg,
hashAlg: config.hashAlg,
signAlg: configCrypto.signAlg,
hashAlg: configCrypto.hashAlg,
existingKeyPair,
}
} else {
Expand All @@ -464,8 +464,8 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI
nickname,
commonName: identity.hiddenService.onionAddress,
peerId: identity.peerId.id,
signAlg: config.signAlg,
hashAlg: config.hashAlg,
signAlg: configCrypto.signAlg,
hashAlg: configCrypto.hashAlg,
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/nest/libp2p/libp2p.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export class Libp2pService extends EventEmitter {

this.logger.info(`Creating or opening existing level datastore for libp2p`)
this.libp2pDatastore = new Libp2pDatastore({
inMemory: true,
inMemory: false,
datastorePath: this.datastorePath,
})

Expand Down
2 changes: 1 addition & 1 deletion packages/mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1398,4 +1398,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: eed49772dde039b0723324c813c83dd4c1af35f7

COCOAPODS: 1.13.0
COCOAPODS: 1.15.2
2 changes: 0 additions & 2 deletions packages/state-manager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ export * from './sagas/communities/communities.types'

export * from './sagas/users/users.types'

export * from './sagas/users/const/certFieldTypes'

export * from './sagas/publicChannels/publicChannels.types'

export * from './sagas/messages/messages.types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { combineReducers } from '@reduxjs/toolkit'
import { expectSaga } from 'redux-saga-test-plan'
import * as matchers from 'redux-saga-test-plan/matchers'
import { setupCrypto, createUserCsr, type UserCsr, getPubKey, loadPrivateKey, pubKeyFromCsr } from '@quiet/identity'
import { setupCrypto, type UserCsr } from '@quiet/identity'
import { prepareStore } from '../../../utils/tests/prepareStore'
import { getFactory } from '../../../utils/tests/factories'
import { reducers } from '../../reducers'
import { identityActions } from '../identity.slice'
import { registerUsernameSaga } from './registerUsername.saga'
import { communitiesActions } from '../../communities/communities.slice'
import { config } from '../../users/const/certFieldTypes'
import { CertData, CreateUserCsrPayload, InitUserCsrPayload, SocketActionTypes } from '@quiet/types'
import { CertData, InitUserCsrPayload, SocketActionTypes } from '@quiet/types'
import { Socket } from '../../../types'
import { communitiesSelectors } from '../../communities/communities.selectors'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { type PayloadAction } from '@reduxjs/toolkit'
import { sign, loadPrivateKey, pubKeyFromCsr } from '@quiet/identity'
import { call, select, apply, put, delay, take } from 'typed-redux-saga'
import { arrayBufferToString } from 'pvutils'
import { config } from '../../users/const/certFieldTypes'
import { identitySelectors } from '../../identity/identity.selectors'
import { publicChannelsActions } from '../../publicChannels/publicChannels.slice'
import { publicChannelsSelectors } from '../../publicChannels/publicChannels.selectors'
import { messagesActions } from '../messages.slice'
import { generateMessageId, getCurrentTime } from '../utils/message.utils'
import { type ChannelMessage, MessageType, SendingStatus, SocketActionTypes } from '@quiet/types'
import { createLogger } from '../../../utils/logger'
import { configCrypto } from '@quiet/identity'

const logger = createLogger('sendMessageSaga')

Expand All @@ -37,7 +37,7 @@ export function* sendMessageSaga(
logger.info(`Sending message ${id} to channel ${channelId}`)

const pubKey = yield* call(pubKeyFromCsr, identity.userCsr.userCsr)
const keyObject = yield* call(loadPrivateKey, identity.userCsr.userKey, config.signAlg)
const keyObject = yield* call(loadPrivateKey, identity.userCsr.userKey, configCrypto.signAlg)
const signatureArrayBuffer = yield* call(sign, action.payload.message, keyObject)
const signature = yield* call(arrayBufferToString, signatureArrayBuffer)
const createdAt = yield* call(getCurrentTime)
Expand Down
11 changes: 0 additions & 11 deletions packages/state-manager/src/sagas/users/const/certFieldTypes.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import * as Block from 'multiformats/block'
import * as dagCbor from '@ipld/dag-cbor'
import { sha256 } from 'multiformats/hashes/sha2'

import { sign, loadPrivateKey, pubKeyFromCsr } from '@quiet/identity'
import { sign, loadPrivateKey, pubKeyFromCsr, configCrypto } from '@quiet/identity'
import { UserProfile, UserProfileData, SocketActionTypes } from '@quiet/types'
import { fileToBase64String } from '@quiet/common'

import { config } from '../../users/const/certFieldTypes'
import { identitySelectors } from '../../identity/identity.selectors'
import { usersActions } from '../users.slice'
import { type Socket, applyEmitParams } from '../../../types'
import { createLogger } from '../../../utils/logger'

Expand All @@ -36,7 +34,7 @@ export function* saveUserProfileSaga(socket: Socket, action: PayloadAction<{ pho
const codec = dagCbor
const hasher = sha256
const { bytes } = yield* call(Block.encode, { value: profile, codec: codec, hasher: hasher })
const keyObject = yield* call(loadPrivateKey, identity.userCsr.userKey, config.signAlg)
const keyObject = yield* call(loadPrivateKey, identity.userCsr.userKey, configCrypto.signAlg)
const signatureArrayBuffer = yield* call(sign, bytes, keyObject)
const signature = yield* call(arrayBufferToString, signatureArrayBuffer)
const pubKey = yield* call(pubKeyFromCsr, identity.userCsr.userCsr)
Expand Down
9 changes: 7 additions & 2 deletions packages/state-manager/src/sagas/users/users.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { createSelector } from '@reduxjs/toolkit'
import { getCertFieldValue, getReqFieldValue, keyFromCertificate, loadCertificate } from '@quiet/identity'
import { CertFieldsTypes } from './const/certFieldTypes'
import {
getCertFieldValue,
getReqFieldValue,
keyFromCertificate,
loadCertificate,
CertFieldsTypes,
} from '@quiet/identity'
import { StoreKeys } from '../store.keys'
import { certificatesAdapter } from './users.adapter'
import { type Certificate } from 'pkijs'
Expand Down
5 changes: 2 additions & 3 deletions packages/state-manager/src/utils/tests/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { keyFromCertificate, loadPrivateKey, parseCertificate, sign } from '@quiet/identity'
import { configCrypto, keyFromCertificate, loadPrivateKey, parseCertificate, sign } from '@quiet/identity'
// import fs from 'fs'
// import os from 'os'
import { arrayBufferToString } from 'pvutils'
import { config } from '../../sagas/users/const/certFieldTypes'
import { type PeerId } from '@quiet/types'
import { createLogger } from '../../utils/logger'

Expand All @@ -25,7 +24,7 @@ export const createMessageSignatureTestHelper = async (
userKey: string
): Promise<{ signature: string; pubKey: string }> => {
const pubKey = keyFromCertificate(parseCertificate(certificate))
const keyObject = await loadPrivateKey(userKey, config.signAlg)
const keyObject = await loadPrivateKey(userKey, configCrypto.signAlg)
const signatureArrayBuffer = await sign(message, keyObject)
const signature = arrayBufferToString(signatureArrayBuffer)
return {
Expand Down

0 comments on commit 23b0a50

Please sign in to comment.