Skip to content

Commit 9a7bc34

Browse files
committed
0.0.3
1 parent 1c77d2d commit 9a7bc34

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/generator/CodeGenerator.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ export class CodeGenerator {
2929
}
3030

3131
public setVerifiedKeys(keys: Iterable<number>): void {
32-
this.verifiedKeys = Array.from(keys).map(k => k | 0);
32+
this.verifiedKeys = Array.from(keys).map((k) => k | 0);
3333
}
3434

3535
public setBlacklistedSerials(serials: Iterable<number>): void {
36-
this.blacklistedSerials = Array.from(serials).map(s => s >>> 0);
36+
this.blacklistedSerials = Array.from(serials).map((s) => s >>> 0);
3737
}
3838

3939
public getBlacklistedSerials(): number[] {
@@ -57,7 +57,9 @@ export class CodeGenerator {
5757
// Collect imports
5858
const imports = new Set<string>();
5959
imports.add("PartialKeyValidator");
60-
imports.add("Fnv1a"); // always used if validateUsername=true
60+
if (this.validateUsername) {
61+
imports.add("Fnv1a"); // only needed if username validation
62+
}
6163

6264
imports.add(checksumClass);
6365
for (const keyIndex of this.verifiedKeys) {
@@ -66,16 +68,13 @@ export class CodeGenerator {
6668
}
6769
}
6870

69-
// Header with imports
71+
// Header with combined import
7072
code += `// Auto-generated validation snippet${nl}`;
71-
imports.forEach(imp => {
72-
code += `import { ${imp} } from "../";${nl}`;
73-
});
74-
code += nl;
73+
code += `import { ${Array.from(imports).sort().join(", ")} } from "pkv.js";${nl}${nl}`;
7574

7675
// Method signature
7776
const sigParams = this.validateUsername ? "userName: string, key: string" : "key: string";
78-
code += `private static validateKey(${sigParams}): boolean {${nl}`;
77+
code += `function validateKey(${sigParams}): boolean {${nl}`;
7978

8079
if (this.validateUsername) {
8180
code += `${tab}const validator = new PartialKeyValidator(new Fnv1a());${nl}${nl}`;

0 commit comments

Comments
 (0)