mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
Implement E2EE and message content moderation
This commit is contained in:
1 parent
e1ff87dc03
commit
198cd80dfd
74 files changed
+12939
-2178
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { decode, encode } from "https://deno.land/std@0.208.0/encoding/base64.ts";
|
||||
|
||||
export interface KeysMetadata {
|
||||
sender_wrapped_key: string;
|
||||
recipient_wrapped_key?: string;
|
||||
admin_wrapped_key: string;
|
||||
admin_key_id: string;
|
||||
algorithm: string;
|
||||
key_wrap_algorithm: string;
|
||||
pending_recipient?: boolean;
|
||||
}
|
||||
|
||||
export async function unwrapWithAdminKey(
|
||||
wrappedKeyBase64: string,
|
||||
adminPrivateKeyJwk: JsonWebKey
|
||||
): Promise<ArrayBuffer> {
|
||||
const privateKey = await crypto.subtle.importKey(
|
||||
"jwk",
|
||||
adminPrivateKeyJwk,
|
||||
{ name: "RSA-OAEP", hash: "SHA-256" },
|
||||
false,
|
||||
["decrypt"]
|
||||
);
|
||||
|
||||
return await crypto.subtle.decrypt(
|
||||
{ name: "RSA-OAEP" },
|
||||
privateKey,
|
||||
base64ToUint8Array(wrappedKeyBase64)
|
||||
);
|
||||
}
|
||||
|
||||
export function base64ToUint8Array(base64: string): Uint8Array {
|
||||
return decode(base64);
|
||||
}
|
||||
|
||||
export function arrayBufferToBase64(buffer: ArrayBuffer): string {
|
||||
return encode(buffer);
|
||||
}
|
||||
Reference in new issue
Block a user