Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
* text=auto eol=lf
30 changes: 26 additions & 4 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1064,28 +1064,50 @@ This method only works for E2EE (end-to-end encrypted) messages. For regular mes
<a name="getDeviceData"></a>
## client.getDeviceData()

Get E2EE device data for storage.
Get the current E2EE device data as JSON string.

This returns the current in-memory E2EE device state, which includes:
- Noise key pair (for encrypted communication)
- Identity key pair (for identity verification)
- Signed pre-key (for session establishment)
- Registration ID
- All sessions and identities established with other users

__Returns__

string - Device data as JSON string

__Note__
__Works with all device store modes__

| Mode | Description |
|------|-------------|
| `e2eeMemoryOnly: true` | Get the ephemeral device data before it's lost on disconnect |
| `deviceData: "..."` | Get the updated state after sessions/keys change |
| `devicePath: "..."` | Get current state (also auto-saved to file) |
Comment on lines +1084 to +1086
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation references a non-existent option e2eeMemoryOnly: true. Based on the ClientOptions interface in src/types.ts (lines 388-401), the available device store options are only devicePath and deviceData. Memory-only mode is implicitly enabled when neither option is provided. Update the table to correctly describe the actual device store modes: no options specified (memory-only), deviceData specified, or devicePath specified.

Suggested change
| `e2eeMemoryOnly: true` | Get the ephemeral device data before it's lost on disconnect |
| `deviceData: "..."` | Get the updated state after sessions/keys change |
| `devicePath: "..."` | Get current state (also auto-saved to file) |
| _No device store options specified_ | Memory-only mode: get ephemeral device data before it's lost on disconnect |
| `deviceData: "..."` | In-memory + caller-managed persistence: get the updated state after sessions/keys change |
| `devicePath: "..."` | File-based persistence: get current state (also auto-saved to file) |

Copilot uses AI. Check for mistakes.

Save device data to avoid setting up E2EE again on each startup.
__Use cases__

- Save device data to database instead of file
- Backup device state periodically
- Transfer device state between instances
- Export state from memory-only mode before disconnect

__Example__

```typescript
import { writeFileSync } from 'fs'

// Save device data
// Save device data to file
const deviceData = client.getDeviceData()
writeFileSync('device.json', deviceData)

// Or save to database
await db.saveDeviceData(userId, deviceData)

// Load on startup
const client = new Client(cookies, {
deviceData: readFileSync('device.json', 'utf-8')
// or: deviceData: await db.getDeviceData(userId)
})
```

Expand Down
30 changes: 26 additions & 4 deletions DOCS_VI.md
Original file line number Diff line number Diff line change
Expand Up @@ -1064,28 +1064,50 @@ Method này chỉ hoạt động với tin nhắn E2EE (mã hóa đầu cuối).
<a name="getDeviceData"></a>
## client.getDeviceData()

Lấy E2EE device data để lưu trữ.
Lấy dữ liệu E2EE device hiện tại dưới dạng JSON string.

Method này trả về trạng thái E2EE device hiện tại trong bộ nhớ, bao gồm:
- Noise key pair (cho giao tiếp mã hóa)
- Identity key pair (cho xác minh danh tính)
- Signed pre-key (cho thiết lập session)
- Registration ID
- Tất cả sessions và identities đã thiết lập với người dùng khác

__Trả về__

string - Device data dưới dạng JSON string

__Lưu ý__
__Hoạt động với tất cả các chế độ device store__

| Chế độ | Mô tả |
|------|-------------|
| `e2eeMemoryOnly: true` | Lấy dữ liệu tạm thời trước khi mất khi ngắt kết nối |
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation references a non-existent option e2eeMemoryOnly: true. Based on the ClientOptions interface in src/types.ts (lines 388-401), the available device store options are only devicePath and deviceData. Memory-only mode is implicitly enabled when neither option is provided. Update the table to correctly describe the actual device store modes: no options specified (memory-only), deviceData specified, or devicePath specified.

Suggested change
| `e2eeMemoryOnly: true` | Lấy dữ liệu tạm thời trước khi mất khi ngắt kết nối |
| Không cấu hình device store (không truyền `devicePath` hoặc `deviceData`) | Lấy dữ liệu tạm thời trong memory-only mode trước khi mất khi ngắt kết nối |

Copilot uses AI. Check for mistakes.
| `deviceData: "..."` | Lấy trạng thái đã cập nhật sau khi sessions/keys thay đổi |
| `devicePath: "..."` | Lấy trạng thái hiện tại (cũng tự động lưu vào file) |

Lưu device data để tránh phải setup E2EE lại mỗi lần khởi động.
__Các trường hợp sử dụng__

- Lưu device data vào database thay vì file
- Backup trạng thái device định kỳ
- Chuyển trạng thái device giữa các instance
- Xuất trạng thái từ memory-only mode trước khi ngắt kết nối

__Ví dụ__

```typescript
import { writeFileSync } from 'fs'

// Lưu device data
// Lưu device data vào file
const deviceData = client.getDeviceData()
writeFileSync('device.json', deviceData)

// Hoặc lưu vào database
await db.saveDeviceData(userId, deviceData)

// Load khi khởi động
const client = new Client(cookies, {
deviceData: readFileSync('device.json', 'utf-8')
// hoặc: deviceData: await db.getDeviceData(userId)
})
```

Expand Down
32 changes: 30 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,11 +710,39 @@ export class Client extends (EventEmitter as new () => TypedEventEmitter<ClientE
}

/**
* Get E2EE device data as JSON string
* Get the current E2EE device data as JSON string
*
* Use this to persist device data externally (e.g., in a database)
* This returns the current in-memory E2EE device state, which includes:
* - Noise key pair
* - Identity key pair
* - Signed pre-key
* - Registration ID
* - All sessions and identities
*
* Works with all device store modes:
* - `e2eeMemoryOnly: true` - Get the ephemeral device data before it's lost
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation references a non-existent option e2eeMemoryOnly: true. Based on the ClientOptions interface in src/types.ts (lines 388-401), the available device store options are only devicePath and deviceData. Memory-only mode is implicitly enabled when neither option is provided to the Client constructor. The correct documentation should reflect this: when neither devicePath nor deviceData is specified, the device data is only stored in memory and lost on disconnect.

Suggested change
* - `e2eeMemoryOnly: true` - Get the ephemeral device data before it's lost
* - In-memory mode (default when neither `devicePath` nor `deviceData` is set) - Get the ephemeral device data before it's lost

Copilot uses AI. Check for mistakes.
* - `deviceData: "..."` - Get the updated state after sessions/keys change
* - `devicePath: "..."` - Get current state (also auto-saved to file)
*
* Use cases:
* - Save device data to database instead of file
* - Backup device state periodically
* - Transfer device state between instances
*
* @returns Device data as JSON string
* @throws Error if not connected
*
* @example
* ```typescript
* // Save to database
* const deviceData = client.getDeviceData();
* await db.saveDeviceData(userId, deviceData);
*
* // Load on next startup
* const client = new Client(cookies, {
* deviceData: await db.getDeviceData(userId)
* });
* ```
*/
getDeviceData(): string {
if (!this.handle) throw new Error("Not connected");
Expand Down
Loading