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

PeculiarVentures / x509 / 15564777427

10 Jun 2025 04:16PM UTC coverage: 90.282% (+1.9%) from 88.355%
15564777427

push

github

microshine
chore(deps): deduplicate dependencies

726 of 843 branches covered (86.12%)

Branch coverage included in aggregate %.

2795 of 3057 relevant lines covered (91.43%)

55.14 hits per line

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

72.6
/src/ed_algorithm.ts
1
import { AlgorithmIdentifier } from "@peculiar/asn1-x509";
2✔
2
import { container, injectable } from "tsyringe";
2✔
3
import { diAlgorithm, IAlgorithm } from "./algorithm";
2✔
4
import { HashedAlgorithm } from "./types";
5

6
// id-X25519    OBJECT IDENTIFIER ::= { 1 3 101 110 }
7
export const idX25519 = "1.3.101.110";
2✔
8
// id-X448      OBJECT IDENTIFIER ::= { 1 3 101 111 }
9
export const idX448 = "1.3.101.111";
2✔
10
// id-Ed25519   OBJECT IDENTIFIER ::= { 1 3 101 112 }
11
export const idEd25519 = "1.3.101.112";
2✔
12
// id-Ed448     OBJECT IDENTIFIER ::= { 1 3 101 113 }
13
export const idEd448 = "1.3.101.113";
2✔
14

15
/**
16
 * ECDH-ES and EdDSA algorithm provider
17
 */
18
@injectable()
2✔
19
export class EdAlgorithm implements IAlgorithm {
2✔
20

21
  public toAsnAlgorithm(alg: EcKeyGenParams): AlgorithmIdentifier | null {
2✔
22
    let algorithm: string | null = null;
4✔
23
    switch (alg.name.toLowerCase()) {
4✔
24
      case "ed25519":
4!
25
        // This algorithm is supported by WebCrypto API
26
        algorithm = idEd25519;
×
27
        break;
×
28
      case "x25519":
4!
29
        // This algorithm is supported by WebCrypto API
30
        algorithm = idX25519;
×
31
        break;
×
32
      case "eddsa":
4✔
33
        // This algorithm works with @peculiar/webcrypto only
34
        switch (alg.namedCurve.toLowerCase()) {
2✔
35
          case "ed25519":
2!
36
            algorithm = idEd25519;
×
37
            break;
×
38
          case "ed448":
2✔
39
            algorithm = idEd448;
2✔
40
            break;
2✔
41
        }
2✔
42
        break;
2✔
43
      case "ecdh-es":
4!
44
        // This algorithm works with @peculiar/webcrypto only
45
        switch (alg.namedCurve.toLowerCase()) {
×
46
          case "x25519":
×
47
            algorithm = idX25519;
×
48
            break;
×
49
          case "x448":
×
50
            algorithm = idX448;
×
51
            break;
×
52
        }
×
53
    }
4✔
54
    if (algorithm) {
4✔
55
      return new AlgorithmIdentifier({
2✔
56
        algorithm,
2✔
57
      });
2✔
58
    }
2✔
59

60
    return null;
2✔
61
  }
4✔
62

63
  public toWebAlgorithm(alg: AlgorithmIdentifier): HashedAlgorithm | EcKeyGenParams | Algorithm | null {
2✔
64
    switch (alg.algorithm) {
12✔
65
      case idEd25519:
12✔
66
        return { name: "Ed25519" };
4✔
67
      case idEd448:
12✔
68
        return { name: "EdDSA", namedCurve: "Ed448" };
2✔
69
      case idX25519:
12!
70
        return { name: "X25519" };
×
71
      case idX448:
12✔
72
        return { name: "ECDH-ES", namedCurve: "X448" };
2✔
73
    }
12✔
74

75
    return null;
4✔
76
  }
12✔
77

78
}
2✔
79

80
// register ED algorithm provider as a singleton object
81
container.registerSingleton(diAlgorithm, EdAlgorithm);
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc