Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit 9465fcc

Browse files
clean up code
1 parent 50e336d commit 9465fcc

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/webauthn/index.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class WebAuthnController {
130130
function convertDEREncodedECDSASignature(derEncoded: Uint8Array): Uint8Array {
131131
const rStart = 4;
132132
const rLength = derEncoded[3];
133-
const rEnd = rStart + rLength!;
133+
const rEnd = rStart + rLength;
134134
const DEREncodedR = derEncoded.slice(rStart, rEnd);
135135
// DER encoded 32 bytes integers can have leading 0x00s or be smaller than 32 bytes
136136
const r = decodeDERInteger(DEREncodedR, 32);
@@ -146,13 +146,14 @@ function convertDEREncodedECDSASignature(derEncoded: Uint8Array): Uint8Array {
146146
}
147147

148148
function decodeDERInteger(integerBytes: Uint8Array, expectedLength: number): Uint8Array {
149-
if (integerBytes.byteLength === expectedLength) return integerBytes;
149+
if (integerBytes.byteLength === expectedLength) {
150+
return integerBytes;
151+
}
150152
if (integerBytes.byteLength < expectedLength) {
151-
return concatenateBytes(
152-
// add leading 0x00s if smaller than expected length
153-
new Uint8Array(expectedLength - integerBytes.byteLength).fill(0),
154-
integerBytes
155-
);
153+
// add leading 0x00s if smaller than expected length
154+
const result = new Uint8Array(expectedLength);
155+
result.set(integerBytes, expectedLength - integerBytes.byteLength);
156+
return result;
156157
}
157158
// remove leading 0x00s if larger then expected length
158159
return integerBytes.slice(-32);

0 commit comments

Comments
 (0)