| … | … | @@ -0,0 +1,104 @@ |
| 1 | # Keet Device Linking |
| 2 | |
| 3 | This directory contains the necessary files to simulate a second device linking to an existing Keet identity. This functionality is essential for allowing the Keet bot to operate across multiple devices. |
| 4 | |
| 5 | ## Files |
| 6 | |
| 7 | - `keet_cmd.js`: The main Keet command-line agent script |
| 8 | - `link_device.js`: A script to link a new device to an existing Keet identity |
| 9 | - `package.json`: Dependencies for the Keet bot |
| 10 | - `storage/`: Directory for storing the device's identity and other data |
| 11 | |
| 12 | ## How Device Linking Works |
| 13 | |
| 14 | The device linking process involves the following steps: |
| 15 | |
| 16 | 1. **First Device Setup**: The first device creates an identity with a unique `memberId`. |
| 17 | 2. **Second Device Linking**: The second device creates a new identity that shares the same `memberId` as the first device but has a different `deviceId`. |
| 18 | 3. **Device Confirmation**: The first device confirms the second device by setting its `confirmed` status to `true`. |
| 19 | |
| 20 | ## Identity Structure |
| 21 | |
| 22 | The identity file (`identity.json`) has the following structure: |
| 23 | |
| 24 | ```json |
| 25 | { |
| 26 | "anonymous": false, |
| 27 | "memberId": "unique-member-id", |
| 28 | "timestamp": 1234567890123, |
| 29 | "displayName": "KeetBot", |
| 30 | "avatar": null, |
| 31 | "devices": [ |
| 32 | { |
| 33 | "deviceId": "device-id-1", |
| 34 | "isMobile": false, |
| 35 | "name": "Primary Device", |
| 36 | "confirmed": true |
| 37 | }, |
| 38 | { |
| 39 | "deviceId": "device-id-2", |
| 40 | "isMobile": true, |
| 41 | "name": "Mobile Device", |
| 42 | "confirmed": true |
| 43 | } |
| 44 | ], |
| 45 | "local": { |
| 46 | "deviceId": "current-device-id" |
| 47 | } |
| 48 | } |
| 49 | ``` |
| 50 | |
| 51 | - `anonymous`: Whether the identity is anonymous (should be `false` for a real identity) |
| 52 | - `memberId`: The unique identifier for the member (shared across all devices) |
| 53 | - `timestamp`: The timestamp when the identity was created |
| 54 | - `displayName`: The display name for the identity |
| 55 | - `avatar`: The avatar for the identity (if any) |
| 56 | - `devices`: An array of devices linked to this identity |
| 57 | - `deviceId`: The unique identifier for the device |
| 58 | - `isMobile`: Whether the device is mobile |
| 59 | - `name`: The name of the device |
| 60 | - `confirmed`: Whether the device has been confirmed |
| 61 | - `local`: Information about the local device |
| 62 | - `deviceId`: The device ID of the current device |
| 63 | |
| 64 | ## Usage |
| 65 | |
| 66 | ### Linking a New Device |
| 67 | |
| 68 | To link a new device to an existing identity, run the `link_device.js` script: |
| 69 | |
| 70 | ```bash |
| 71 | node link_device.js |
| 72 | ``` |
| 73 | |
| 74 | This will: |
| 75 | 1. Read the identity from the first device |
| 76 | 2. Create a new device ID |
| 77 | 3. Create a new identity for the second device that links to the first device's identity |
| 78 | 4. Update the first device's identity to include the new device |
| 79 | |
| 80 | ### Confirming a Device |
| 81 | |
| 82 | To confirm a device, run the `keet_cmd.js` script with the `--confirm-device` option: |
| 83 | |
| 84 | ```bash |
| 85 | node keet_cmd.js --confirm-device=device-id --storage=path-to-storage |
| 86 | ``` |
| 87 | |
| 88 | Alternatively, you can manually update the identity files to set the `confirmed` status to `true` for the device. |
| 89 | |
| 90 | ## Implementation Details |
| 91 | |
| 92 | The device linking functionality is implemented in the `link_device.js` script. The key steps are: |
| 93 | |
| 94 | 1. Read the first device's identity |
| 95 | 2. Generate a new device ID |
| 96 | 3. Create a new device entry |
| 97 | 4. Create a new identity for the second device that links to the first device's identity |
| 98 | 5. Update the first device's identity to include the new device |
| 99 | |
| 100 | The device confirmation functionality is implemented in the `keet_cmd.js` script. The key steps are: |
| 101 | |
| 102 | 1. Find the device in the identity's devices array |
| 103 | 2. Set the device's `confirmed` status to `true` |
| 104 | 3. Update the identity file |