diff --git a/README.md b/README.md index bb4cece..a956f5a 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ The only external requirement is a PostgreSQL database. ## Documentation -- [Cryptography](./docs/cryptography) +- [Cryptography](./docs/docs/cryptography) ## Contributing diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index e7a7d59..f5252c6 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -615,9 +615,30 @@ export class Client { } public async getEnrolledDevices() { - return listDevicesResponseBody.parse( + await this.sodium.ready + if (this.#state.state !== 'loaded') { + throw new Error('Account locked: cannot list enrolled devices') + } + const devices = listDevicesResponseBody.parse( await this.#apiCall('GET', '/v1/auth/devices') ) + const deviceLabelCipher = getDeviceLabelCipher( + this.sodium, + this.#state.identity.userId, + this.#state.identity.keychainBaseKey + ) + try { + return devices.map(device => ({ + ...device, + label: device.label + ? z + .string() + .parse(decrypt(this.sodium, device.label, deviceLabelCipher)) + : undefined, + })) + } finally { + this.sodium.memzero(deviceLabelCipher.key) + } } // Key Ops -- diff --git a/packages/devtools/src/tabs/DevicesTab.tsx b/packages/devtools/src/tabs/DevicesTab.tsx index 234a118..7a38500 100644 --- a/packages/devtools/src/tabs/DevicesTab.tsx +++ b/packages/devtools/src/tabs/DevicesTab.tsx @@ -1,4 +1,12 @@ -import { Badge, BoxProps, Button, Flex, Stack, Text } from '@chakra-ui/react' +import { + Badge, + Box, + BoxProps, + Button, + Flex, + Stack, + Text, +} from '@chakra-ui/react' import { useE2ESDKClient, useE2ESDKClientIdentity, @@ -40,16 +48,27 @@ const YourDevicesSection = (props: BoxProps) => { {devices.map(device => ( - - {device.id} - - {client.currentDeviceId === device.id && ( - - Current - - )} + + + {device.label ?? 'Unnamed device'} + + + {device.id} + {client.currentDeviceId === device.id && ( + + Current + + )} + + - {device.sessions.length} session(s) + {device.sessions.length || 'no'} session + {device.sessions.length > 1 ? 's' : ''} ))}