@ianacaburian/generate-key-file 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,6 +6,10 @@ Ports juce_KeyGeneration::generateKeyFile() to node.
6
6
  [![NPM Version](https://img.shields.io/npm/v/%40ianacaburian%2Fgenerate-key-file)](https://www.npmjs.com/package/@ianacaburian/generate-key-file)
7
7
  [![X (formerly Twitter) URL](https://img.shields.io/twitter/url?url=https%3A%2F%2Ftwitter.com%2Fintent%2Fpost%3Ftext%3DNeed%2520to%2520auth%2520a%2520JUCE%2520app%2520in%2520nodejs%2520%253F%2520Check%2520out%2520generate-key-file%2520by%2520%2540ianacaburian%2520%2520%26url%3Dhttps%253A%252F%252Fgithub.com%252Fianacaburian%252Fgenerate-key-file)](https://twitter.com/intent/tweet?text=Need%20to%20auth%20a%20JUCE%20app%20in%20nodejs%20%3F%20Check%20out%20generate-key-file%20by%20%40ianacaburian%20%20&url=https%3A%2F%2Fgithub.com%2Fianacaburian%2Fgenerate-key-file)
8
8
 
9
+ ## Requirements
10
+
11
+ Node.js >= 24
12
+
9
13
  ## Installation
10
14
 
11
15
  ```
@@ -39,7 +43,7 @@ const keyFileContent = generateKeyFile({
39
43
  - Returns the <key> string value to be used in the XML response for decryption
40
44
  by the client.
41
45
  - Throws ZodError for invalid params -- see
42
- [zod](https://github.com/colinhacks/zod).
46
+ [zod](https://zod.dev).
43
47
  - From juce_KeyFileGeneration.h:
44
48
 
45
49
  ```
@@ -80,7 +84,7 @@ const expiringKeyFileContent = generateExpiringKeyFile({
80
84
  userEmail: 'ian@email.com',
81
85
  machineNumbers: '123',
82
86
  appName: 'app-name-or-product-id',
83
- privateKey: 'comma-sep-private-key'
87
+ privateKey: 'comma-sep-private-key',
84
88
  expiryTime: oneDayFromNow
85
89
  })
86
90
  ```
@@ -88,7 +92,7 @@ const expiringKeyFileContent = generateExpiringKeyFile({
88
92
  - Returns the <key> string value to be used in the XML response for decryption
89
93
  by the client.
90
94
  - Throws ZodError for invalid params -- see
91
- [zod](https://github.com/colinhacks/zod).
95
+ [zod](https://zod.dev).
92
96
  - From juce_KeyFileGeneration.h:
93
97
 
94
98
  ```
@@ -121,8 +125,8 @@ npm run cm:open # Open test/console project in Xcode.
121
125
  npm run cm:install # Build and install the test/console bins.
122
126
  ```
123
127
 
124
- - Optional: Set "FC_NUM_RUMS" (default=1) to specify how many times to run
125
- each (randomly generated) propery-based test -- see
128
+ - Optional: Set "FC_NUM_RUNS" (default=1) to specify how many times to run
129
+ each (randomly generated) property-based test -- see
126
130
  [fast-check](https://github.com/dubzzz/fast-check).
127
131
 
128
132
  ```
package/dist/index.cjs CHANGED
@@ -18,15 +18,12 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  generateExpiringKeyFile: () => generateExpiringKeyFile,
24
24
  generateKeyFile: () => generateKeyFile
25
25
  });
26
- module.exports = __toCommonJS(src_exports);
27
-
28
- // src/juce/JuceKeyFileUtils.ts
29
- var import_fast_xml_parser = require("fast-xml-parser");
26
+ module.exports = __toCommonJS(index_exports);
30
27
 
31
28
  // src/juce/JuceBigInteger.ts
32
29
  var import_jsbn = require("jsbn");
@@ -88,17 +85,14 @@ var xmlAttributeCharProcessor = (char) => (
88
85
  // Ports juce::XmlOutputFunctions::escapeIllegalXMLChars()
89
86
  char.length !== 1 ? "" : legalXmlCharRegex.test(char) ? char : char === "&" ? "&amp;" : char === '"' ? "&quot;" : char === ">" ? "&gt;" : char === "<" ? "&lt;" : `&#${char.charCodeAt(0)};`
90
87
  );
91
- var xmlAttributeValueProcessor = (value) => (
88
+ var escapeAttr = (value) => (
92
89
  // Ports juce::XmlOutputFunctions::escapeIllegalXMLChars()
93
- typeof value !== "string" ? "" : value.split("").map(xmlAttributeCharProcessor).join("")
90
+ value.split("").map(xmlAttributeCharProcessor).join("")
94
91
  );
95
- var xmlBuilder = new import_fast_xml_parser.XMLBuilder({
96
- ignoreAttributes: false,
97
- suppressEmptyNode: true,
98
- // processEntities is disabled since it doesn't port to juce as is
99
- processEntities: false,
100
- attributeValueProcessor: (_, value) => xmlAttributeValueProcessor(value)
101
- });
92
+ var buildKeyElement = (attrs) => {
93
+ const attrStr = Object.entries(attrs).map(([k, v]) => `${k}="${escapeAttr(v)}"`).join(" ");
94
+ return `<key ${attrStr}/>`;
95
+ };
102
96
  var JuceKeyFileUtils = class {
103
97
  static toString(date) {
104
98
  const months = [
@@ -136,17 +130,15 @@ var JuceKeyFileUtils = class {
136
130
  machineNumbers,
137
131
  machineNumbersAttributeName
138
132
  }, date, expiryTime) {
139
- const xml = {
140
- key: {
141
- "@_user": userName,
142
- "@_email": userEmail,
143
- [`@_${machineNumbersAttributeName}`]: machineNumbers,
144
- "@_app": appName,
145
- "@_date": date,
146
- ...expiryTime ? { "@_expiryTime": expiryTime } : {}
147
- }
133
+ const attrs = {
134
+ user: userName,
135
+ email: userEmail,
136
+ [machineNumbersAttributeName]: machineNumbers,
137
+ app: appName,
138
+ date
148
139
  };
149
- return [XML_DECLARATION, xmlBuilder.build(xml).trim()].join(" ");
140
+ if (expiryTime) attrs.expiryTime = expiryTime;
141
+ return [XML_DECLARATION, buildKeyElement(attrs)].join(" ");
150
142
  }
151
143
  static createKeyFileComment({
152
144
  appName,
@@ -270,41 +262,42 @@ var JuceKeyGeneration = class {
270
262
 
271
263
  // src/types.ts
272
264
  var import_zod = require("zod");
273
- var createKeyFileCommentParamsValidator = import_zod.z.object({
265
+ var createKeyFileCommentParamsSchema = import_zod.z.object({
274
266
  appName: import_zod.z.string().min(1),
275
- userEmail: import_zod.z.string().min(1).email(),
267
+ userEmail: import_zod.z.string().min(1),
276
268
  userName: import_zod.z.string().min(1),
277
269
  machineNumbers: import_zod.z.string().min(1)
278
270
  });
279
- var machineNumbersAttributeNameValidator = import_zod.z.enum([
271
+ var machineNumbersAttributeNameSchema = import_zod.z.enum([
280
272
  "mach",
281
273
  "expiring_mach"
282
274
  ]);
283
- var createKeyFileContentLineParamsValidator = createKeyFileCommentParamsValidator.extend({
284
- machineNumbersAttributeName: machineNumbersAttributeNameValidator
275
+ var createKeyFileContentLineParamsSchema = createKeyFileCommentParamsSchema.extend({
276
+ machineNumbersAttributeName: machineNumbersAttributeNameSchema
285
277
  });
286
- var rsaKeyComponentsValidator = import_zod.z.string().refine(
278
+ var rsaKeyComponentsSchema = import_zod.z.stringFormat(
287
279
  // Ports juce::RSAKey::RSAKey() and juce::RSAKey::applyToValue()
280
+ "RSAKeyComponents",
288
281
  (x) => x.includes(",") && x.split(",").every((p) => !JuceBigInteger.fromHex(p).isZero())
289
282
  );
290
- var generateKeyFileParamsValidator = createKeyFileCommentParamsValidator.extend({
291
- privateKey: rsaKeyComponentsValidator
283
+ var generateKeyFileParamsSchema = createKeyFileCommentParamsSchema.extend({
284
+ privateKey: rsaKeyComponentsSchema
292
285
  });
293
- var generateExpiringKeyFileParamsValidator = generateKeyFileParamsValidator.extend({
286
+ var generateExpiringKeyFileParamsSchema = generateKeyFileParamsSchema.extend({
294
287
  expiryTime: import_zod.z.date().min(/* @__PURE__ */ new Date("1970-01-01T00:00:00.001Z"), {
295
- message: "Expiry time must be after 1970-01-01T00:00:00.000Z"
288
+ error: "Expiry time must be after 1970-01-01T00:00:00.000Z"
296
289
  })
297
290
  });
298
291
 
299
292
  // src/generateKeyFile.ts
300
293
  var generateKeyFile = (params, date = /* @__PURE__ */ new Date()) => {
301
- const paramsParse = generateKeyFileParamsValidator.parse(params);
294
+ const paramsParse = generateKeyFileParamsSchema.parse(params);
302
295
  return JuceKeyGeneration.generateKeyFile(paramsParse, date);
303
296
  };
304
297
 
305
298
  // src/generateExpiringKeyFile.ts
306
299
  var generateExpiringKeyFile = (params, date = /* @__PURE__ */ new Date()) => {
307
- const paramsParse = generateExpiringKeyFileParamsValidator.parse(params);
300
+ const paramsParse = generateExpiringKeyFileParamsSchema.parse(params);
308
301
  return JuceKeyGeneration.generateExpiringKeyFile(paramsParse, date);
309
302
  };
310
303
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/juce/JuceKeyFileUtils.ts","../src/juce/JuceBigInteger.ts","../src/juce/JuceRSAKey.ts","../src/juce/JuceKeyGeneration.ts","../src/types.ts","../src/generateKeyFile.ts","../src/generateExpiringKeyFile.ts"],"sourcesContent":["export {\n type GenerateKeyFileParams,\n type GenerateExpiringKeyFileParams\n} from './types'\n\nexport { generateKeyFile } from './generateKeyFile'\nexport { generateExpiringKeyFile } from './generateExpiringKeyFile'\n","import { XMLBuilder } from 'fast-xml-parser'\nimport {\n CreateKeyFileCommentParams,\n CreateKeyFileContentLineParams\n} from 'src/types'\n\nimport { JuceBigInteger } from './JuceBigInteger'\nimport { JuceRSAKey } from './JuceRSAKey'\n\nconst XML_DECLARATION = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>'\n\nconst legalXmlCharRegex =\n // Ports juce::XmlOutputFunctions::LegalCharLookupTable\n /^[a-zA-Z0-9 .,;:\\-()_+=?!$#@[\\]/|*%~{}'\\\\]$/\n\nconst xmlAttributeCharProcessor = (char: string): string =>\n // Ports juce::XmlOutputFunctions::escapeIllegalXMLChars()\n char.length !== 1\n ? ''\n : legalXmlCharRegex.test(char)\n ? char\n : char === '&'\n ? '&amp;'\n : char === '\"'\n ? '&quot;'\n : char === '>'\n ? '&gt;'\n : char === '<'\n ? '&lt;'\n : `&#${char.charCodeAt(0)};`\n\nconst xmlAttributeValueProcessor = (value: unknown): string =>\n // Ports juce::XmlOutputFunctions::escapeIllegalXMLChars()\n typeof value !== 'string'\n ? ''\n : value.split('').map(xmlAttributeCharProcessor).join('')\n\nconst xmlBuilder = new XMLBuilder({\n ignoreAttributes: false,\n suppressEmptyNode: true,\n // processEntities is disabled since it doesn't port to juce as is\n processEntities: false,\n attributeValueProcessor: (_, value) => xmlAttributeValueProcessor(value)\n})\n\nexport class JuceKeyFileUtils {\n static toString(date: Date): string {\n // Ports juce::Time::getCurrentTime().toString (true, true)\n // prettier-ignore\n const months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', \n 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]\n const day = date.getDate().toString()\n const month = months[date.getMonth()]\n const year = date.getFullYear()\n let hours = date.getHours()\n const minutes = date.getMinutes().toString().padStart(2, '0')\n const seconds = date.getSeconds().toString().padStart(2, '0')\n const ampm = hours >= 12 ? 'pm' : 'am'\n hours = hours % 12\n hours = hours ? hours : 12\n return `${day} ${month} ${year} ${hours}:${minutes}:${seconds}${ampm}`\n }\n\n static toHexStringMilliseconds(date: Date): string {\n // Ports juce::String::toHexString (juce::Time::getCurrentTime().toMilliseconds())\n return date.getTime().toString(16)\n }\n\n static createKeyFileContentLine(\n {\n appName,\n userEmail,\n userName,\n machineNumbers,\n machineNumbersAttributeName\n }: CreateKeyFileContentLineParams,\n date: string,\n expiryTime?: string\n ): string {\n // Ports juce::KeyFileUtils::createKeyFileContent\n // and juce::KeyFileUtils::encryptXML\n const xml = {\n key: {\n '@_user': userName,\n '@_email': userEmail,\n [`@_${machineNumbersAttributeName}`]: machineNumbers,\n '@_app': appName,\n '@_date': date,\n ...(expiryTime ? { '@_expiryTime': expiryTime } : {})\n }\n }\n return [XML_DECLARATION, xmlBuilder.build(xml).trim()].join(' ')\n }\n\n static createKeyFileComment(\n {\n appName,\n userEmail,\n userName,\n machineNumbers\n }: CreateKeyFileCommentParams,\n created: string,\n expiryTime?: string\n ): string {\n // Ports juce::KeyFileUtils::createKeyFileComment\n return (\n `Keyfile for ${appName}\\r\\n` +\n `${userName ? `User: ${userName}\\r\\n` : ''}` +\n `Email: ${userEmail}\\r\\n` +\n `Machine numbers: ${machineNumbers}\\r\\n` +\n `Created: ${created}` +\n (expiryTime ? `\\r\\nExpires: ${expiryTime}` : '')\n )\n }\n\n static encryptXMLLine(xmlLine: string, privateKey: JuceRSAKey): string {\n // Ports juce::KeyFileUtils::encryptXML\n const val = JuceBigInteger.fromUTF8MemoryBlock(xmlLine)\n privateKey.applyToValue(val)\n return val.toHex()\n }\n\n static createKeyFile(\n comment: string,\n xmlLine: string,\n rsaPrivateKey: JuceRSAKey\n ): string {\n // Ports juce::KeyFileUtils::createKeyFile\n let asHex = '#' + this.encryptXMLLine(xmlLine, rsaPrivateKey)\n\n const lines: string[] = []\n lines.push(comment)\n lines.push('')\n\n const charsPerLine = 70\n while (asHex.length > 0) {\n lines.push(asHex.substring(0, charsPerLine))\n asHex = asHex.substring(charsPerLine)\n }\n\n lines.push('')\n\n return lines.join('\\r\\n')\n }\n}\n","import { BigInteger as JSBN } from 'jsbn'\n\nexport class JuceBigInteger {\n constructor(public value: bigint = 0n) {}\n\n static fromJSBN(b: JSBN): JuceBigInteger {\n return JuceBigInteger.fromHex(b.toString(16))\n }\n\n toJSBN(): JSBN {\n return new JSBN(this.toHex(), 16)\n }\n\n static fromHex(hex: string): JuceBigInteger {\n const h = hex.trim()\n return new JuceBigInteger(h ? BigInt(`0x${h}`) : 0n)\n }\n\n toHex(): string {\n return this.value.toString(16)\n }\n\n static fromUTF8MemoryBlock(input: string): JuceBigInteger {\n // Ports juce::BigInteger::loadFromMemoryBlock()\n const u = Buffer.from(input, 'utf8')\n const b = new JuceBigInteger()\n for (let i = u.length - 1; i >= 0; i--) {\n b.value = (b.value << 8n) | BigInt(u[i])\n }\n return b\n }\n\n isZero(): boolean {\n return this.value === 0n\n }\n\n divideBy(divisor: JuceBigInteger, remainder: JuceBigInteger): void {\n // Ports juce::BigInteger::divideBy()\n if (divisor.isZero()) {\n this.value = 0n\n return\n }\n const b = this.toJSBN()\n const d = divisor.toJSBN()\n const [q, r] = b.divideAndRemainder(d)\n this.value = JuceBigInteger.fromJSBN(q).value\n remainder.value = JuceBigInteger.fromJSBN(r).value\n }\n\n exponentModulo(exponent: JuceBigInteger, modulus: JuceBigInteger): void {\n // Ports juce::BigInteger::exponentModulo()\n const b = this.toJSBN()\n const e = exponent.toJSBN()\n const m = modulus.toJSBN()\n const em = b.modPow(e, m)\n this.value = JuceBigInteger.fromJSBN(em).value\n }\n}\n","import { JuceBigInteger } from './JuceBigInteger'\n\nexport class JuceRSAKey {\n protected part1: JuceBigInteger\n protected part2: JuceBigInteger\n constructor(public s: string) {\n // Ports juce::RSAKey::RSAKey()\n if (s.includes(',')) {\n const [p1, p2] = s.split(',').map(p => JuceBigInteger.fromHex(p))\n this.part1 = p1\n this.part2 = p2\n } else {\n this.part1 = new JuceBigInteger()\n this.part2 = new JuceBigInteger()\n }\n }\n applyToValue(val: JuceBigInteger): void {\n // Ports juce::RSAKey::applyToValue()\n if (this.part1.isZero() || this.part2.isZero() || val.value <= 0n) {\n return\n }\n\n const result = new JuceBigInteger()\n\n while (!val.isZero()) {\n result.value *= this.part2.value\n\n const remainder = new JuceBigInteger()\n val.divideBy(this.part2, remainder)\n\n remainder.exponentModulo(this.part1, this.part2)\n\n result.value += remainder.value\n }\n\n val.value = result.value\n }\n}\n","import { GenerateExpiringKeyFileParams, GenerateKeyFileParams } from 'src/types'\n\nimport { JuceKeyFileUtils } from './JuceKeyFileUtils'\nimport { JuceRSAKey } from './JuceRSAKey'\n\nexport class JuceKeyGeneration {\n static generateKeyFile(\n params: GenerateKeyFileParams,\n date: Date = new Date()\n ) {\n const xml = JuceKeyFileUtils.createKeyFileContentLine(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers,\n machineNumbersAttributeName: 'mach'\n },\n JuceKeyFileUtils.toHexStringMilliseconds(date)\n )\n const comment = JuceKeyFileUtils.createKeyFileComment(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers\n },\n JuceKeyFileUtils.toString(date)\n )\n return JuceKeyFileUtils.createKeyFile(\n comment,\n xml,\n new JuceRSAKey(params.privateKey)\n )\n }\n\n static generateExpiringKeyFile(\n params: GenerateExpiringKeyFileParams,\n date: Date = new Date()\n ) {\n const xml = JuceKeyFileUtils.createKeyFileContentLine(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers,\n machineNumbersAttributeName: 'expiring_mach'\n },\n JuceKeyFileUtils.toHexStringMilliseconds(date),\n JuceKeyFileUtils.toHexStringMilliseconds(params.expiryTime)\n )\n const comment = JuceKeyFileUtils.createKeyFileComment(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers\n },\n JuceKeyFileUtils.toString(date),\n JuceKeyFileUtils.toString(params.expiryTime)\n )\n return JuceKeyFileUtils.createKeyFile(\n comment,\n xml,\n new JuceRSAKey(params.privateKey)\n )\n }\n}\n","import { z } from 'zod'\n\nimport { JuceBigInteger } from './juce/JuceBigInteger'\n\nexport const createKeyFileCommentParamsValidator = z.object({\n appName: z.string().min(1),\n userEmail: z.string().min(1).email(),\n userName: z.string().min(1),\n machineNumbers: z.string().min(1)\n})\nexport type CreateKeyFileCommentParams = z.infer<\n typeof createKeyFileCommentParamsValidator\n>\n\nexport const machineNumbersAttributeNameValidator = z.enum([\n 'mach',\n 'expiring_mach'\n])\nexport type MachineNumbersAttributeName = z.infer<\n typeof machineNumbersAttributeNameValidator\n>\n\nexport const createKeyFileContentLineParamsValidator =\n createKeyFileCommentParamsValidator.extend({\n machineNumbersAttributeName: machineNumbersAttributeNameValidator\n })\nexport type CreateKeyFileContentLineParams = z.infer<\n typeof createKeyFileContentLineParamsValidator\n>\n\nexport const rsaKeyComponentsValidator = z.string().refine(\n // Ports juce::RSAKey::RSAKey() and juce::RSAKey::applyToValue()\n x =>\n x.includes(',') &&\n x.split(',').every(p => !JuceBigInteger.fromHex(p).isZero())\n)\nexport type RSAKeyComponents = z.infer<typeof rsaKeyComponentsValidator>\n\nexport const generateKeyFileParamsValidator =\n createKeyFileCommentParamsValidator.extend({\n privateKey: rsaKeyComponentsValidator\n })\nexport type GenerateKeyFileParams = z.infer<\n typeof generateKeyFileParamsValidator\n>\n\nexport const generateExpiringKeyFileParamsValidator =\n generateKeyFileParamsValidator.extend({\n expiryTime: z.date().min(new Date('1970-01-01T00:00:00.001Z'), {\n message: 'Expiry time must be after 1970-01-01T00:00:00.000Z'\n })\n })\nexport type GenerateExpiringKeyFileParams = z.infer<\n typeof generateExpiringKeyFileParamsValidator\n>\n","import { JuceKeyGeneration } from './juce/JuceKeyGeneration'\nimport { GenerateKeyFileParams, generateKeyFileParamsValidator } from './types'\n\nexport const generateKeyFile = (\n params: GenerateKeyFileParams,\n date: Date = new Date()\n) => {\n const paramsParse = generateKeyFileParamsValidator.parse(params)\n return JuceKeyGeneration.generateKeyFile(paramsParse, date)\n}\n","import { JuceKeyGeneration } from './juce/JuceKeyGeneration'\nimport {\n GenerateExpiringKeyFileParams,\n generateExpiringKeyFileParamsValidator\n} from './types'\n\nexport const generateExpiringKeyFile = (\n params: GenerateExpiringKeyFileParams,\n date: Date = new Date()\n) => {\n const paramsParse = generateExpiringKeyFileParamsValidator.parse(params)\n return JuceKeyGeneration.generateExpiringKeyFile(paramsParse, date)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,6BAA2B;;;ACA3B,kBAAmC;AAE5B,IAAM,iBAAN,MAAM,gBAAe;AAAA,EACxB,YAAmB,QAAgB,IAAI;AAApB;AAAA,EAAqB;AAAA,EAExC,OAAO,SAAS,GAAyB;AACrC,WAAO,gBAAe,QAAQ,EAAE,SAAS,EAAE,CAAC;AAAA,EAChD;AAAA,EAEA,SAAe;AACX,WAAO,IAAI,YAAAA,WAAK,KAAK,MAAM,GAAG,EAAE;AAAA,EACpC;AAAA,EAEA,OAAO,QAAQ,KAA6B;AACxC,UAAM,IAAI,IAAI,KAAK;AACnB,WAAO,IAAI,gBAAe,IA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AAChB,CAAC;AAKE,IAAM,yCACT,+BAA+B,OAAO;AAAA,EAClC,YAAY,aAAE,KAAK,EAAE,IAAI,oBAAI,KAAK,0BAA0B,GAAG;AAAA,IAC3D,SAAS;AAAA,EACb,CAAC;AACL,CAAC;;;AChDE,IAAM,kBAAkB,CAC3B,QACA,OAAa,oBAAI,KAAK,MACrB;AACD,QAAM,cAAc,+BAA+B,MAAM,MAAM;AAC/D,SAAO,kBAAkB,gBAAgB,aAAa,IAAI;AAC9D;;;ACHO,IAAM,0BAA0B,CACnC,QACA,OAAa,oBAAI,KAAK,MACrB;AACD,QAAM,cAAc,uCAAuC,MAAM,MAAM;AACvE,SAAO,kBAAkB,wBAAwB,aAAa,IAAI;AACtE;","names":["JSBN"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/juce/JuceBigInteger.ts","../src/juce/JuceKeyFileUtils.ts","../src/juce/JuceRSAKey.ts","../src/juce/JuceKeyGeneration.ts","../src/types.ts","../src/generateKeyFile.ts","../src/generateExpiringKeyFile.ts"],"sourcesContent":["export {\n type GenerateKeyFileParams,\n type GenerateExpiringKeyFileParams\n} from './types'\n\nexport { generateKeyFile } from './generateKeyFile'\nexport { generateExpiringKeyFile } from './generateExpiringKeyFile'\n","import { BigInteger as JSBN } from 'jsbn'\n\nexport class JuceBigInteger {\n constructor(public value: bigint = 0n) {}\n\n static fromJSBN(b: JSBN): JuceBigInteger {\n return JuceBigInteger.fromHex(b.toString(16))\n }\n\n toJSBN(): JSBN {\n return new JSBN(this.toHex(), 16)\n }\n\n static fromHex(hex: string): JuceBigInteger {\n const h = hex.trim()\n return new JuceBigInteger(h ? BigInt(`0x${h}`) : 0n)\n }\n\n toHex(): string {\n return this.value.toString(16)\n }\n\n static fromUTF8MemoryBlock(input: string): JuceBigInteger {\n // Ports juce::BigInteger::loadFromMemoryBlock()\n const u = Buffer.from(input, 'utf8')\n const b = new JuceBigInteger()\n for (let i = u.length - 1; i >= 0; i--) {\n b.value = (b.value << 8n) | BigInt(u[i])\n }\n return b\n }\n\n isZero(): boolean {\n return this.value === 0n\n }\n\n divideBy(divisor: JuceBigInteger, remainder: JuceBigInteger): void {\n // Ports juce::BigInteger::divideBy()\n if (divisor.isZero()) {\n this.value = 0n\n return\n }\n const b = this.toJSBN()\n const d = divisor.toJSBN()\n const [q, r] = b.divideAndRemainder(d)\n this.value = JuceBigInteger.fromJSBN(q).value\n remainder.value = JuceBigInteger.fromJSBN(r).value\n }\n\n exponentModulo(exponent: JuceBigInteger, modulus: JuceBigInteger): void {\n // Ports juce::BigInteger::exponentModulo()\n const b = this.toJSBN()\n const e = exponent.toJSBN()\n const m = modulus.toJSBN()\n const em = b.modPow(e, m)\n this.value = JuceBigInteger.fromJSBN(em).value\n }\n}\n","import {\n CreateKeyFileCommentParams,\n CreateKeyFileContentLineParams\n} from '../types'\nimport { JuceBigInteger } from './JuceBigInteger'\nimport { JuceRSAKey } from './JuceRSAKey'\n\nconst XML_DECLARATION = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>'\n\nconst legalXmlCharRegex =\n // Ports juce::XmlOutputFunctions::LegalCharLookupTable\n /^[a-zA-Z0-9 .,;:\\-()_+=?!$#@[\\]/|*%~{}'\\\\]$/\n\nconst xmlAttributeCharProcessor = (char: string): string =>\n // Ports juce::XmlOutputFunctions::escapeIllegalXMLChars()\n char.length !== 1\n ? ''\n : legalXmlCharRegex.test(char)\n ? char\n : char === '&'\n ? '&amp;'\n : char === '\"'\n ? '&quot;'\n : char === '>'\n ? '&gt;'\n : char === '<'\n ? '&lt;'\n : `&#${char.charCodeAt(0)};`\n\nconst escapeAttr = (value: string): string =>\n // Ports juce::XmlOutputFunctions::escapeIllegalXMLChars()\n value.split('').map(xmlAttributeCharProcessor).join('')\n\nconst buildKeyElement = (attrs: Record<string, string>): string => {\n // Builds <key attr=\"val\" .../> without delegating to fast-xml-parser,\n // which unconditionally escapes single quotes in attribute values in v5\n // — breaking the JUCE port (single quote is a legal char in JUCE XML).\n const attrStr = Object.entries(attrs)\n .map(([k, v]) => `${k}=\"${escapeAttr(v)}\"`)\n .join(' ')\n return `<key ${attrStr}/>`\n}\n\nexport class JuceKeyFileUtils {\n static toString(date: Date): string {\n // Ports juce::Time::getCurrentTime().toString (true, true)\n // prettier-ignore\n const months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', \n 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]\n const day = date.getDate().toString()\n const month = months[date.getMonth()]\n const year = date.getFullYear()\n let hours = date.getHours()\n const minutes = date.getMinutes().toString().padStart(2, '0')\n const seconds = date.getSeconds().toString().padStart(2, '0')\n const ampm = hours >= 12 ? 'pm' : 'am'\n hours = hours % 12\n hours = hours ? hours : 12\n return `${day} ${month} ${year} ${hours}:${minutes}:${seconds}${ampm}`\n }\n\n static toHexStringMilliseconds(date: Date): string {\n // Ports juce::String::toHexString (juce::Time::getCurrentTime().toMilliseconds())\n return date.getTime().toString(16)\n }\n\n static createKeyFileContentLine(\n {\n appName,\n userEmail,\n userName,\n machineNumbers,\n machineNumbersAttributeName\n }: CreateKeyFileContentLineParams,\n date: string,\n expiryTime?: string\n ): string {\n // Ports juce::KeyFileUtils::createKeyFileContent\n // and juce::KeyFileUtils::encryptXML\n const attrs: Record<string, string> = {\n user: userName,\n email: userEmail,\n [machineNumbersAttributeName]: machineNumbers,\n app: appName,\n date\n }\n if (expiryTime) attrs.expiryTime = expiryTime\n return [XML_DECLARATION, buildKeyElement(attrs)].join(' ')\n }\n\n static createKeyFileComment(\n {\n appName,\n userEmail,\n userName,\n machineNumbers\n }: CreateKeyFileCommentParams,\n created: string,\n expiryTime?: string\n ): string {\n // Ports juce::KeyFileUtils::createKeyFileComment\n return (\n `Keyfile for ${appName}\\r\\n` +\n `${userName ? `User: ${userName}\\r\\n` : ''}` +\n `Email: ${userEmail}\\r\\n` +\n `Machine numbers: ${machineNumbers}\\r\\n` +\n `Created: ${created}` +\n (expiryTime ? `\\r\\nExpires: ${expiryTime}` : '')\n )\n }\n\n static encryptXMLLine(xmlLine: string, privateKey: JuceRSAKey): string {\n // Ports juce::KeyFileUtils::encryptXML\n const val = JuceBigInteger.fromUTF8MemoryBlock(xmlLine)\n privateKey.applyToValue(val)\n return val.toHex()\n }\n\n static createKeyFile(\n comment: string,\n xmlLine: string,\n rsaPrivateKey: JuceRSAKey\n ): string {\n // Ports juce::KeyFileUtils::createKeyFile\n let asHex = '#' + this.encryptXMLLine(xmlLine, rsaPrivateKey)\n\n const lines: string[] = []\n lines.push(comment)\n lines.push('')\n\n const charsPerLine = 70\n while (asHex.length > 0) {\n lines.push(asHex.substring(0, charsPerLine))\n asHex = asHex.substring(charsPerLine)\n }\n\n lines.push('')\n\n return lines.join('\\r\\n')\n }\n}\n","import { JuceBigInteger } from './JuceBigInteger'\n\nexport class JuceRSAKey {\n protected part1: JuceBigInteger\n protected part2: JuceBigInteger\n constructor(public s: string) {\n // Ports juce::RSAKey::RSAKey()\n if (s.includes(',')) {\n const [p1, p2] = s.split(',').map(p => JuceBigInteger.fromHex(p))\n this.part1 = p1\n this.part2 = p2\n } else {\n this.part1 = new JuceBigInteger()\n this.part2 = new JuceBigInteger()\n }\n }\n applyToValue(val: JuceBigInteger): void {\n // Ports juce::RSAKey::applyToValue()\n if (this.part1.isZero() || this.part2.isZero() || val.value <= 0n) {\n return\n }\n\n const result = new JuceBigInteger()\n\n while (!val.isZero()) {\n result.value *= this.part2.value\n\n const remainder = new JuceBigInteger()\n val.divideBy(this.part2, remainder)\n\n remainder.exponentModulo(this.part1, this.part2)\n\n result.value += remainder.value\n }\n\n val.value = result.value\n }\n}\n","import { GenerateExpiringKeyFileParams, GenerateKeyFileParams } from '../types'\nimport { JuceKeyFileUtils } from './JuceKeyFileUtils'\nimport { JuceRSAKey } from './JuceRSAKey'\n\nexport class JuceKeyGeneration {\n static generateKeyFile(\n params: GenerateKeyFileParams,\n date: Date = new Date()\n ) {\n const xml = JuceKeyFileUtils.createKeyFileContentLine(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers,\n machineNumbersAttributeName: 'mach'\n },\n JuceKeyFileUtils.toHexStringMilliseconds(date)\n )\n const comment = JuceKeyFileUtils.createKeyFileComment(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers\n },\n JuceKeyFileUtils.toString(date)\n )\n return JuceKeyFileUtils.createKeyFile(\n comment,\n xml,\n new JuceRSAKey(params.privateKey)\n )\n }\n\n static generateExpiringKeyFile(\n params: GenerateExpiringKeyFileParams,\n date: Date = new Date()\n ) {\n const xml = JuceKeyFileUtils.createKeyFileContentLine(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers,\n machineNumbersAttributeName: 'expiring_mach'\n },\n JuceKeyFileUtils.toHexStringMilliseconds(date),\n JuceKeyFileUtils.toHexStringMilliseconds(params.expiryTime)\n )\n const comment = JuceKeyFileUtils.createKeyFileComment(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers\n },\n JuceKeyFileUtils.toString(date),\n JuceKeyFileUtils.toString(params.expiryTime)\n )\n return JuceKeyFileUtils.createKeyFile(\n comment,\n xml,\n new JuceRSAKey(params.privateKey)\n )\n }\n}\n","import { z } from 'zod'\n\nimport { JuceBigInteger } from './juce/JuceBigInteger'\n\nexport const createKeyFileCommentParamsSchema = z.object({\n appName: z.string().min(1),\n userEmail: z.string().min(1),\n userName: z.string().min(1),\n machineNumbers: z.string().min(1)\n})\nexport type CreateKeyFileCommentParams = z.infer<\n typeof createKeyFileCommentParamsSchema\n>\n\nexport const machineNumbersAttributeNameSchema = z.enum([\n 'mach',\n 'expiring_mach'\n])\nexport type MachineNumbersAttributeName = z.infer<\n typeof machineNumbersAttributeNameSchema\n>\n\nexport const createKeyFileContentLineParamsSchema =\n createKeyFileCommentParamsSchema.extend({\n machineNumbersAttributeName: machineNumbersAttributeNameSchema\n })\nexport type CreateKeyFileContentLineParams = z.infer<\n typeof createKeyFileContentLineParamsSchema\n>\n\nexport const rsaKeyComponentsSchema = z.stringFormat(\n // Ports juce::RSAKey::RSAKey() and juce::RSAKey::applyToValue()\n 'RSAKeyComponents',\n x =>\n x.includes(',') &&\n x.split(',').every(p => !JuceBigInteger.fromHex(p).isZero())\n)\nexport type RSAKeyComponents = z.infer<typeof rsaKeyComponentsSchema>\n\nexport const generateKeyFileParamsSchema =\n createKeyFileCommentParamsSchema.extend({\n privateKey: rsaKeyComponentsSchema\n })\nexport type GenerateKeyFileParams = z.infer<typeof generateKeyFileParamsSchema>\n\nexport const generateExpiringKeyFileParamsSchema =\n generateKeyFileParamsSchema.extend({\n expiryTime: z.date().min(new Date('1970-01-01T00:00:00.001Z'), {\n error: 'Expiry time must be after 1970-01-01T00:00:00.000Z'\n })\n })\nexport type GenerateExpiringKeyFileParams = z.infer<\n typeof generateExpiringKeyFileParamsSchema\n>\n","import { JuceKeyGeneration } from './juce/JuceKeyGeneration'\nimport { GenerateKeyFileParams, generateKeyFileParamsSchema } from './types'\n\nexport const generateKeyFile = (\n params: GenerateKeyFileParams,\n date: Date = new Date()\n) => {\n const paramsParse = generateKeyFileParamsSchema.parse(params)\n return JuceKeyGeneration.generateKeyFile(paramsParse, date)\n}\n","import { JuceKeyGeneration } from './juce/JuceKeyGeneration'\nimport {\n GenerateExpiringKeyFileParams,\n generateExpiringKeyFileParamsSchema\n} from './types'\n\nexport const generateExpiringKeyFile = (\n params: GenerateExpiringKeyFileParams,\n date: Date = new Date()\n) => {\n const paramsParse = generateExpiringKeyFileParamsSchema.parse(params)\n return JuceKeyGeneration.generateExpiringKeyFile(paramsParse, date)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAmC;AAE5B,IAAM,iBAAN,MAAM,gBAAe;AAAA,EACxB,YAAmB,QAAgB,IAAI;AAApB;AAAA,EAAqB;AAAA,E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AEpC;AAAA,EACA,OACI,EAAE,SAAS,GAAG,KACd,EAAE,MAAM,GAAG,EAAE,MAAM,OAAK,CAAC,eAAe,QAAQ,CAAC,EAAE,OAAO,CAAC;AACnE;AAGO,IAAM,8BACT,iCAAiC,OAAO;AAAA,EACpC,YAAY;AAChB,CAAC;AAGE,IAAM,sCACT,4BAA4B,OAAO;AAAA,EAC/B,YAAY,aAAE,KAAK,EAAE,IAAI,oBAAI,KAAK,0BAA0B,GAAG;AAAA,IAC3D,OAAO;AAAA,EACX,CAAC;AACL,CAAC;;;AC/CE,IAAM,kBAAkB,CAC3B,QACA,OAAa,oBAAI,KAAK,MACrB;AACD,QAAM,cAAc,4BAA4B,MAAM,MAAM;AAC5D,SAAO,kBAAkB,gBAAgB,aAAa,IAAI;AAC9D;;;ACHO,IAAM,0BAA0B,CACnC,QACA,OAAa,oBAAI,KAAK,MACrB;AACD,QAAM,cAAc,oCAAoC,MAAM,MAAM;AACpE,SAAO,kBAAkB,wBAAwB,aAAa,IAAI;AACtE;","names":["JSBN"]}
package/dist/index.d.cts CHANGED
@@ -1,51 +1,22 @@
1
1
  import { z } from 'zod';
2
2
 
3
- declare const generateKeyFileParamsValidator: z.ZodObject<z.objectUtil.extendShape<{
3
+ declare const generateKeyFileParamsSchema: z.ZodObject<{
4
4
  appName: z.ZodString;
5
5
  userEmail: z.ZodString;
6
6
  userName: z.ZodString;
7
7
  machineNumbers: z.ZodString;
8
- }, {
9
- privateKey: z.ZodEffects<z.ZodString, string, string>;
10
- }>, "strip", z.ZodTypeAny, {
11
- appName: string;
12
- userEmail: string;
13
- userName: string;
14
- machineNumbers: string;
15
- privateKey: string;
16
- }, {
17
- appName: string;
18
- userEmail: string;
19
- userName: string;
20
- machineNumbers: string;
21
- privateKey: string;
22
- }>;
23
- type GenerateKeyFileParams = z.infer<typeof generateKeyFileParamsValidator>;
24
- declare const generateExpiringKeyFileParamsValidator: z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<{
8
+ privateKey: z.ZodCustomStringFormat<"RSAKeyComponents">;
9
+ }, z.core.$strip>;
10
+ type GenerateKeyFileParams = z.infer<typeof generateKeyFileParamsSchema>;
11
+ declare const generateExpiringKeyFileParamsSchema: z.ZodObject<{
25
12
  appName: z.ZodString;
26
13
  userEmail: z.ZodString;
27
14
  userName: z.ZodString;
28
15
  machineNumbers: z.ZodString;
29
- }, {
30
- privateKey: z.ZodEffects<z.ZodString, string, string>;
31
- }>, {
16
+ privateKey: z.ZodCustomStringFormat<"RSAKeyComponents">;
32
17
  expiryTime: z.ZodDate;
33
- }>, "strip", z.ZodTypeAny, {
34
- appName: string;
35
- userEmail: string;
36
- userName: string;
37
- machineNumbers: string;
38
- privateKey: string;
39
- expiryTime: Date;
40
- }, {
41
- appName: string;
42
- userEmail: string;
43
- userName: string;
44
- machineNumbers: string;
45
- privateKey: string;
46
- expiryTime: Date;
47
- }>;
48
- type GenerateExpiringKeyFileParams = z.infer<typeof generateExpiringKeyFileParamsValidator>;
18
+ }, z.core.$strip>;
19
+ type GenerateExpiringKeyFileParams = z.infer<typeof generateExpiringKeyFileParamsSchema>;
49
20
 
50
21
  declare const generateKeyFile: (params: GenerateKeyFileParams, date?: Date) => string;
51
22
 
package/dist/index.d.ts CHANGED
@@ -1,51 +1,22 @@
1
1
  import { z } from 'zod';
2
2
 
3
- declare const generateKeyFileParamsValidator: z.ZodObject<z.objectUtil.extendShape<{
3
+ declare const generateKeyFileParamsSchema: z.ZodObject<{
4
4
  appName: z.ZodString;
5
5
  userEmail: z.ZodString;
6
6
  userName: z.ZodString;
7
7
  machineNumbers: z.ZodString;
8
- }, {
9
- privateKey: z.ZodEffects<z.ZodString, string, string>;
10
- }>, "strip", z.ZodTypeAny, {
11
- appName: string;
12
- userEmail: string;
13
- userName: string;
14
- machineNumbers: string;
15
- privateKey: string;
16
- }, {
17
- appName: string;
18
- userEmail: string;
19
- userName: string;
20
- machineNumbers: string;
21
- privateKey: string;
22
- }>;
23
- type GenerateKeyFileParams = z.infer<typeof generateKeyFileParamsValidator>;
24
- declare const generateExpiringKeyFileParamsValidator: z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<{
8
+ privateKey: z.ZodCustomStringFormat<"RSAKeyComponents">;
9
+ }, z.core.$strip>;
10
+ type GenerateKeyFileParams = z.infer<typeof generateKeyFileParamsSchema>;
11
+ declare const generateExpiringKeyFileParamsSchema: z.ZodObject<{
25
12
  appName: z.ZodString;
26
13
  userEmail: z.ZodString;
27
14
  userName: z.ZodString;
28
15
  machineNumbers: z.ZodString;
29
- }, {
30
- privateKey: z.ZodEffects<z.ZodString, string, string>;
31
- }>, {
16
+ privateKey: z.ZodCustomStringFormat<"RSAKeyComponents">;
32
17
  expiryTime: z.ZodDate;
33
- }>, "strip", z.ZodTypeAny, {
34
- appName: string;
35
- userEmail: string;
36
- userName: string;
37
- machineNumbers: string;
38
- privateKey: string;
39
- expiryTime: Date;
40
- }, {
41
- appName: string;
42
- userEmail: string;
43
- userName: string;
44
- machineNumbers: string;
45
- privateKey: string;
46
- expiryTime: Date;
47
- }>;
48
- type GenerateExpiringKeyFileParams = z.infer<typeof generateExpiringKeyFileParamsValidator>;
18
+ }, z.core.$strip>;
19
+ type GenerateExpiringKeyFileParams = z.infer<typeof generateExpiringKeyFileParamsSchema>;
49
20
 
50
21
  declare const generateKeyFile: (params: GenerateKeyFileParams, date?: Date) => string;
51
22
 
package/dist/index.js CHANGED
@@ -1,6 +1,3 @@
1
- // src/juce/JuceKeyFileUtils.ts
2
- import { XMLBuilder } from "fast-xml-parser";
3
-
4
1
  // src/juce/JuceBigInteger.ts
5
2
  import { BigInteger as JSBN } from "jsbn";
6
3
  var JuceBigInteger = class _JuceBigInteger {
@@ -61,17 +58,14 @@ var xmlAttributeCharProcessor = (char) => (
61
58
  // Ports juce::XmlOutputFunctions::escapeIllegalXMLChars()
62
59
  char.length !== 1 ? "" : legalXmlCharRegex.test(char) ? char : char === "&" ? "&amp;" : char === '"' ? "&quot;" : char === ">" ? "&gt;" : char === "<" ? "&lt;" : `&#${char.charCodeAt(0)};`
63
60
  );
64
- var xmlAttributeValueProcessor = (value) => (
61
+ var escapeAttr = (value) => (
65
62
  // Ports juce::XmlOutputFunctions::escapeIllegalXMLChars()
66
- typeof value !== "string" ? "" : value.split("").map(xmlAttributeCharProcessor).join("")
63
+ value.split("").map(xmlAttributeCharProcessor).join("")
67
64
  );
68
- var xmlBuilder = new XMLBuilder({
69
- ignoreAttributes: false,
70
- suppressEmptyNode: true,
71
- // processEntities is disabled since it doesn't port to juce as is
72
- processEntities: false,
73
- attributeValueProcessor: (_, value) => xmlAttributeValueProcessor(value)
74
- });
65
+ var buildKeyElement = (attrs) => {
66
+ const attrStr = Object.entries(attrs).map(([k, v]) => `${k}="${escapeAttr(v)}"`).join(" ");
67
+ return `<key ${attrStr}/>`;
68
+ };
75
69
  var JuceKeyFileUtils = class {
76
70
  static toString(date) {
77
71
  const months = [
@@ -109,17 +103,15 @@ var JuceKeyFileUtils = class {
109
103
  machineNumbers,
110
104
  machineNumbersAttributeName
111
105
  }, date, expiryTime) {
112
- const xml = {
113
- key: {
114
- "@_user": userName,
115
- "@_email": userEmail,
116
- [`@_${machineNumbersAttributeName}`]: machineNumbers,
117
- "@_app": appName,
118
- "@_date": date,
119
- ...expiryTime ? { "@_expiryTime": expiryTime } : {}
120
- }
106
+ const attrs = {
107
+ user: userName,
108
+ email: userEmail,
109
+ [machineNumbersAttributeName]: machineNumbers,
110
+ app: appName,
111
+ date
121
112
  };
122
- return [XML_DECLARATION, xmlBuilder.build(xml).trim()].join(" ");
113
+ if (expiryTime) attrs.expiryTime = expiryTime;
114
+ return [XML_DECLARATION, buildKeyElement(attrs)].join(" ");
123
115
  }
124
116
  static createKeyFileComment({
125
117
  appName,
@@ -243,41 +235,42 @@ var JuceKeyGeneration = class {
243
235
 
244
236
  // src/types.ts
245
237
  import { z } from "zod";
246
- var createKeyFileCommentParamsValidator = z.object({
238
+ var createKeyFileCommentParamsSchema = z.object({
247
239
  appName: z.string().min(1),
248
- userEmail: z.string().min(1).email(),
240
+ userEmail: z.string().min(1),
249
241
  userName: z.string().min(1),
250
242
  machineNumbers: z.string().min(1)
251
243
  });
252
- var machineNumbersAttributeNameValidator = z.enum([
244
+ var machineNumbersAttributeNameSchema = z.enum([
253
245
  "mach",
254
246
  "expiring_mach"
255
247
  ]);
256
- var createKeyFileContentLineParamsValidator = createKeyFileCommentParamsValidator.extend({
257
- machineNumbersAttributeName: machineNumbersAttributeNameValidator
248
+ var createKeyFileContentLineParamsSchema = createKeyFileCommentParamsSchema.extend({
249
+ machineNumbersAttributeName: machineNumbersAttributeNameSchema
258
250
  });
259
- var rsaKeyComponentsValidator = z.string().refine(
251
+ var rsaKeyComponentsSchema = z.stringFormat(
260
252
  // Ports juce::RSAKey::RSAKey() and juce::RSAKey::applyToValue()
253
+ "RSAKeyComponents",
261
254
  (x) => x.includes(",") && x.split(",").every((p) => !JuceBigInteger.fromHex(p).isZero())
262
255
  );
263
- var generateKeyFileParamsValidator = createKeyFileCommentParamsValidator.extend({
264
- privateKey: rsaKeyComponentsValidator
256
+ var generateKeyFileParamsSchema = createKeyFileCommentParamsSchema.extend({
257
+ privateKey: rsaKeyComponentsSchema
265
258
  });
266
- var generateExpiringKeyFileParamsValidator = generateKeyFileParamsValidator.extend({
259
+ var generateExpiringKeyFileParamsSchema = generateKeyFileParamsSchema.extend({
267
260
  expiryTime: z.date().min(/* @__PURE__ */ new Date("1970-01-01T00:00:00.001Z"), {
268
- message: "Expiry time must be after 1970-01-01T00:00:00.000Z"
261
+ error: "Expiry time must be after 1970-01-01T00:00:00.000Z"
269
262
  })
270
263
  });
271
264
 
272
265
  // src/generateKeyFile.ts
273
266
  var generateKeyFile = (params, date = /* @__PURE__ */ new Date()) => {
274
- const paramsParse = generateKeyFileParamsValidator.parse(params);
267
+ const paramsParse = generateKeyFileParamsSchema.parse(params);
275
268
  return JuceKeyGeneration.generateKeyFile(paramsParse, date);
276
269
  };
277
270
 
278
271
  // src/generateExpiringKeyFile.ts
279
272
  var generateExpiringKeyFile = (params, date = /* @__PURE__ */ new Date()) => {
280
- const paramsParse = generateExpiringKeyFileParamsValidator.parse(params);
273
+ const paramsParse = generateExpiringKeyFileParamsSchema.parse(params);
281
274
  return JuceKeyGeneration.generateExpiringKeyFile(paramsParse, date);
282
275
  };
283
276
  export {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/juce/JuceKeyFileUtils.ts","../src/juce/JuceBigInteger.ts","../src/juce/JuceRSAKey.ts","../src/juce/JuceKeyGeneration.ts","../src/types.ts","../src/generateKeyFile.ts","../src/generateExpiringKeyFile.ts"],"sourcesContent":["import { XMLBuilder } from 'fast-xml-parser'\nimport {\n CreateKeyFileCommentParams,\n CreateKeyFileContentLineParams\n} from 'src/types'\n\nimport { JuceBigInteger } from './JuceBigInteger'\nimport { JuceRSAKey } from './JuceRSAKey'\n\nconst XML_DECLARATION = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>'\n\nconst legalXmlCharRegex =\n // Ports juce::XmlOutputFunctions::LegalCharLookupTable\n /^[a-zA-Z0-9 .,;:\\-()_+=?!$#@[\\]/|*%~{}'\\\\]$/\n\nconst xmlAttributeCharProcessor = (char: string): string =>\n // Ports juce::XmlOutputFunctions::escapeIllegalXMLChars()\n char.length !== 1\n ? ''\n : legalXmlCharRegex.test(char)\n ? char\n : char === '&'\n ? '&amp;'\n : char === '\"'\n ? '&quot;'\n : char === '>'\n ? '&gt;'\n : char === '<'\n ? '&lt;'\n : `&#${char.charCodeAt(0)};`\n\nconst xmlAttributeValueProcessor = (value: unknown): string =>\n // Ports juce::XmlOutputFunctions::escapeIllegalXMLChars()\n typeof value !== 'string'\n ? ''\n : value.split('').map(xmlAttributeCharProcessor).join('')\n\nconst xmlBuilder = new XMLBuilder({\n ignoreAttributes: false,\n suppressEmptyNode: true,\n // processEntities is disabled since it doesn't port to juce as is\n processEntities: false,\n attributeValueProcessor: (_, value) => xmlAttributeValueProcessor(value)\n})\n\nexport class JuceKeyFileUtils {\n static toString(date: Date): string {\n // Ports juce::Time::getCurrentTime().toString (true, true)\n // prettier-ignore\n const months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', \n 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]\n const day = date.getDate().toString()\n const month = months[date.getMonth()]\n const year = date.getFullYear()\n let hours = date.getHours()\n const minutes = date.getMinutes().toString().padStart(2, '0')\n const seconds = date.getSeconds().toString().padStart(2, '0')\n const ampm = hours >= 12 ? 'pm' : 'am'\n hours = hours % 12\n hours = hours ? hours : 12\n return `${day} ${month} ${year} ${hours}:${minutes}:${seconds}${ampm}`\n }\n\n static toHexStringMilliseconds(date: Date): string {\n // Ports juce::String::toHexString (juce::Time::getCurrentTime().toMilliseconds())\n return date.getTime().toString(16)\n }\n\n static createKeyFileContentLine(\n {\n appName,\n userEmail,\n userName,\n machineNumbers,\n machineNumbersAttributeName\n }: CreateKeyFileContentLineParams,\n date: string,\n expiryTime?: string\n ): string {\n // Ports juce::KeyFileUtils::createKeyFileContent\n // and juce::KeyFileUtils::encryptXML\n const xml = {\n key: {\n '@_user': userName,\n '@_email': userEmail,\n [`@_${machineNumbersAttributeName}`]: machineNumbers,\n '@_app': appName,\n '@_date': date,\n ...(expiryTime ? { '@_expiryTime': expiryTime } : {})\n }\n }\n return [XML_DECLARATION, xmlBuilder.build(xml).trim()].join(' ')\n }\n\n static createKeyFileComment(\n {\n appName,\n userEmail,\n userName,\n machineNumbers\n }: CreateKeyFileCommentParams,\n created: string,\n expiryTime?: string\n ): string {\n // Ports juce::KeyFileUtils::createKeyFileComment\n return (\n `Keyfile for ${appName}\\r\\n` +\n `${userName ? `User: ${userName}\\r\\n` : ''}` +\n `Email: ${userEmail}\\r\\n` +\n `Machine numbers: ${machineNumbers}\\r\\n` +\n `Created: ${created}` +\n (expiryTime ? `\\r\\nExpires: ${expiryTime}` : '')\n )\n }\n\n static encryptXMLLine(xmlLine: string, privateKey: JuceRSAKey): string {\n // Ports juce::KeyFileUtils::encryptXML\n const val = JuceBigInteger.fromUTF8MemoryBlock(xmlLine)\n privateKey.applyToValue(val)\n return val.toHex()\n }\n\n static createKeyFile(\n comment: string,\n xmlLine: string,\n rsaPrivateKey: JuceRSAKey\n ): string {\n // Ports juce::KeyFileUtils::createKeyFile\n let asHex = '#' + this.encryptXMLLine(xmlLine, rsaPrivateKey)\n\n const lines: string[] = []\n lines.push(comment)\n lines.push('')\n\n const charsPerLine = 70\n while (asHex.length > 0) {\n lines.push(asHex.substring(0, charsPerLine))\n asHex = asHex.substring(charsPerLine)\n }\n\n lines.push('')\n\n return lines.join('\\r\\n')\n }\n}\n","import { BigInteger as JSBN } from 'jsbn'\n\nexport class JuceBigInteger {\n constructor(public value: bigint = 0n) {}\n\n static fromJSBN(b: JSBN): JuceBigInteger {\n return JuceBigInteger.fromHex(b.toString(16))\n }\n\n toJSBN(): JSBN {\n return new JSBN(this.toHex(), 16)\n }\n\n static fromHex(hex: string): JuceBigInteger {\n const h = hex.trim()\n return new JuceBigInteger(h ? BigInt(`0x${h}`) : 0n)\n }\n\n toHex(): string {\n return this.value.toString(16)\n }\n\n static fromUTF8MemoryBlock(input: string): JuceBigInteger {\n // Ports juce::BigInteger::loadFromMemoryBlock()\n const u = Buffer.from(input, 'utf8')\n const b = new JuceBigInteger()\n for (let i = u.length - 1; i >= 0; i--) {\n b.value = (b.value << 8n) | BigInt(u[i])\n }\n return b\n }\n\n isZero(): boolean {\n return this.value === 0n\n }\n\n divideBy(divisor: JuceBigInteger, remainder: JuceBigInteger): void {\n // Ports juce::BigInteger::divideBy()\n if (divisor.isZero()) {\n this.value = 0n\n return\n }\n const b = this.toJSBN()\n const d = divisor.toJSBN()\n const [q, r] = b.divideAndRemainder(d)\n this.value = JuceBigInteger.fromJSBN(q).value\n remainder.value = JuceBigInteger.fromJSBN(r).value\n }\n\n exponentModulo(exponent: JuceBigInteger, modulus: JuceBigInteger): void {\n // Ports juce::BigInteger::exponentModulo()\n const b = this.toJSBN()\n const e = exponent.toJSBN()\n const m = modulus.toJSBN()\n const em = b.modPow(e, m)\n this.value = JuceBigInteger.fromJSBN(em).value\n }\n}\n","import { JuceBigInteger } from './JuceBigInteger'\n\nexport class JuceRSAKey {\n protected part1: JuceBigInteger\n protected part2: JuceBigInteger\n constructor(public s: string) {\n // Ports juce::RSAKey::RSAKey()\n if (s.includes(',')) {\n const [p1, p2] = s.split(',').map(p => JuceBigInteger.fromHex(p))\n this.part1 = p1\n this.part2 = p2\n } else {\n this.part1 = new JuceBigInteger()\n this.part2 = new JuceBigInteger()\n }\n }\n applyToValue(val: JuceBigInteger): void {\n // Ports juce::RSAKey::applyToValue()\n if (this.part1.isZero() || this.part2.isZero() || val.value <= 0n) {\n return\n }\n\n const result = new JuceBigInteger()\n\n while (!val.isZero()) {\n result.value *= this.part2.value\n\n const remainder = new JuceBigInteger()\n val.divideBy(this.part2, remainder)\n\n remainder.exponentModulo(this.part1, this.part2)\n\n result.value += remainder.value\n }\n\n val.value = result.value\n }\n}\n","import { GenerateExpiringKeyFileParams, GenerateKeyFileParams } from 'src/types'\n\nimport { JuceKeyFileUtils } from './JuceKeyFileUtils'\nimport { JuceRSAKey } from './JuceRSAKey'\n\nexport class JuceKeyGeneration {\n static generateKeyFile(\n params: GenerateKeyFileParams,\n date: Date = new Date()\n ) {\n const xml = JuceKeyFileUtils.createKeyFileContentLine(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers,\n machineNumbersAttributeName: 'mach'\n },\n JuceKeyFileUtils.toHexStringMilliseconds(date)\n )\n const comment = JuceKeyFileUtils.createKeyFileComment(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers\n },\n JuceKeyFileUtils.toString(date)\n )\n return JuceKeyFileUtils.createKeyFile(\n comment,\n xml,\n new JuceRSAKey(params.privateKey)\n )\n }\n\n static generateExpiringKeyFile(\n params: GenerateExpiringKeyFileParams,\n date: Date = new Date()\n ) {\n const xml = JuceKeyFileUtils.createKeyFileContentLine(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers,\n machineNumbersAttributeName: 'expiring_mach'\n },\n JuceKeyFileUtils.toHexStringMilliseconds(date),\n JuceKeyFileUtils.toHexStringMilliseconds(params.expiryTime)\n )\n const comment = JuceKeyFileUtils.createKeyFileComment(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers\n },\n JuceKeyFileUtils.toString(date),\n JuceKeyFileUtils.toString(params.expiryTime)\n )\n return JuceKeyFileUtils.createKeyFile(\n comment,\n xml,\n new JuceRSAKey(params.privateKey)\n )\n }\n}\n","import { z } from 'zod'\n\nimport { JuceBigInteger } from './juce/JuceBigInteger'\n\nexport const createKeyFileCommentParamsValidator = z.object({\n appName: z.string().min(1),\n userEmail: z.string().min(1).email(),\n userName: z.string().min(1),\n machineNumbers: z.string().min(1)\n})\nexport type CreateKeyFileCommentParams = z.infer<\n typeof createKeyFileCommentParamsValidator\n>\n\nexport const machineNumbersAttributeNameValidator = z.enum([\n 'mach',\n 'expiring_mach'\n])\nexport type MachineNumbersAttributeName = z.infer<\n typeof machineNumbersAttributeNameValidator\n>\n\nexport const createKeyFileContentLineParamsValidator =\n createKeyFileCommentParamsValidator.extend({\n machineNumbersAttributeName: machineNumbersAttributeNameValidator\n })\nexport type CreateKeyFileContentLineParams = z.infer<\n typeof createKeyFileContentLineParamsValidator\n>\n\nexport const rsaKeyComponentsValidator = z.string().refine(\n // Ports juce::RSAKey::RSAKey() and juce::RSAKey::applyToValue()\n x =>\n x.includes(',') &&\n x.split(',').every(p => !JuceBigInteger.fromHex(p).isZero())\n)\nexport type RSAKeyComponents = z.infer<typeof rsaKeyComponentsValidator>\n\nexport const generateKeyFileParamsValidator =\n createKeyFileCommentParamsValidator.extend({\n privateKey: rsaKeyComponentsValidator\n })\nexport type GenerateKeyFileParams = z.infer<\n typeof generateKeyFileParamsValidator\n>\n\nexport const generateExpiringKeyFileParamsValidator =\n generateKeyFileParamsValidator.extend({\n expiryTime: z.date().min(new Date('1970-01-01T00:00:00.001Z'), {\n message: 'Expiry time must be after 1970-01-01T00:00:00.000Z'\n })\n })\nexport type GenerateExpiringKeyFileParams = z.infer<\n typeof generateExpiringKeyFileParamsValidator\n>\n","import { JuceKeyGeneration } from './juce/JuceKeyGeneration'\nimport { GenerateKeyFileParams, generateKeyFileParamsValidator } from './types'\n\nexport const generateKeyFile = (\n params: GenerateKeyFileParams,\n date: Date = new Date()\n) => {\n const paramsParse = generateKeyFileParamsValidator.parse(params)\n return JuceKeyGeneration.generateKeyFile(paramsParse, date)\n}\n","import { JuceKeyGeneration } from './juce/JuceKeyGeneration'\nimport {\n GenerateExpiringKeyFileParams,\n generateExpiringKeyFileParamsValidator\n} from './types'\n\nexport const generateExpiringKeyFile = (\n params: GenerateExpiringKeyFileParams,\n date: Date = new Date()\n) => {\n const paramsParse = generateExpiringKeyFileParamsValidator.parse(params)\n return JuceKeyGeneration.generateExpiringKeyFile(paramsParse, date)\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;;;ACA3B,SAAS,cAAc,YAAY;AAE5B,IAAM,iBAAN,MAAM,gBAAe;AAAA,EACxB,YAAmB,QAAgB,IAAI;AAApB;AAAA,EAAqB;AAAA,EAExC,OAAO,SAAS,GAAyB;AACrC,WAAO,gBAAe,QAAQ,EAAE,SAAS,EAAE,CAAC;AAAA,EAChD;AAAA,EAEA,SAAe;AACX,WAAO,IAAI,KAAK,KAAK,MAAM,GAAG,EAAE;AAAA,EACpC;AAAA,EAEA,OAAO,QAAQ,KAA6B;AACxC,UAAM,IAAI,IAAI,KAAK;AACnB,WAAO,IAAI,gBAAe,IAAI,OAAO,KAAK,CAAC,EAAE,IAAI,EAAE;AAAA,EACvD;AAAA,EAEA,QAAgB;AACZ,WAAO,KAAK,MAAM,SAAS,EAAE;AAAA,E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G;AAAA,IAC3D,SAAS;AAAA,EACb,CAAC;AACL,CAAC;;;AChDE,IAAM,kBAAkB,CAC3B,QACA,OAAa,oBAAI,KAAK,MACrB;AACD,QAAM,cAAc,+BAA+B,MAAM,MAAM;AAC/D,SAAO,kBAAkB,gBAAgB,aAAa,IAAI;AAC9D;;;ACHO,IAAM,0BAA0B,CACnC,QACA,OAAa,oBAAI,KAAK,MACrB;AACD,QAAM,cAAc,uCAAuC,MAAM,MAAM;AACvE,SAAO,kBAAkB,wBAAwB,aAAa,IAAI;AACtE;","names":[]}
1
+ {"version":3,"sources":["../src/juce/JuceBigInteger.ts","../src/juce/JuceKeyFileUtils.ts","../src/juce/JuceRSAKey.ts","../src/juce/JuceKeyGeneration.ts","../src/types.ts","../src/generateKeyFile.ts","../src/generateExpiringKeyFile.ts"],"sourcesContent":["import { BigInteger as JSBN } from 'jsbn'\n\nexport class JuceBigInteger {\n constructor(public value: bigint = 0n) {}\n\n static fromJSBN(b: JSBN): JuceBigInteger {\n return JuceBigInteger.fromHex(b.toString(16))\n }\n\n toJSBN(): JSBN {\n return new JSBN(this.toHex(), 16)\n }\n\n static fromHex(hex: string): JuceBigInteger {\n const h = hex.trim()\n return new JuceBigInteger(h ? BigInt(`0x${h}`) : 0n)\n }\n\n toHex(): string {\n return this.value.toString(16)\n }\n\n static fromUTF8MemoryBlock(input: string): JuceBigInteger {\n // Ports juce::BigInteger::loadFromMemoryBlock()\n const u = Buffer.from(input, 'utf8')\n const b = new JuceBigInteger()\n for (let i = u.length - 1; i >= 0; i--) {\n b.value = (b.value << 8n) | BigInt(u[i])\n }\n return b\n }\n\n isZero(): boolean {\n return this.value === 0n\n }\n\n divideBy(divisor: JuceBigInteger, remainder: JuceBigInteger): void {\n // Ports juce::BigInteger::divideBy()\n if (divisor.isZero()) {\n this.value = 0n\n return\n }\n const b = this.toJSBN()\n const d = divisor.toJSBN()\n const [q, r] = b.divideAndRemainder(d)\n this.value = JuceBigInteger.fromJSBN(q).value\n remainder.value = JuceBigInteger.fromJSBN(r).value\n }\n\n exponentModulo(exponent: JuceBigInteger, modulus: JuceBigInteger): void {\n // Ports juce::BigInteger::exponentModulo()\n const b = this.toJSBN()\n const e = exponent.toJSBN()\n const m = modulus.toJSBN()\n const em = b.modPow(e, m)\n this.value = JuceBigInteger.fromJSBN(em).value\n }\n}\n","import {\n CreateKeyFileCommentParams,\n CreateKeyFileContentLineParams\n} from '../types'\nimport { JuceBigInteger } from './JuceBigInteger'\nimport { JuceRSAKey } from './JuceRSAKey'\n\nconst XML_DECLARATION = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>'\n\nconst legalXmlCharRegex =\n // Ports juce::XmlOutputFunctions::LegalCharLookupTable\n /^[a-zA-Z0-9 .,;:\\-()_+=?!$#@[\\]/|*%~{}'\\\\]$/\n\nconst xmlAttributeCharProcessor = (char: string): string =>\n // Ports juce::XmlOutputFunctions::escapeIllegalXMLChars()\n char.length !== 1\n ? ''\n : legalXmlCharRegex.test(char)\n ? char\n : char === '&'\n ? '&amp;'\n : char === '\"'\n ? '&quot;'\n : char === '>'\n ? '&gt;'\n : char === '<'\n ? '&lt;'\n : `&#${char.charCodeAt(0)};`\n\nconst escapeAttr = (value: string): string =>\n // Ports juce::XmlOutputFunctions::escapeIllegalXMLChars()\n value.split('').map(xmlAttributeCharProcessor).join('')\n\nconst buildKeyElement = (attrs: Record<string, string>): string => {\n // Builds <key attr=\"val\" .../> without delegating to fast-xml-parser,\n // which unconditionally escapes single quotes in attribute values in v5\n // — breaking the JUCE port (single quote is a legal char in JUCE XML).\n const attrStr = Object.entries(attrs)\n .map(([k, v]) => `${k}=\"${escapeAttr(v)}\"`)\n .join(' ')\n return `<key ${attrStr}/>`\n}\n\nexport class JuceKeyFileUtils {\n static toString(date: Date): string {\n // Ports juce::Time::getCurrentTime().toString (true, true)\n // prettier-ignore\n const months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', \n 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]\n const day = date.getDate().toString()\n const month = months[date.getMonth()]\n const year = date.getFullYear()\n let hours = date.getHours()\n const minutes = date.getMinutes().toString().padStart(2, '0')\n const seconds = date.getSeconds().toString().padStart(2, '0')\n const ampm = hours >= 12 ? 'pm' : 'am'\n hours = hours % 12\n hours = hours ? hours : 12\n return `${day} ${month} ${year} ${hours}:${minutes}:${seconds}${ampm}`\n }\n\n static toHexStringMilliseconds(date: Date): string {\n // Ports juce::String::toHexString (juce::Time::getCurrentTime().toMilliseconds())\n return date.getTime().toString(16)\n }\n\n static createKeyFileContentLine(\n {\n appName,\n userEmail,\n userName,\n machineNumbers,\n machineNumbersAttributeName\n }: CreateKeyFileContentLineParams,\n date: string,\n expiryTime?: string\n ): string {\n // Ports juce::KeyFileUtils::createKeyFileContent\n // and juce::KeyFileUtils::encryptXML\n const attrs: Record<string, string> = {\n user: userName,\n email: userEmail,\n [machineNumbersAttributeName]: machineNumbers,\n app: appName,\n date\n }\n if (expiryTime) attrs.expiryTime = expiryTime\n return [XML_DECLARATION, buildKeyElement(attrs)].join(' ')\n }\n\n static createKeyFileComment(\n {\n appName,\n userEmail,\n userName,\n machineNumbers\n }: CreateKeyFileCommentParams,\n created: string,\n expiryTime?: string\n ): string {\n // Ports juce::KeyFileUtils::createKeyFileComment\n return (\n `Keyfile for ${appName}\\r\\n` +\n `${userName ? `User: ${userName}\\r\\n` : ''}` +\n `Email: ${userEmail}\\r\\n` +\n `Machine numbers: ${machineNumbers}\\r\\n` +\n `Created: ${created}` +\n (expiryTime ? `\\r\\nExpires: ${expiryTime}` : '')\n )\n }\n\n static encryptXMLLine(xmlLine: string, privateKey: JuceRSAKey): string {\n // Ports juce::KeyFileUtils::encryptXML\n const val = JuceBigInteger.fromUTF8MemoryBlock(xmlLine)\n privateKey.applyToValue(val)\n return val.toHex()\n }\n\n static createKeyFile(\n comment: string,\n xmlLine: string,\n rsaPrivateKey: JuceRSAKey\n ): string {\n // Ports juce::KeyFileUtils::createKeyFile\n let asHex = '#' + this.encryptXMLLine(xmlLine, rsaPrivateKey)\n\n const lines: string[] = []\n lines.push(comment)\n lines.push('')\n\n const charsPerLine = 70\n while (asHex.length > 0) {\n lines.push(asHex.substring(0, charsPerLine))\n asHex = asHex.substring(charsPerLine)\n }\n\n lines.push('')\n\n return lines.join('\\r\\n')\n }\n}\n","import { JuceBigInteger } from './JuceBigInteger'\n\nexport class JuceRSAKey {\n protected part1: JuceBigInteger\n protected part2: JuceBigInteger\n constructor(public s: string) {\n // Ports juce::RSAKey::RSAKey()\n if (s.includes(',')) {\n const [p1, p2] = s.split(',').map(p => JuceBigInteger.fromHex(p))\n this.part1 = p1\n this.part2 = p2\n } else {\n this.part1 = new JuceBigInteger()\n this.part2 = new JuceBigInteger()\n }\n }\n applyToValue(val: JuceBigInteger): void {\n // Ports juce::RSAKey::applyToValue()\n if (this.part1.isZero() || this.part2.isZero() || val.value <= 0n) {\n return\n }\n\n const result = new JuceBigInteger()\n\n while (!val.isZero()) {\n result.value *= this.part2.value\n\n const remainder = new JuceBigInteger()\n val.divideBy(this.part2, remainder)\n\n remainder.exponentModulo(this.part1, this.part2)\n\n result.value += remainder.value\n }\n\n val.value = result.value\n }\n}\n","import { GenerateExpiringKeyFileParams, GenerateKeyFileParams } from '../types'\nimport { JuceKeyFileUtils } from './JuceKeyFileUtils'\nimport { JuceRSAKey } from './JuceRSAKey'\n\nexport class JuceKeyGeneration {\n static generateKeyFile(\n params: GenerateKeyFileParams,\n date: Date = new Date()\n ) {\n const xml = JuceKeyFileUtils.createKeyFileContentLine(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers,\n machineNumbersAttributeName: 'mach'\n },\n JuceKeyFileUtils.toHexStringMilliseconds(date)\n )\n const comment = JuceKeyFileUtils.createKeyFileComment(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers\n },\n JuceKeyFileUtils.toString(date)\n )\n return JuceKeyFileUtils.createKeyFile(\n comment,\n xml,\n new JuceRSAKey(params.privateKey)\n )\n }\n\n static generateExpiringKeyFile(\n params: GenerateExpiringKeyFileParams,\n date: Date = new Date()\n ) {\n const xml = JuceKeyFileUtils.createKeyFileContentLine(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers,\n machineNumbersAttributeName: 'expiring_mach'\n },\n JuceKeyFileUtils.toHexStringMilliseconds(date),\n JuceKeyFileUtils.toHexStringMilliseconds(params.expiryTime)\n )\n const comment = JuceKeyFileUtils.createKeyFileComment(\n {\n appName: params.appName,\n userEmail: params.userEmail,\n userName: params.userName,\n machineNumbers: params.machineNumbers\n },\n JuceKeyFileUtils.toString(date),\n JuceKeyFileUtils.toString(params.expiryTime)\n )\n return JuceKeyFileUtils.createKeyFile(\n comment,\n xml,\n new JuceRSAKey(params.privateKey)\n )\n }\n}\n","import { z } from 'zod'\n\nimport { JuceBigInteger } from './juce/JuceBigInteger'\n\nexport const createKeyFileCommentParamsSchema = z.object({\n appName: z.string().min(1),\n userEmail: z.string().min(1),\n userName: z.string().min(1),\n machineNumbers: z.string().min(1)\n})\nexport type CreateKeyFileCommentParams = z.infer<\n typeof createKeyFileCommentParamsSchema\n>\n\nexport const machineNumbersAttributeNameSchema = z.enum([\n 'mach',\n 'expiring_mach'\n])\nexport type MachineNumbersAttributeName = z.infer<\n typeof machineNumbersAttributeNameSchema\n>\n\nexport const createKeyFileContentLineParamsSchema =\n createKeyFileCommentParamsSchema.extend({\n machineNumbersAttributeName: machineNumbersAttributeNameSchema\n })\nexport type CreateKeyFileContentLineParams = z.infer<\n typeof createKeyFileContentLineParamsSchema\n>\n\nexport const rsaKeyComponentsSchema = z.stringFormat(\n // Ports juce::RSAKey::RSAKey() and juce::RSAKey::applyToValue()\n 'RSAKeyComponents',\n x =>\n x.includes(',') &&\n x.split(',').every(p => !JuceBigInteger.fromHex(p).isZero())\n)\nexport type RSAKeyComponents = z.infer<typeof rsaKeyComponentsSchema>\n\nexport const generateKeyFileParamsSchema =\n createKeyFileCommentParamsSchema.extend({\n privateKey: rsaKeyComponentsSchema\n })\nexport type GenerateKeyFileParams = z.infer<typeof generateKeyFileParamsSchema>\n\nexport const generateExpiringKeyFileParamsSchema =\n generateKeyFileParamsSchema.extend({\n expiryTime: z.date().min(new Date('1970-01-01T00:00:00.001Z'), {\n error: 'Expiry time must be after 1970-01-01T00:00:00.000Z'\n })\n })\nexport type GenerateExpiringKeyFileParams = z.infer<\n typeof generateExpiringKeyFileParamsSchema\n>\n","import { JuceKeyGeneration } from './juce/JuceKeyGeneration'\nimport { GenerateKeyFileParams, generateKeyFileParamsSchema } from './types'\n\nexport const generateKeyFile = (\n params: GenerateKeyFileParams,\n date: Date = new Date()\n) => {\n const paramsParse = generateKeyFileParamsSchema.parse(params)\n return JuceKeyGeneration.generateKeyFile(paramsParse, date)\n}\n","import { JuceKeyGeneration } from './juce/JuceKeyGeneration'\nimport {\n GenerateExpiringKeyFileParams,\n generateExpiringKeyFileParamsSchema\n} from './types'\n\nexport const generateExpiringKeyFile = (\n params: GenerateExpiringKeyFileParams,\n date: Date = new Date()\n) => {\n const paramsParse = generateExpiringKeyFileParamsSchema.parse(params)\n return JuceKeyGeneration.generateExpiringKeyFile(paramsParse, date)\n}\n"],"mappings":";AAAA,SAAS,cAAc,YAAY;AAE5B,IAAM,iBAAN,MAAM,gBAAe;AAAA,EACxB,YAAmB,QAAgB,IAAI;AAApB;AAAA,EAAqB;AAAA,EAExC,OAAO,SAAS,GAAyB;AACrC,WAAO,gBAAe,QAAQ,EAAE,SAAS,EAAE,CAAC;AAAA,EAChD;AAAA,EAEA,SAAe;AACX,WAAO,IAAI,KAAK,KAAK,MAAM,GAAG,EAAE;AAAA,EACpC;AAAA,EAEA,OAAO,QAAQ,KAA6B;AACxC,UAAM,IAAI,IAAI,KAAK;AACnB,WAAO,IAAI,gBAAe,IAAI,OAAO,KAAK,CAAC,EAAE,IAAI,EAAE;AAAA,E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C3D,OAAO;AAAA,EACX,CAAC;AACL,CAAC;;;AC/CE,IAAM,kBAAkB,CAC3B,QACA,OAAa,oBAAI,KAAK,MACrB;AACD,QAAM,cAAc,4BAA4B,MAAM,MAAM;AAC5D,SAAO,kBAAkB,gBAAgB,aAAa,IAAI;AAC9D;;;ACHO,IAAM,0BAA0B,CACnC,QACA,OAAa,oBAAI,KAAK,MACrB;AACD,QAAM,cAAc,oCAAoC,MAAM,MAAM;AACpE,SAAO,kBAAkB,wBAAwB,aAAa,IAAI;AACtE;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ianacaburian/generate-key-file",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Ports juce_KeyGeneration::generateKeyFile() to node.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -9,6 +9,9 @@
9
9
  "files": [
10
10
  "dist"
11
11
  ],
12
+ "engines": {
13
+ "node": ">=24"
14
+ },
12
15
  "scripts": {
13
16
  "clean": "rm -rf dist && npm run cm:clean",
14
17
  "lint": "eslint src",
@@ -36,27 +39,24 @@
36
39
  },
37
40
  "homepage": "https://github.com/ianacaburian/generate-key-file#readme",
38
41
  "devDependencies": {
39
- "@eslint/js": "^9.11.1",
40
- "@ianvs/prettier-plugin-sort-imports": "^4.3.1",
42
+ "@eslint/js": "^10.0.1",
43
+ "@ianvs/prettier-plugin-sort-imports": "^4.7.1",
41
44
  "@types/jsbn": "^1.2.33",
42
- "@typescript-eslint/eslint-plugin": "^8.7.0",
43
- "@typescript-eslint/parser": "^8.7.0",
44
- "eslint": "^9.11.1",
45
- "eslint-config-prettier": "^9.1.0",
46
- "eslint-plugin-prettier": "^5.2.1",
47
- "fast-check": "^3.22.0",
48
- "globals": "^15.9.0",
49
- "prettier": "^3.3.3",
50
- "ts-node": "^10.9.2",
51
- "tsup": "^8.3.0",
52
- "typescript": "5.5.4",
53
- "typescript-eslint": "^8.7.0",
54
- "vitest": "^2.1.1",
55
- "zod-fast-check": "^0.10.1"
45
+ "@typescript-eslint/eslint-plugin": "^8.61.1",
46
+ "@typescript-eslint/parser": "^8.61.1",
47
+ "eslint": "^10.5.0",
48
+ "eslint-config-prettier": "^10.1.8",
49
+ "eslint-plugin-prettier": "^5.5.6",
50
+ "fast-check": "^4.8.0",
51
+ "globals": "^17.6.0",
52
+ "prettier": "^3.8.4",
53
+ "tsup": "^8.5.1",
54
+ "typescript": "~6.0.3",
55
+ "typescript-eslint": "^8.61.1",
56
+ "vitest": "^4.1.9"
56
57
  },
57
58
  "dependencies": {
58
- "fast-xml-parser": "^4.5.0",
59
59
  "jsbn": "^1.1.0",
60
- "zod": "^3.23.8"
60
+ "zod": "^4.4.3"
61
61
  }
62
62
  }