mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Fix type issues
This commit is contained in:
+2
-12
@@ -6,7 +6,7 @@ import { importAesGcmKey, aesGcmEncrypt, aesGcmDecrypt } from "../crypto/symmetr
|
|||||||
import { randomBytes } from "../crypto/kdf";
|
import { randomBytes } from "../crypto/kdf";
|
||||||
import { getCurrentKeys } from "../auth/crypto";
|
import { getCurrentKeys } from "../auth/crypto";
|
||||||
import { request, websocket } from "../websocket";
|
import { request, websocket } from "../websocket";
|
||||||
import type { FetchDMResponse, SendDMRequest, WebSocketMessage, User } from "../core/types";
|
import type { FetchDMResponse, SendDMRequest, WebSocketMessage, User, DmEnvelope } from "../core/types";
|
||||||
import type { Tabs } from "mdui/components/tabs";
|
import type { Tabs } from "mdui/components/tabs";
|
||||||
import { b64, ub64 } from "../utils/utils";
|
import { b64, ub64 } from "../utils/utils";
|
||||||
|
|
||||||
@@ -35,17 +35,7 @@ export async function sendDm(recipientId: number, recipientPublicKeyB64: string,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DmEnvelope {
|
|
||||||
id: number;
|
|
||||||
senderId: number;
|
|
||||||
recipientId: number;
|
|
||||||
iv: string;
|
|
||||||
ciphertext: string;
|
|
||||||
salt: string;
|
|
||||||
iv2: string;
|
|
||||||
wrappedMk: string;
|
|
||||||
timestamp: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function fetchDm(since?: number): Promise<DmEnvelope[]> {
|
export async function fetchDm(since?: number): Promise<DmEnvelope[]> {
|
||||||
const url = new URL(`${API_BASE_URL}/dm/fetch`);
|
const url = new URL(`${API_BASE_URL}/dm/fetch`);
|
||||||
|
|||||||
Vendored
+12
-1
@@ -5,7 +5,6 @@
|
|||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { DmEnvelope } from "../chat/dm";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP headers object type
|
* HTTP headers object type
|
||||||
@@ -169,6 +168,18 @@ export interface BackupBlob {
|
|||||||
blob: string;
|
blob: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DmEnvelope {
|
||||||
|
id: number;
|
||||||
|
senderId: number;
|
||||||
|
recipientId: number;
|
||||||
|
iv: string;
|
||||||
|
ciphertext: string;
|
||||||
|
salt: string;
|
||||||
|
iv2: string;
|
||||||
|
wrappedMk: string;
|
||||||
|
timestamp: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface FetchDMResponse {
|
export interface FetchDMResponse {
|
||||||
messages: DmEnvelope[]
|
messages: DmEnvelope[]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,18 @@ export async function aesGcmEncrypt(key: CryptoKey, plaintext: Uint8Array | Arra
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function aesGcmDecrypt(key: CryptoKey, iv: Uint8Array | ArrayBuffer, ciphertext: Uint8Array | ArrayBuffer): Promise<Uint8Array> {
|
export async function aesGcmDecrypt(key: CryptoKey, iv: Uint8Array | ArrayBuffer, ciphertext: Uint8Array | ArrayBuffer): Promise<Uint8Array> {
|
||||||
// WebCrypto AES-GCM requires Uint8Array for iv and data; passing ArrayBuffer slices can break auth tag boundaries
|
// Normalize IV to ArrayBuffer (12 bytes for AES-GCM)
|
||||||
const ivBytes = iv instanceof Uint8Array ? iv : new Uint8Array(iv);
|
const ivBuf: ArrayBuffer = iv instanceof Uint8Array
|
||||||
const ctBytes = ciphertext instanceof Uint8Array ? ciphertext : new Uint8Array(ciphertext);
|
? (iv.buffer as ArrayBuffer).slice(iv.byteOffset, iv.byteOffset + iv.byteLength)
|
||||||
const pt = await crypto.subtle.decrypt({ name: "AES-GCM", iv: ivBytes }, key, ctBytes);
|
: (iv as ArrayBuffer);
|
||||||
return new Uint8Array(pt);
|
|
||||||
|
// Normalize ciphertext to a contiguous ArrayBuffer slice
|
||||||
|
const ctBuf: ArrayBuffer = ciphertext instanceof Uint8Array
|
||||||
|
? (ciphertext.buffer as ArrayBuffer).slice(ciphertext.byteOffset, ciphertext.byteOffset + ciphertext.byteLength)
|
||||||
|
: (ciphertext as ArrayBuffer);
|
||||||
|
|
||||||
|
const pt = await crypto.subtle.decrypt({ name: "AES-GCM", iv: ivBuf }, key, ctBuf);
|
||||||
|
return new Uint8Array(pt as ArrayBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function importAesGcmKey(rawKey: Uint8Array | ArrayBuffer): Promise<CryptoKey> {
|
export async function importAesGcmKey(rawKey: Uint8Array | ArrayBuffer): Promise<CryptoKey> {
|
||||||
|
|||||||
Vendored
-4
@@ -1,4 +0,0 @@
|
|||||||
declare module "tweetnacl" {
|
|
||||||
const nacl: any;
|
|
||||||
export default nacl;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user