@open-charging-cloud/chargy-core 0.11.0 → 0.11.2

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
@@ -181,7 +181,7 @@ npx playwright install chromium
181
181
  ## Publishing
182
182
 
183
183
  ```bash
184
- npm version 0.11.0 --no-git-tag-version
184
+ npm version 0.11.2 --no-git-tag-version
185
185
  npm run verify
186
186
  npm pack --dry-run
187
187
  npm pack
@@ -12232,33 +12232,58 @@ var Chargy = class {
12232
12232
  );
12233
12233
  });
12234
12234
  const publicKeyDER = ASN1_PublicKey.decode(publicKeyBuffer, "der");
12235
- const KeyType_OID = publicKeyDER.oids[0].join(".");
12235
+ const firstOID = publicKeyDER.oids[0];
12236
+ if (firstOID === void 0)
12237
+ throw new Error("The SubjectPublicKeyInfo algorithm identifier is missing!");
12238
+ const KeyType_OID = firstOID.join(".");
12236
12239
  let KeyType = "unknown";
12237
12240
  switch (KeyType_OID) {
12238
12241
  case "1.2.840.10045.2.1":
12239
12242
  KeyType = "ecPublicKey";
12240
12243
  break;
12244
+ case "1.3.101.112":
12245
+ case "1.3.101.113":
12246
+ KeyType = "EdDSA";
12247
+ break;
12248
+ case "2.16.840.1.101.3.4.3.18":
12249
+ KeyType = "ML-DSA";
12250
+ break;
12241
12251
  }
12242
- const Curve_OID = publicKeyDER.oids[1].join(".");
12243
- let Curve = "unknown";
12244
- switch (Curve_OID) {
12252
+ const Algorithm_OID = publicKeyDER.oids[1]?.join(".") ?? KeyType_OID;
12253
+ let Algorithm = "unknown";
12254
+ switch (Algorithm_OID) {
12255
+ case "1.3.101.112":
12256
+ Algorithm = "Ed25519";
12257
+ break;
12258
+ case "1.3.101.113":
12259
+ Algorithm = "Ed448";
12260
+ break;
12261
+ case "2.16.840.1.101.3.4.3.18":
12262
+ Algorithm = "ML-DSA-65";
12263
+ break;
12245
12264
  // Koblitz 224-bit curve
12246
12265
  case "1.3.132.0.32":
12247
- Curve = "secp224k1";
12266
+ Algorithm = "secp224k1";
12248
12267
  break;
12249
12268
  // NIST/ANSI X9.62 named 256-bit elliptic curve used with SHA256
12250
12269
  case "1.2.840.10045.3.1.7":
12251
- Curve = "secp256r1";
12270
+ Algorithm = "secp256r1";
12252
12271
  break;
12253
12272
  // NIST/ANSI X9.62 named 384-bit elliptic curve used with SHA384
12254
12273
  case "1.3.132.0.34":
12255
- Curve = "secp384r1";
12274
+ Algorithm = "secp384r1";
12256
12275
  break;
12257
12276
  // NIST/ANSI X9.62 named 521-bit elliptic curve used with SHA512
12258
12277
  case "1.3.132.0.35":
12259
- Curve = "secp521r1";
12278
+ Algorithm = "secp521r1";
12260
12279
  break;
12261
12280
  }
12281
+ const publicKeyData = new Uint8Array(publicKeyDER.publicKey.data);
12282
+ const expectedLength = Algorithm === "Ed25519" ? 32 : Algorithm === "Ed448" ? 57 : Algorithm === "ML-DSA-65" ? 1952 : void 0;
12283
+ if (publicKeyDER.publicKey.unused !== void 0 && publicKeyDER.publicKey.unused !== 0)
12284
+ throw new Error("The SubjectPublicKeyInfo public key has unused bits!");
12285
+ if (expectedLength !== void 0 && publicKeyData.length !== expectedLength)
12286
+ throw new Error(`Invalid ${Algorithm} public key length: expected ${expectedLength} bytes, got ${publicKeyData.length}!`);
12262
12287
  return {
12263
12288
  "@id": keyId,
12264
12289
  "@context": "https://open.charging.cloud/contexts/CTR+json",
@@ -12267,15 +12292,15 @@ var Chargy = class {
12267
12292
  "@id": keyId,
12268
12293
  "@context": "https://open.charging.cloud/contexts/publicKey+json",
12269
12294
  "subject": keyId,
12270
- type: {
12295
+ type: KeyType === "EdDSA" || KeyType === "ML-DSA" ? KeyType : {
12271
12296
  oid: KeyType_OID,
12272
12297
  name: KeyType
12273
12298
  },
12274
12299
  algorithm: {
12275
- oid: Curve_OID,
12276
- name: Curve
12300
+ oid: Algorithm_OID,
12301
+ name: Algorithm
12277
12302
  },
12278
- value: buf2hex(publicKeyDER.publicKey.data),
12303
+ value: buf2hex(publicKeyData),
12279
12304
  certainty: 0
12280
12305
  }
12281
12306
  ]
@@ -12289,15 +12314,36 @@ var Chargy = class {
12289
12314
  const publicKeyHEX = textContent.replace(/\s+/g, "");
12290
12315
  return publicKeyFile && publicKeyHEX.length >= 80 && publicKeyHEX.length % 2 === 0 && publicKeyHEX.startsWith("30") && /^[0-9a-fA-F]+$/.test(publicKeyHEX);
12291
12316
  }
12292
- TryToGetDERPublicKeyHEX(fileName, textContent) {
12317
+ TryToGetPublicKeyHEX(fileName, textContent) {
12293
12318
  if (textContent == null)
12294
12319
  return void 0;
12295
12320
  if (textContent.startsWith("-----BEGIN PUBLIC KEY-----") && textContent.endsWith("-----END PUBLIC KEY-----")) {
12296
12321
  const publicKeyPEM = textContent.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").split("\n").map((line) => line.trim()).filter((line) => line !== "" && !line.startsWith("#")).join("");
12297
- return buf2hex(import_buffer2.Buffer.from(publicKeyPEM, "base64"));
12322
+ try {
12323
+ const publicKeyDER = import_buffer2.Buffer.from(publicKeyPEM, "base64");
12324
+ const publicKey = this.TryToParseDERPublicKey(
12325
+ this.PublicKeyIdFromFileName(fileName),
12326
+ publicKeyDER
12327
+ ).publicKeys[0];
12328
+ const algorithm = typeof publicKey?.algorithm === "string" ? publicKey.algorithm : publicKey?.algorithm.name;
12329
+ return algorithm === "Ed25519" || algorithm === "Ed448" || algorithm === "ML-DSA-65" ? publicKey?.value : buf2hex(publicKeyDER);
12330
+ } catch {
12331
+ return void 0;
12332
+ }
12333
+ }
12334
+ if (this.IsHexEncodedPublicKeyFile(fileName, textContent)) {
12335
+ try {
12336
+ const publicKeyDER = import_buffer2.Buffer.from(textContent.replace(/\s+/g, ""), "hex");
12337
+ const publicKey = this.TryToParseDERPublicKey(
12338
+ this.PublicKeyIdFromFileName(fileName),
12339
+ publicKeyDER
12340
+ ).publicKeys[0];
12341
+ const algorithm = typeof publicKey?.algorithm === "string" ? publicKey.algorithm : publicKey?.algorithm.name;
12342
+ return algorithm === "Ed25519" || algorithm === "Ed448" || algorithm === "ML-DSA-65" ? publicKey?.value : buf2hex(publicKeyDER);
12343
+ } catch {
12344
+ return void 0;
12345
+ }
12298
12346
  }
12299
- if (this.IsHexEncodedPublicKeyFile(fileName, textContent))
12300
- return textContent.replace(/\s+/g, "");
12301
12347
  return void 0;
12302
12348
  }
12303
12349
  TryToCreatePublicKeyLookup(processedFiles) {
@@ -12923,7 +12969,7 @@ var Chargy = class {
12923
12969
  let textContent = new TextDecoder("utf-8").decode(expandedFile.data).trim();
12924
12970
  if (textContent.charCodeAt(0) === 65279)
12925
12971
  textContent = textContent.substring(1);
12926
- const publicKeyHEX = this.TryToGetDERPublicKeyHEX(expandedFile.name, textContent);
12972
+ const publicKeyHEX = this.TryToGetPublicKeyHEX(expandedFile.name, textContent);
12927
12973
  if (publicKeyHEX != null)
12928
12974
  publicKeyHEXLookup.set(this.PublicKeyIdFromFileName(expandedFile.name), publicKeyHEX);
12929
12975
  }