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

hyperledger-identus / sdk-ts / 14536530200

18 Apr 2025 02:17PM UTC coverage: 82.802% (+7.3%) from 75.544%
14536530200

Pull #419

github

web-flow
Merge d20157089 into 0bddae204
Pull Request #419: test: chai and sinon removal

1711 of 2060 branches covered (83.06%)

Branch coverage included in aggregate %.

1 of 4 new or added lines in 1 file covered. (25.0%)

1047 existing lines in 114 files now uncovered.

9401 of 11360 relevant lines covered (82.76%)

33.67 hits per line

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

38.98
/src/pollux/utils/jwt/DER.ts
1
/**
2
 * Fix around normalising DER signatures into their raw representation
3
 * @param derSignature Uint8Array
4
 * @returns Uint8Array
5
 */
6
export function normaliseDER(derSignature: Uint8Array): Uint8Array {
1✔
7
    // Ensure the DER signature starts with the correct sequence header
8
    if (derSignature[0] !== 0x30) {
27!
9
        return derSignature;
×
UNCOV
10
    }
×
11
    // Get the length of the sequence
12
    let seqLength = derSignature[1];
27✔
13
    let offset = 2;
27✔
14
    if (seqLength & 0x80) {
27!
15
        const lengthBytes = seqLength & 0x7f;
×
16
        seqLength = 0;
×
17
        for (let i = 0; i < lengthBytes; i++) {
×
18
            seqLength = (seqLength << 8) | derSignature[offset++];
×
UNCOV
19
        }
×
UNCOV
20
    }
×
21

22
    if (derSignature[offset++] !== 0x02) {
27!
23
        throw new Error('Invalid DER signature: expected integer for r');
×
UNCOV
24
    }
×
25

26
    const rLength = derSignature[offset++];
27✔
27
    let r = Buffer.from(derSignature.slice(offset, offset + rLength));
27✔
28
    offset += rLength;
27✔
29

30
    // Extract s value
31
    if (derSignature[offset++] !== 0x02) {
27!
32
        throw new Error('Invalid DER signature: expected integer for s');
×
UNCOV
33
    }
×
34
    const sLength = derSignature[offset++];
27✔
35
    let s = Buffer.from(derSignature.slice(offset, offset + sLength));
27✔
36

37
    // Normalize r and s to 32 bytes
38
    if (r.length > 32) {
27✔
39
        r = r.subarray(-32); // truncate if r is longer than 32 bytes
15✔
40
    } else if (r.length < 32) {
23!
NEW
41
        const paddedR = Buffer.alloc(32);
×
42
        r.copy(paddedR, 32 - r.length);
×
43
        r = Buffer.from(paddedR); // left pad with zeros if r is shorter than 32 bytes
×
UNCOV
44
    }
×
45

46
    if (s.length > 32) {
27!
NEW
47
        s = s.subarray(-32); // truncate if s is longer than 32 bytes
×
48
    } else if (s.length < 32) {
27!
NEW
49
        const paddedS = Buffer.alloc(32);
×
50
        s.copy(paddedS, 32 - s.length);
×
51
        s = Buffer.from(paddedS); // left pad with zeros if s is shorter than 32 bytes
×
UNCOV
52
    }
×
53

54
    // Concatenate r and s to form the raw signature
55
    return Uint8Array.from([...r, ...s]);
27✔
56
}
27✔
57
/**
58
 * Remove leading zeros from a buffer
59
 * @param buffer Buffer
60
 * @returns Buffer
61
 */
UNCOV
62
function removeLeadingZeros(buffer: Buffer): Buffer {
×
63
    const arr = Array.from(buffer)
×
64
    let i = 0;
×
65
    while (i < arr.length - 1 && arr[i] === 0) {
×
66
        i++;
×
UNCOV
67
    }
×
68
    return Buffer.from(arr.slice(i));
×
UNCOV
69
}
×
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

© 2025 Coveralls, Inc