MCPcopy Index your code
hub / github.com/CapSoftware/Cap / deriveKey

Function deriveKey

packages/database/crypto.ts:35–61  ·  view source on GitHub ↗
(salt: BufferSource)

Source from the content-addressed store, hash-verified

33};
34
35async function deriveKey(salt: BufferSource): Promise<CryptoKey> {
36 const key = ENCRYPTION_KEY();
37 if (!key) throw new Error("Encryption key is not available");
38
39 const keyBuffer = Buffer.from(key, "hex");
40
41 const keyMaterial = await crypto.subtle.importKey(
42 "raw",
43 keyBuffer,
44 "PBKDF2",
45 false,
46 ["deriveKey"],
47 );
48
49 return crypto.subtle.deriveKey(
50 {
51 name: "PBKDF2",
52 salt,
53 iterations: ITERATIONS,
54 hash: "SHA-256",
55 },
56 keyMaterial,
57 ALGORITHM,
58 false,
59 ["encrypt", "decrypt"],
60 );
61}
62
63export async function encrypt(text: string): Promise<string> {
64 if (!text) {

Callers 2

encryptFunction · 0.85
decryptFunction · 0.85

Calls 1

ENCRYPTION_KEYFunction · 0.85

Tested by

no test coverage detected