[Fix] Harden MTP codec, transport, and SDK security

This commit is contained in:
Alex Emmet 2026-08-18 20:57:45 +02:00
commit a7e804c603
No known key found for this signature in database
73 changed files with 11892 additions and 5756 deletions

26
src/sdk/credentials.ts Normal file
View file

@ -0,0 +1,26 @@
import type { MTPClientCredentials } from "./index.js";
export type InternalCredentials = {
clientId: bigint | null;
keyring: Uint8Array;
hostPublicKey?: Uint8Array;
};
export function publicCredentials(
credentials: InternalCredentials | null,
): MTPClientCredentials | null {
if (!credentials) {
return null;
}
return {
clientId: credentials.clientId,
keyring: credentials.keyring.slice(),
hostPublicKey: credentials.hostPublicKey?.slice(),
};
}
export function zeroCredentials(credentials: InternalCredentials | null): void {
// The host public key is intentionally not wiped: it is public configuration
// and may also be retained by the connection options.
credentials?.keyring.fill(0);
}