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

PeculiarVentures / xmldsigjs / 16903405456

12 Aug 2025 08:29AM UTC coverage: 89.156% (+5.9%) from 83.278%
16903405456

push

github

web-flow
Merge pull request #82 from PeculiarVentures/monorepo

952 of 1192 branches covered (79.87%)

5433 of 6095 new or added lines in 92 files covered. (89.14%)

5443 of 6105 relevant lines covered (89.16%)

1565.31 hits per line

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

85.71
/packages/xmldsig/src/algorithm.ts
1
import { Convert, Stringify } from 'xml-core';
1✔
2
import { Application } from './application.js';
1✔
3
import { SignatureMethod } from './xml/signature_method.js';
4

5
export type BASE64 = string;
6

7
export interface IAlgorithm {
8
  algorithm: Algorithm;
9
  namespaceURI: string;
10
  getAlgorithmName(): string;
11
}
12

13
export interface IHashAlgorithm extends IAlgorithm {
14
  Digest(xml: BufferSource | string | Node): Promise<Uint8Array>;
15
}
16

17
export type IHashAlgorithmConstructable = new () => IHashAlgorithm;
18

19
export abstract class XmlAlgorithm implements IAlgorithm {
1✔
20
  public algorithm: Algorithm;
21
  public namespaceURI: string;
22

23
  public getAlgorithmName(): string {
1✔
NEW
24
    return this.namespaceURI;
×
NEW
25
  }
×
26
}
1✔
27

28
export abstract class HashAlgorithm extends XmlAlgorithm implements IHashAlgorithm {
1✔
29
  public async Digest(xml: BufferSource | string | Node): Promise<Uint8Array> {
1✔
30
    // console.log("HashedInfo:", xml);
31
    let buf: Uint8Array;
168✔
32
    if (typeof xml === 'string') {
168✔
33
      // C14N transforms
34
      // console.log("Hash:\n%s\n", xml);
35
      buf = Convert.FromString(xml, 'utf8');
146✔
36
    } else if (ArrayBuffer.isView(xml)) {
166✔
37
      buf = new Uint8Array(xml.buffer);
14✔
38
    } else if (xml instanceof ArrayBuffer) {
22✔
39
      // base64 transform
40
      buf = new Uint8Array(xml);
8✔
41
    } else {
8!
42
      // enveloped signature transform
NEW
43
      const txt = Stringify(xml);
×
NEW
44
      buf = Convert.FromString(txt, 'utf8');
×
NEW
45
    }
×
46
    const hash = await Application.crypto.subtle.digest(this.algorithm, buf);
168✔
47
    return new Uint8Array(hash);
168✔
48
  }
168✔
49
}
1✔
50

51
export interface ISignatureAlgorithm extends IAlgorithm {
52
  /**
53
   * Optional method to retrieve parameters from a SignatureMethod.
54
   */
55
  fromMethod?: (method: SignatureMethod) => void;
56
  /**
57
   * Optional method to set parameters to a SignatureMethod.
58
   */
59
  toMethod?: (method: SignatureMethod) => void;
60
  Sign(signedInfo: string, signingKey: CryptoKey, algorithm: Algorithm): Promise<ArrayBuffer>;
61
  Verify(signedInfo: string, key: CryptoKey, signatureValue: Uint8Array): Promise<boolean>;
62
}
63

64
export interface ISignatureAlgorithmConstructable {
65
  new (): ISignatureAlgorithm;
66
  fromAlgorithm(alg: Algorithm): ISignatureAlgorithm | null;
67
}
68

69
export abstract class SignatureAlgorithm extends XmlAlgorithm implements ISignatureAlgorithm {
1✔
70
  /**
71
   * Sign the given string using the given key
72
   */
73
  public async Sign(signedInfo: string, signingKey: CryptoKey, algorithm: Algorithm) {
1✔
74
    const info = Convert.FromString(signedInfo, 'utf8');
61✔
75

76
    return Application.crypto.subtle.sign(algorithm as any, signingKey, info);
61✔
77
  }
61✔
78

79
  /**
80
   * Verify the given signature of the given string using key
81
   */
82
  public async Verify(signedInfo: string, key: CryptoKey, signatureValue: Uint8Array) {
1✔
83
    const alg = this.algorithm;
81✔
84
    const info = Convert.FromString(signedInfo, 'utf8');
81✔
85

86
    return Application.crypto.subtle.verify(alg, key, signatureValue, info);
81✔
87
  }
81✔
88
}
1✔
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