Skip to content

Commit 49a0bc6

Browse files
committed
Fix comlink serialization by converting Buffer to Uint8Array at worker boundary
1 parent f80db24 commit 49a0bc6

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

packages/sdk/src/encryption/EncryptionService.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ export class EncryptionService {
4949
* Encrypt the next group key using the current group key.
5050
*/
5151
async encryptNextGroupKey(currentKey: GroupKey, nextKey: GroupKey): Promise<EncryptedGroupKey> {
52+
// Convert Buffer to Uint8Array for worker communication
5253
const result = await this.getWorkerApi().encryptGroupKey({
5354
nextGroupKeyId: nextKey.id,
54-
nextGroupKeyData: nextKey.data,
55-
currentGroupKeyData: currentKey.data
55+
nextGroupKeyData: new Uint8Array(nextKey.data),
56+
currentGroupKeyData: new Uint8Array(currentKey.data)
5657
})
5758
if (result.type === 'error') {
5859
throw new Error(`Group key encryption failed: ${result.message}`)
@@ -67,10 +68,11 @@ export class EncryptionService {
6768
* Decrypt an encrypted group key using the current group key.
6869
*/
6970
async decryptNextGroupKey(currentKey: GroupKey, encryptedKey: EncryptedGroupKey): Promise<GroupKey> {
71+
// Convert Buffer to Uint8Array for worker communication
7072
const result = await this.getWorkerApi().decryptGroupKey({
7173
encryptedGroupKeyId: encryptedKey.id,
72-
encryptedGroupKeyData: encryptedKey.data,
73-
currentGroupKeyData: currentKey.data
74+
encryptedGroupKeyData: new Uint8Array(encryptedKey.data),
75+
currentGroupKeyData: new Uint8Array(currentKey.data)
7476
})
7577
if (result.type === 'error') {
7678
throw new Error(`Group key decryption failed: ${result.message}`)
@@ -88,12 +90,13 @@ export class EncryptionService {
8890
groupKey: GroupKey,
8991
encryptedNewGroupKey?: EncryptedGroupKey
9092
): Promise<[Uint8Array, GroupKey?]> {
93+
// Convert Buffer to Uint8Array for worker communication
9194
const request = {
9295
content,
93-
groupKeyData: groupKey.data,
96+
groupKeyData: new Uint8Array(groupKey.data),
9497
newGroupKey: encryptedNewGroupKey ? {
9598
id: encryptedNewGroupKey.id,
96-
data: encryptedNewGroupKey.data
99+
data: new Uint8Array(encryptedNewGroupKey.data)
97100
} : undefined
98101
}
99102
const result = await this.getWorkerApi().decryptStreamMessage(

0 commit comments

Comments
 (0)