Skip to content

Commit

Permalink
generate random device name instead of using mac
Browse files Browse the repository at this point in the history
  • Loading branch information
adrastaea committed Dec 3, 2024
1 parent 243cd9b commit bfd297b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 26 deletions.
73 changes: 55 additions & 18 deletions packages/backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"@nestjs/common": "^10.2.10",
"@nestjs/core": "^10.2.10",
"@nestjs/platform-express": "^10.2.10",
"@paralleldrive/cuid2": "^2.2.2",
"@peculiar/webcrypto": "1.4.3",
"@quiet/common": "^2.0.2-alpha.1",
"@quiet/identity": "^2.0.2-alpha.2",
Expand Down Expand Up @@ -125,7 +126,6 @@
"helia": "4.0.2",
"@helia/unixfs": "3.0.1",
"@helia/block-brokers": "2.0.3",
"getmac": "^6.6.0",
"go-ipfs": "npm:[email protected]",
"http-server": "^0.12.3",
"https-proxy-agent": "^7.0.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('invites', () => {
expect(adminSigChain.roles.amIMemberOfRole(adminSigChain.context, RoleName.MEMBER)).toBe(true)
})
it('sigchain should contain admin device', () => {
const adminDeviceName = DeviceService.determineDeviceName()
const adminDeviceName = DeviceService.generateDeviceName()
adminSigChain.team.hasDevice(adminSigChain.context.device.deviceId)
})
it('should generate a new device', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Handles device-related chain operations
*/

import getMAC from 'getmac'
import { createId } from '@paralleldrive/cuid2'
import { ChainServiceBase } from '../chainServiceBase'
import { Device, DeviceWithSecrets, redactDevice } from '@localfirst/auth'
import { SigChain } from '../../sigchain'
Expand All @@ -23,7 +23,7 @@ class DeviceService extends ChainServiceBase {
public static generateDeviceForUser(userId: string): DeviceWithSecrets {
const params = {
userId,
deviceName: DeviceService.determineDeviceName(),
deviceName: DeviceService.generateDeviceName(),
}

return SigChain.lfa.createDevice(params)
Expand All @@ -32,11 +32,11 @@ class DeviceService extends ChainServiceBase {
/**
* Get an identifier for the current device
*
* @returns Formatted MAC address of the current device
* @returns collision-resistant device identifier
*/
public static determineDeviceName(): string {
const mac = getMAC()
return mac.replace(/:/g, '')
public static generateDeviceName(): string {
// TODO: let users set their own device name in a GUI
return createId()
}

public static redactDevice(device: DeviceWithSecrets): Device {
Expand Down

0 comments on commit bfd297b

Please sign in to comment.