Files
wehub-resource-sync 98e40dac97
CLI Smoke Test / smoke-test-linux (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-linux (24) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (20) (push) Has been cancelled
CLI Smoke Test / smoke-test-windows (24) (push) Has been cancelled
Expo App TypeScript typecheck / typecheck (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:40:49 +08:00

26 lines
821 B
TypeScript

import { KeyTree, crypto } from "privacy-kit";
let keyTree: KeyTree | null = null;
export async function initEncrypt() {
keyTree = new KeyTree(await crypto.deriveSecureKey({
key: process.env.HANDY_MASTER_SECRET!,
usage: 'happy-server-tokens'
}));
}
export function encryptString(path: string[], string: string) {
return keyTree!.symmetricEncrypt(path, string);
}
export function encryptBytes(path: string[], bytes: Uint8Array<ArrayBuffer>) {
return keyTree!.symmetricEncrypt(path, bytes);
}
export function decryptString(path: string[], encrypted: Uint8Array<ArrayBuffer>) {
return keyTree!.symmetricDecryptString(path, encrypted);
}
export function decryptBytes(path: string[], encrypted: Uint8Array<ArrayBuffer>) {
return keyTree!.symmetricDecryptBuffer(path, encrypted);
}