diff --git a/packages/communication/src/crypto/WsSessionCrypto.ts b/packages/communication/src/crypto/WsSessionCrypto.ts index e92078c..ed7f814 100644 --- a/packages/communication/src/crypto/WsSessionCrypto.ts +++ b/packages/communication/src/crypto/WsSessionCrypto.ts @@ -38,17 +38,17 @@ export async function deriveAesKey(sharedSecret: ArrayBuffer): Promise +export async function aesGcmEncrypt(key: CryptoKey, nonce: Uint8Array, plaintext: ArrayBuffer): Promise { return window.crypto.subtle.encrypt({ name: 'AES-GCM', iv: nonce, tagLength: GCM_TAG_LEN * 8 }, key, plaintext); } -export async function aesGcmDecrypt(key: CryptoKey, nonce: Uint8Array, ciphertextWithTag: ArrayBuffer): Promise +export async function aesGcmDecrypt(key: CryptoKey, nonce: Uint8Array, ciphertextWithTag: ArrayBuffer): Promise { return window.crypto.subtle.decrypt({ name: 'AES-GCM', iv: nonce, tagLength: GCM_TAG_LEN * 8 }, key, ciphertextWithTag); } -export function randomNonce(): Uint8Array +export function randomNonce(): Uint8Array { const n = new Uint8Array(NONCE_LEN); window.crypto.getRandomValues(n); diff --git a/packages/utils/src/ArrayBufferToBase64.ts b/packages/utils/src/ArrayBufferToBase64.ts index aa8eb74..409bca0 100644 --- a/packages/utils/src/ArrayBufferToBase64.ts +++ b/packages/utils/src/ArrayBufferToBase64.ts @@ -1,8 +1,8 @@ -export const ArrayBufferToBase64 = (buffer: ArrayBuffer) => +export const ArrayBufferToBase64 = (buffer: ArrayBufferLike | Uint8Array) => { let binary = ''; - const bytes = new Uint8Array(buffer); + const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer); const len = bytes.byteLength; for(let i = 0; i < len; i++) (binary += String.fromCharCode(bytes[i])); diff --git a/packages/utils/src/BinaryReader.ts b/packages/utils/src/BinaryReader.ts index b0c68ac..f42b25f 100644 --- a/packages/utils/src/BinaryReader.ts +++ b/packages/utils/src/BinaryReader.ts @@ -13,7 +13,7 @@ export class BinaryReader implements IBinaryReader public readBytes(length: number): IBinaryReader { - const buffer = new BinaryReader(this._dataView.buffer.slice(this._position, this._position + length)); + const buffer = new BinaryReader(this._dataView.buffer.slice(this._position, this._position + length) as ArrayBuffer); this._position += length; @@ -77,6 +77,6 @@ export class BinaryReader implements IBinaryReader public toArrayBuffer(): ArrayBuffer { - return this._dataView.buffer; + return this._dataView.buffer as ArrayBuffer; } } diff --git a/packages/utils/src/BinaryWriter.ts b/packages/utils/src/BinaryWriter.ts index dd20ef5..554a823 100644 --- a/packages/utils/src/BinaryWriter.ts +++ b/packages/utils/src/BinaryWriter.ts @@ -89,7 +89,7 @@ export class BinaryWriter implements IBinaryWriter public getBuffer(): ArrayBuffer { - return this._buffer.buffer; + return this._buffer.buffer as ArrayBuffer; } public get position(): number