• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LukaJCB / ts-mls / 17283659198

28 Aug 2025 02:05AM UTC coverage: 93.75% (+1.7%) from 92.046%
17283659198

push

github

web-flow
Migrate from jest to vitest and parallelize tests (#90)

1121 of 1250 branches covered (89.68%)

Branch coverage included in aggregate %.

388 of 393 new or added lines in 63 files covered. (98.73%)

57 existing lines in 13 files now uncovered.

6364 of 6734 relevant lines covered (94.51%)

51774.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.19
/src/crypto/implementation/default/makeAead.ts
1
import { AeadInterface, Aes128Gcm, Aes256Gcm } from "@hpke/core"
1✔
2
import { DependencyError } from "../../../mlsError"
1✔
3
import { bytesToBuffer } from "../../../util/byteArray"
1✔
4
import { AeadAlgorithm, Aead } from "../../aead"
5

6
export async function makeAead(aeadAlg: AeadAlgorithm): Promise<[Aead, AeadInterface]> {
1,231✔
7
  switch (aeadAlg) {
1,231✔
8
    case "AES128GCM":
1,231✔
9
      return [
222✔
10
        {
222✔
11
          encrypt(key, nonce, aad, plaintext) {
222✔
12
            return encryptAesGcm(key, nonce, aad, plaintext)
1,029✔
13
          },
1,029✔
14
          decrypt(key, nonce, aad, ciphertext) {
222✔
15
            return decryptAesGcm(key, nonce, aad, ciphertext)
2,045✔
16
          },
2,045✔
17
        },
222✔
18
        new Aes128Gcm(),
222✔
19
      ]
222✔
20
    case "AES256GCM":
1,231✔
21
      return [
551✔
22
        {
551✔
23
          encrypt(key, nonce, aad, plaintext) {
551✔
24
            return encryptAesGcm(key, nonce, aad, plaintext)
4,569✔
25
          },
4,569✔
26
          decrypt(key, nonce, aad, ciphertext) {
551✔
27
            return decryptAesGcm(key, nonce, aad, ciphertext)
8,956✔
28
          },
8,956✔
29
        },
551✔
30
        new Aes256Gcm(),
551✔
31
      ]
551✔
32
    case "CHACHA20POLY1305":
1,231✔
33
      try {
458✔
34
        const { Chacha20Poly1305 } = await import("@hpke/chacha20poly1305")
458✔
35
        const { chacha20poly1305 } = await import("@noble/ciphers/chacha")
458✔
36
        return [
458✔
37
          {
458✔
38
            async encrypt(key, nonce, aad, plaintext) {
458✔
39
              return chacha20poly1305(key, nonce, aad).encrypt(plaintext)
4,084✔
40
            },
4,084✔
41
            async decrypt(key, nonce, aad, ciphertext) {
458✔
42
              return chacha20poly1305(key, nonce, aad).decrypt(ciphertext)
7,956✔
43
            },
7,956✔
44
          },
458✔
45
          new Chacha20Poly1305(),
458✔
46
        ]
458✔
47
      } catch (err) {
458!
48
        throw new DependencyError(
×
UNCOV
49
          "Optional dependency '@hpke/chacha20poly1305' is not installed. Please install it to use this feature.",
×
UNCOV
50
        )
×
UNCOV
51
      }
×
52
  }
1,231✔
53
}
1,231✔
54

55
async function encryptAesGcm(
5,598✔
56
  key: Uint8Array,
5,598✔
57
  nonce: Uint8Array,
5,598✔
58
  aad: Uint8Array,
5,598✔
59
  plaintext: Uint8Array,
5,598✔
60
): Promise<Uint8Array> {
5,598✔
61
  const cryptoKey = await crypto.subtle.importKey("raw", bytesToBuffer(key), { name: "AES-GCM" }, false, ["encrypt"])
5,598✔
62
  const result = await crypto.subtle.encrypt(
5,598✔
63
    {
5,598✔
64
      name: "AES-GCM",
5,598✔
65
      iv: bytesToBuffer(nonce),
5,598✔
66
      additionalData: aad.length > 0 ? bytesToBuffer(aad) : undefined,
5,598✔
67
    },
5,598✔
68
    cryptoKey,
5,598✔
69
    bytesToBuffer(plaintext),
5,598✔
70
  )
5,598✔
71
  return new Uint8Array(result)
5,598✔
72
}
5,598✔
73

74
async function decryptAesGcm(
11,001✔
75
  key: Uint8Array,
11,001✔
76
  nonce: Uint8Array,
11,001✔
77
  aad: Uint8Array,
11,001✔
78
  ciphertext: Uint8Array,
11,001✔
79
): Promise<Uint8Array> {
11,001✔
80
  const cryptoKey = await crypto.subtle.importKey("raw", bytesToBuffer(key), { name: "AES-GCM" }, false, ["decrypt"])
11,001✔
81
  const result = await crypto.subtle.decrypt(
11,000✔
82
    {
11,000✔
83
      name: "AES-GCM",
11,000✔
84
      iv: bytesToBuffer(nonce),
11,000✔
85
      additionalData: aad.length > 0 ? bytesToBuffer(aad) : undefined,
11,001✔
86
    },
11,001✔
87
    cryptoKey,
11,001✔
88
    bytesToBuffer(ciphertext),
11,001✔
89
  )
11,001✔
90
  return new Uint8Array(result)
11,000✔
91
}
11,000✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc