Skip to content

Commit

Permalink
fix: remove peculiar/webcrypto from common
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper-RF committed Nov 2, 2023
1 parent 1c2bbd0 commit f0ccff7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
1 change: 0 additions & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
},
"dependencies": {
"@quiet/types": "^1.8.1",
"@peculiar/webcrypto": "1.4.3",
"cross-env": "^5.2.0",
"debug": "^4.3.1"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/common/src/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { encodeSecret, generateSecret, verifyToken } from './auth'
import { encodeSecret, verifyToken } from './auth'

describe('Auth', () => {
it('correctly create secret, encode and decode', () => {
const secret = generateSecret()
const secret = 'secret'
const token = encodeSecret(secret)
const decodedSecret = verifyToken(secret, token)

expect(decodedSecret).toBeTruthy()
})

it('create token with wrong secret', () => {
const secret = generateSecret()
const secret = 'secret'
const token = encodeSecret('test')
const decodedSecret = verifyToken(secret, token)

Expand Down
8 changes: 0 additions & 8 deletions packages/common/src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
import { Crypto } from '@peculiar/webcrypto'

const webcrypto = new Crypto()

const array = new Uint32Array(5)

export const generateSecret = () => webcrypto.getRandomValues(array).join('')

export const encodeSecret = (secret: string) => Buffer.from(secret).toString('base64')

export const verifyToken = (secret: string, token: string): boolean => {
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop/src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Crypto } from '@peculiar/webcrypto'
import logger from './logger'
import { DATA_DIR, DEV_DATA_DIR } from '../shared/static'
import { fork, ChildProcess } from 'child_process'
import { generateSecret, getFilesData } from '@quiet/common'
import { getFilesData } from '@quiet/common'
import { updateDesktopFile, processInvitationCode } from './invitation'
import { argvInvitationCode, retrieveInvitationCode } from '@quiet/common'
const ElectronStore = require('electron-store')
Expand Down Expand Up @@ -103,7 +103,7 @@ setEngine(
})
)

const SOCKET_IO_SECRET = generateSecret()
const SOCKET_IO_SECRET = webcrypto.getRandomValues(new Uint32Array(5)).join('')

export const isBrowserWindow = (window: BrowserWindow | null): window is BrowserWindow => {
return window instanceof BrowserWindow
Expand Down

0 comments on commit f0ccff7

Please sign in to comment.