Skip to content

Commit 600ed77

Browse files
author
VishnuGadekar7
committed
Fix TypeScript type errors and crypto API references
1 parent fd0c1c1 commit 600ed77

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

service/src/cryptoAES.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface ISymmetricEncryption {
66
/** Generate / initialise the local encryption key. Idempotent. */
77
init(): Promise<void>;
88
/** Encrypt a raw data buffer. Returns the ciphertext and the IV used. */
9-
encryptData(data: ArrayBuffer): Promise<{ encryptedData: Uint8Array<ArrayBuffer>; iv: Uint8Array<ArrayBuffer> }>;
9+
encryptData(data: ArrayBuffer): Promise<{ encryptedData: Uint8Array; iv: Uint8Array }>;
1010
/** Decrypt a ciphertext buffer using the previously imported remote key. */
1111
decryptData(data: BufferSource, iv: BufferSource): Promise<ArrayBuffer>;
1212
/** Serialise the local key to a string for transmission (e.g. JWK JSON). */
@@ -53,12 +53,12 @@ export class AesGcmEncryption implements ISymmetricEncryption {
5353
);
5454
}
5555

56-
public async encryptData(data: ArrayBuffer): Promise<{ encryptedData: Uint8Array<ArrayBuffer>; iv: Uint8Array<ArrayBuffer> }> {
56+
public async encryptData(data: ArrayBuffer): Promise<{ encryptedData: Uint8Array; iv: Uint8Array }> {
5757
if (!this.aesKeyLocal) {
5858
throw new Error('Local AES key not generated.');
5959
}
60-
const iv = crypto.getRandomValues(new Uint8Array(12));
61-
const encryptedData = await crypto.subtle.encrypt(
60+
const iv = window.crypto.getRandomValues(new Uint8Array(12));
61+
const encryptedData = await window.crypto.subtle.encrypt(
6262
{ name: "AES-GCM", iv },
6363
this.aesKeyLocal,
6464
data
@@ -70,7 +70,7 @@ export class AesGcmEncryption implements ISymmetricEncryption {
7070
if (!this.aesKeyRemote) {
7171
throw new Error('Remote AES key not set.');
7272
}
73-
return crypto.subtle.decrypt(
73+
return window.crypto.subtle.decrypt(
7474
{ name: "AES-GCM", iv },
7575
this.aesKeyRemote,
7676
data

service/src/sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ class ChatE2EE implements IChatE2EE {
6868
constructor(config?: Partial<configType>, encryptionStrategy?: EncryptionStrategy) {
6969
config && setConfig(config);
7070
const defaults = EncryptionFactory.create();
71-
this.symEncryption = encryptionStrategy?.symmetric ?? defaults.symmetric;
72-
this.asymEncryption = encryptionStrategy?.asymmetric ?? defaults.asymmetric;
71+
this.symEncryption = encryptionStrategy?.symmetric ?? defaults.symmetric!;
72+
this.asymEncryption = encryptionStrategy?.asymmetric ?? defaults.asymmetric!;
7373
}
7474

7575
public async init(): Promise<void> {

0 commit comments

Comments
 (0)