Skip to content

Commit e424192

Browse files
committed
fix: resolve TypeScript 5.9 crypto API compatibility issues
1 parent 898e245 commit e424192

7 files changed

Lines changed: 26 additions & 27 deletions

File tree

src/components/editor/config/editor-config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,15 @@ lowlight.register('markdown', markdown);
4747
export function createEditorExtensions() {
4848
return [
4949
StarterKit.configure({
50-
history: {
51-
depth: 10,
52-
},
5350
heading: {
5451
levels: [1, 2, 3],
5552
},
5653
codeBlock: false,
5754
horizontalRule: false,
5855
dropcursor: false,
5956
// Disable built-in extensions we're adding separately
57+
link: false,
58+
underline: false,
6059
}),
6160
ExecutableCodeBlock.configure({
6261
defaultLanguage: 'javascript',

src/components/editor/hooks/useEditorEffects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function useEditorEffects({
3030
const currentContent = editor.getHTML();
3131
if (note.content !== currentContent) {
3232
const { from, to } = editor.state.selection;
33-
editor.commands.setContent(note.content || '', false);
33+
editor.commands.setContent(note.content || '', { emitUpdate: false });
3434
lastContentRef.current = note.content || '';
3535

3636
// Update word and character counts

src/lib/encryption/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class EncryptionService {
9393

9494
const keyMaterial = await crypto.subtle.importKey(
9595
'raw',
96-
securePassword.getBytes(),
96+
securePassword.getBytes().buffer as ArrayBuffer,
9797
{ name: 'PBKDF2' },
9898
false,
9999
['deriveKey']
@@ -102,7 +102,7 @@ class EncryptionService {
102102
const key = await crypto.subtle.deriveKey(
103103
{
104104
name: 'PBKDF2',
105-
salt: userSalt,
105+
salt: userSalt.buffer as ArrayBuffer,
106106
iterations: ENCRYPTION_CONFIG.ITERATIONS,
107107
hash: 'SHA-256',
108108
},
@@ -157,7 +157,7 @@ class EncryptionService {
157157

158158
const keyMaterial = await crypto.subtle.importKey(
159159
'raw',
160-
securePassword.getBytes(),
160+
securePassword.getBytes().buffer as ArrayBuffer,
161161
{ name: 'PBKDF2' },
162162
false,
163163
['deriveKey']
@@ -166,7 +166,7 @@ class EncryptionService {
166166
const key = await crypto.subtle.deriveKey(
167167
{
168168
name: 'PBKDF2',
169-
salt: userSalt,
169+
salt: userSalt.buffer as ArrayBuffer,
170170
iterations: ENCRYPTION_CONFIG.ITERATIONS,
171171
hash: 'SHA-256',
172172
},
@@ -192,7 +192,7 @@ class EncryptionService {
192192
const encryptedData = this.base64ToArrayBuffer(testObj.data);
193193

194194
await crypto.subtle.decrypt(
195-
{ name: ENCRYPTION_CONFIG.ALGORITHM, iv },
195+
{ name: ENCRYPTION_CONFIG.ALGORITHM, iv: iv.buffer as ArrayBuffer },
196196
key,
197197
encryptedData
198198
);
@@ -281,7 +281,7 @@ class EncryptionService {
281281
const keyData = this.base64ToUint8Array(userSecret);
282282
return crypto.subtle.importKey(
283283
'raw',
284-
keyData,
284+
keyData.buffer as ArrayBuffer,
285285
{ name: ENCRYPTION_CONFIG.ALGORITHM },
286286
false,
287287
['encrypt', 'decrypt']
@@ -301,7 +301,7 @@ class EncryptionService {
301301
return crypto.subtle.deriveKey(
302302
{
303303
name: 'PBKDF2',
304-
salt,
304+
salt: salt.buffer as ArrayBuffer,
305305
iterations: ENCRYPTION_CONFIG.ITERATIONS,
306306
hash: 'SHA-256',
307307
},
@@ -421,13 +421,13 @@ class EncryptionService {
421421
const contentBuffer = this.base64ToArrayBuffer(encryptedContent);
422422

423423
const decryptedTitleBuffer = await crypto.subtle.decrypt(
424-
{ name: ENCRYPTION_CONFIG.ALGORITHM, iv },
424+
{ name: ENCRYPTION_CONFIG.ALGORITHM, iv: iv.buffer as ArrayBuffer },
425425
key,
426426
titleBuffer
427427
);
428428

429429
const decryptedContentBuffer = await crypto.subtle.decrypt(
430-
{ name: ENCRYPTION_CONFIG.ALGORITHM, iv },
430+
{ name: ENCRYPTION_CONFIG.ALGORITHM, iv: iv.buffer as ArrayBuffer },
431431
key,
432432
contentBuffer
433433
);
@@ -496,7 +496,7 @@ class EncryptionService {
496496
return bytes.buffer.slice(
497497
bytes.byteOffset,
498498
bytes.byteOffset + bytes.byteLength
499-
);
499+
) as ArrayBuffer;
500500
}
501501

502502
private base64ToUint8Array(base64: string): Uint8Array {

src/lib/encryption/secureStorage.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SecureStorage {
2929

3030
try {
3131
const encoder = new TextEncoder();
32-
const data = encoder.encode(value);
32+
const data = encoder.encode(value).buffer as ArrayBuffer;
3333

3434
// Generate random IV for each encryption
3535
const iv = crypto.getRandomValues(
@@ -38,15 +38,15 @@ class SecureStorage {
3838

3939
// Encrypt the data
4040
const encryptedData = await crypto.subtle.encrypt(
41-
{ name: ENCRYPTION_CONFIG.ALGORITHM, iv },
41+
{ name: ENCRYPTION_CONFIG.ALGORITHM, iv: iv.buffer as ArrayBuffer },
4242
this.sessionKey!,
4343
data
4444
);
4545

4646
// Store encrypted data + IV
4747
const payload = {
4848
encrypted: this.arrayBufferToBase64(encryptedData),
49-
iv: this.arrayBufferToBase64(iv),
49+
iv: this.arrayBufferToBase64(iv.buffer as ArrayBuffer),
5050
};
5151

5252
localStorage.setItem(key, JSON.stringify(payload));
@@ -77,7 +77,7 @@ class SecureStorage {
7777
const iv = this.base64ToUint8Array(payload.iv);
7878

7979
const decryptedBuffer = await crypto.subtle.decrypt(
80-
{ name: ENCRYPTION_CONFIG.ALGORITHM, iv },
80+
{ name: ENCRYPTION_CONFIG.ALGORITHM, iv: iv.buffer as ArrayBuffer },
8181
this.sessionKey!,
8282
encryptedData
8383
);
@@ -120,7 +120,7 @@ class SecureStorage {
120120
return bytes.buffer.slice(
121121
bytes.byteOffset,
122122
bytes.byteOffset + bytes.byteLength
123-
);
123+
) as ArrayBuffer;
124124
}
125125

126126
private base64ToUint8Array(base64: string): Uint8Array {

src/lib/utils/messageAuth.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class MessageAuthenticator {
2121
const encoder = new TextEncoder();
2222
const keyMaterial = await crypto.subtle.importKey(
2323
'raw',
24-
encoder.encode(sessionSecret),
24+
encoder.encode(sessionSecret).buffer as ArrayBuffer,
2525
{ name: 'HMAC', hash: 'SHA-256' },
2626
false,
2727
['sign', 'verify']
@@ -57,7 +57,7 @@ class MessageAuthenticator {
5757
};
5858

5959
const encoder = new TextEncoder();
60-
const dataToSign = encoder.encode(JSON.stringify(messageData));
60+
const dataToSign = encoder.encode(JSON.stringify(messageData)).buffer as ArrayBuffer;
6161

6262
// Generate HMAC signature
6363
const signatureBuffer = await crypto.subtle.sign(
@@ -107,7 +107,7 @@ class MessageAuthenticator {
107107
};
108108

109109
const encoder = new TextEncoder();
110-
const dataToVerify = encoder.encode(JSON.stringify(messageData));
110+
const dataToVerify = encoder.encode(JSON.stringify(messageData)).buffer as ArrayBuffer;
111111
const signatureBuffer = this.base64ToArrayBuffer(message.signature);
112112

113113
// Verify HMAC signature
@@ -131,7 +131,7 @@ class MessageAuthenticator {
131131
private generateNonce(): string {
132132
const array = new Uint8Array(16);
133133
crypto.getRandomValues(array);
134-
return this.arrayBufferToBase64(array);
134+
return this.arrayBufferToBase64(array.buffer as ArrayBuffer);
135135
}
136136

137137
private arrayBufferToBase64(buffer: ArrayBuffer): string {

src/lib/utils/secureString.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class SecureString {
120120

121121
const keyMaterial = await crypto.subtle.importKey(
122122
'raw',
123-
this.data,
123+
this.data.buffer as ArrayBuffer,
124124
{ name: 'PBKDF2' },
125125
false,
126126
['deriveKey']
@@ -129,7 +129,7 @@ export class SecureString {
129129
return crypto.subtle.deriveKey(
130130
{
131131
name: 'PBKDF2',
132-
salt,
132+
salt: salt.buffer as ArrayBuffer,
133133
iterations,
134134
hash: 'SHA-256',
135135
},

src/services/fileService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class FileService {
8484

8585
// Decrypt the file content
8686
const decryptedBuffer = await crypto.subtle.decrypt(
87-
{ name: 'AES-GCM', iv: ivBytes },
87+
{ name: 'AES-GCM', iv: ivBytes.buffer as ArrayBuffer },
8888
key,
8989
encryptedBytes
9090
);
@@ -121,7 +121,7 @@ export class FileService {
121121
return bytes.buffer.slice(
122122
bytes.byteOffset,
123123
bytes.byteOffset + bytes.byteLength
124-
);
124+
) as ArrayBuffer;
125125
}
126126

127127
async uploadFiles(

0 commit comments

Comments
 (0)