ksef-client-ts 0.7.1 → 0.7.2-alpha.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/dist/cli.js CHANGED
@@ -2371,7 +2371,7 @@ ${lines.join("\n")}
2371
2371
  });
2372
2372
 
2373
2373
  // src/crypto/cryptography-service.ts
2374
- import * as crypto from "crypto";
2374
+ import * as crypto from "node:crypto";
2375
2375
  import * as x509 from "@peculiar/x509";
2376
2376
  function setCryptoProvider() {
2377
2377
  x509.cryptoProvider.set(crypto.webcrypto);
@@ -2459,7 +2459,7 @@ var init_cryptography_service = __esm({
2459
2459
  const certPem = this.fetcher.getSymmetricKeyEncryptionPem();
2460
2460
  const encryptedKey = crypto.publicEncrypt(
2461
2461
  {
2462
- key: certPem,
2462
+ key: this.extractSpkiPem(certPem),
2463
2463
  oaepHash: "sha256",
2464
2464
  padding: crypto.constants.RSA_PKCS1_OAEP_PADDING
2465
2465
  },
@@ -2589,12 +2589,22 @@ var init_cryptography_service = __esm({
2589
2589
  // ---------------------------------------------------------------------------
2590
2590
  // Private helpers
2591
2591
  // ---------------------------------------------------------------------------
2592
+ /**
2593
+ * Extract a public-key SPKI PEM (`-----BEGIN PUBLIC KEY-----`) from a full
2594
+ * CERTIFICATE PEM. Node's `publicEncrypt` accepts either form, but Deno's
2595
+ * Node compatibility layer only accepts SPKI PEM, so we normalize upfront
2596
+ * to keep the library portable across runtimes.
2597
+ */
2598
+ extractSpkiPem(certPem) {
2599
+ const publicKey = new crypto.X509Certificate(certPem).publicKey;
2600
+ return publicKey.export({ type: "spki", format: "pem" });
2601
+ }
2592
2602
  /** RSA-OAEP SHA-256 encryption. */
2593
2603
  encryptRsaOaep(certPem, plaintext) {
2594
2604
  return new Uint8Array(
2595
2605
  crypto.publicEncrypt(
2596
2606
  {
2597
- key: certPem,
2607
+ key: this.extractSpkiPem(certPem),
2598
2608
  oaepHash: "sha256",
2599
2609
  padding: crypto.constants.RSA_PKCS1_OAEP_PADDING
2600
2610
  },
@@ -2632,7 +2642,7 @@ var init_cryptography_service = __esm({
2632
2642
  });
2633
2643
 
2634
2644
  // src/qr/verification-link-service.ts
2635
- import crypto2 from "crypto";
2645
+ import crypto2 from "node:crypto";
2636
2646
  var VerificationLinkService;
2637
2647
  var init_verification_link_service = __esm({
2638
2648
  "src/qr/verification-link-service.ts"() {
@@ -2938,7 +2948,7 @@ var init_document_structures = __esm({
2938
2948
  });
2939
2949
 
2940
2950
  // src/workflows/offline-invoice-workflow.ts
2941
- import crypto3 from "crypto";
2951
+ import crypto3 from "node:crypto";
2942
2952
  var OfflineInvoiceWorkflow;
2943
2953
  var init_offline_invoice_workflow = __esm({
2944
2954
  "src/workflows/offline-invoice-workflow.ts"() {
@@ -3230,7 +3240,7 @@ var signature_service_exports = {};
3230
3240
  __export(signature_service_exports, {
3231
3241
  SignatureService: () => SignatureService
3232
3242
  });
3233
- import * as crypto4 from "crypto";
3243
+ import * as crypto4 from "node:crypto";
3234
3244
  import { ExclusiveCanonicalization } from "xml-crypto";
3235
3245
  import { DOMParser, XMLSerializer } from "@xmldom/xmldom";
3236
3246
  function pickRsaAlgo() {
@@ -6473,7 +6483,7 @@ var init_invoice_validator = __esm({
6473
6483
  });
6474
6484
 
6475
6485
  // src/builders/batch-file.ts
6476
- import * as crypto6 from "crypto";
6486
+ import * as crypto6 from "node:crypto";
6477
6487
  function splitBuffer(data, maxPartSize) {
6478
6488
  if (data.length <= maxPartSize) {
6479
6489
  return [data];
@@ -6802,18 +6812,18 @@ var init_batch_session_workflow = __esm({
6802
6812
  });
6803
6813
 
6804
6814
  // src/cli/index.ts
6805
- import { readFileSync as readFileSync11 } from "fs";
6806
- import { fileURLToPath as fileURLToPath2 } from "url";
6807
- import { dirname as dirname3, resolve } from "path";
6815
+ import { readFileSync as readFileSync11 } from "node:fs";
6816
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
6817
+ import { dirname as dirname3, resolve } from "node:path";
6808
6818
  import { defineCommand as defineCommand19, runMain } from "citty";
6809
6819
 
6810
6820
  // src/cli/commands/config.ts
6811
6821
  import { defineCommand } from "citty";
6812
6822
 
6813
6823
  // src/cli/config-store.ts
6814
- import * as fs from "fs";
6815
- import * as path from "path";
6816
- import * as os from "os";
6824
+ import * as fs from "node:fs";
6825
+ import * as path from "node:path";
6826
+ import * as os from "node:os";
6817
6827
 
6818
6828
  // src/cli/types.ts
6819
6829
  var ENV_MAP = {
@@ -6892,9 +6902,9 @@ function outputWarning(msg) {
6892
6902
  }
6893
6903
 
6894
6904
  // src/cli/session-store.ts
6895
- import * as fs2 from "fs";
6896
- import * as path2 from "path";
6897
- import * as os2 from "os";
6905
+ import * as fs2 from "node:fs";
6906
+ import * as path2 from "node:path";
6907
+ import * as os2 from "node:os";
6898
6908
  var SESSION_DIR = path2.join(os2.homedir(), ".ksef");
6899
6909
  var SESSION_FILE = path2.join(SESSION_DIR, "session.json");
6900
6910
  function loadSession() {
@@ -7149,7 +7159,7 @@ var configCommand = defineCommand({
7149
7159
  });
7150
7160
 
7151
7161
  // src/cli/commands/auth.ts
7152
- import * as fs5 from "fs";
7162
+ import * as fs5 from "node:fs";
7153
7163
  import { defineCommand as defineCommand2 } from "citty";
7154
7164
  import { consola as consola7 } from "consola";
7155
7165
 
@@ -7161,9 +7171,9 @@ import { consola as consola6 } from "consola";
7161
7171
  import { consola as consola5 } from "consola";
7162
7172
 
7163
7173
  // src/cli/credentials-store.ts
7164
- import * as fs3 from "fs";
7165
- import * as path3 from "path";
7166
- import * as os3 from "os";
7174
+ import * as fs3 from "node:fs";
7175
+ import * as path3 from "node:path";
7176
+ import * as os3 from "node:os";
7167
7177
  var CREDENTIALS_DIR = path3.join(os3.homedir(), ".ksef");
7168
7178
  var CREDENTIALS_FILE = path3.join(CREDENTIALS_DIR, "credentials.json");
7169
7179
  function loadCredentials() {
@@ -7303,9 +7313,9 @@ async function requireSession(globalOpts) {
7303
7313
  }
7304
7314
 
7305
7315
  // src/cli/pending-challenge-store.ts
7306
- import * as fs4 from "fs";
7307
- import * as path4 from "path";
7308
- import * as os4 from "os";
7316
+ import * as fs4 from "node:fs";
7317
+ import * as path4 from "node:path";
7318
+ import * as os4 from "node:os";
7309
7319
  var PENDING_CHALLENGE_FILE = path4.join(os4.homedir(), ".ksef", "pending-challenge.json");
7310
7320
  function savePendingChallenge(data) {
7311
7321
  const dir = path4.dirname(PENDING_CHALLENGE_FILE);
@@ -7390,11 +7400,11 @@ var login = defineCommand2({
7390
7400
  if (token) {
7391
7401
  loginResult = await client.loginWithToken(token, nip);
7392
7402
  } else if (args.p12) {
7393
- const fs17 = await import("fs");
7403
+ const fs17 = await import("node:fs");
7394
7404
  const p12Buffer = fs17.readFileSync(args.p12);
7395
7405
  loginResult = await client.loginWithPkcs12(p12Buffer, args["p12-password"] ?? "", nip);
7396
7406
  } else if (args.cert && args.key) {
7397
- const fs17 = await import("fs");
7407
+ const fs17 = await import("node:fs");
7398
7408
  const certPem = fs17.readFileSync(args.cert, "utf-8");
7399
7409
  const keyPem = fs17.readFileSync(args.key, "utf-8");
7400
7410
  loginResult = await client.loginWithCertificate(certPem, keyPem, nip, args["key-password"]);
@@ -7745,7 +7755,7 @@ var authCommand = defineCommand2({
7745
7755
  });
7746
7756
 
7747
7757
  // src/cli/commands/session.ts
7748
- import * as fs6 from "fs";
7758
+ import * as fs6 from "node:fs";
7749
7759
  import { defineCommand as defineCommand3 } from "citty";
7750
7760
  import { consola as consola8 } from "consola";
7751
7761
  init_document_structures();
@@ -8200,21 +8210,21 @@ var sessionCommand = defineCommand3({
8200
8210
  });
8201
8211
 
8202
8212
  // src/cli/commands/invoice.ts
8203
- import * as fs11 from "fs";
8204
- import * as path8 from "path";
8205
- import { Readable } from "stream";
8213
+ import * as fs11 from "node:fs";
8214
+ import * as path8 from "node:path";
8215
+ import { Readable } from "node:stream";
8206
8216
  import { defineCommand as defineCommand6 } from "citty";
8207
8217
  import { consola as consola11 } from "consola";
8208
8218
  init_document_structures();
8209
8219
 
8210
8220
  // src/cli/commands/export-incremental.ts
8211
- import * as fs8 from "fs";
8212
- import * as path5 from "path";
8221
+ import * as fs8 from "node:fs";
8222
+ import * as path5 from "node:path";
8213
8223
  import { defineCommand as defineCommand4 } from "citty";
8214
8224
  import { consola as consola9 } from "consola";
8215
8225
 
8216
8226
  // src/workflows/hwm-storage.ts
8217
- import * as fs7 from "fs/promises";
8227
+ import * as fs7 from "node:fs/promises";
8218
8228
  var FileHwmStore = class {
8219
8229
  constructor(filePath) {
8220
8230
  this.filePath = filePath;
@@ -8240,7 +8250,7 @@ init_zip();
8240
8250
  init_polling();
8241
8251
 
8242
8252
  // src/utils/hash.ts
8243
- import crypto5 from "crypto";
8253
+ import crypto5 from "node:crypto";
8244
8254
  function sha256Base64(data) {
8245
8255
  return crypto5.createHash("sha256").update(data).digest("base64");
8246
8256
  }
@@ -8492,10 +8502,10 @@ init_xml();
8492
8502
  init_invoice_validator();
8493
8503
 
8494
8504
  // src/validation/xsd-validator.ts
8495
- import { createRequire } from "module";
8496
- import * as fs9 from "fs";
8497
- import * as path6 from "path";
8498
- import { fileURLToPath, pathToFileURL } from "url";
8505
+ import { createRequire } from "node:module";
8506
+ import * as fs9 from "node:fs";
8507
+ import * as path6 from "node:path";
8508
+ import { fileURLToPath, pathToFileURL } from "node:url";
8499
8509
  var cachedPkgRoot = null;
8500
8510
  function locatePackageRoot() {
8501
8511
  if (cachedPkgRoot !== null) return cachedPkgRoot;
@@ -8600,8 +8610,8 @@ init_ksef_xsd_validation_error();
8600
8610
  // src/cli/commands/invoice-build-helpers.ts
8601
8611
  init_ksef_validation_error();
8602
8612
  init_ksef_xsd_validation_error();
8603
- import * as fs10 from "fs";
8604
- import * as path7 from "path";
8613
+ import * as fs10 from "node:fs";
8614
+ import * as path7 from "node:path";
8605
8615
  import { parse as parseYaml, YAMLParseError } from "yaml";
8606
8616
 
8607
8617
  // src/cli/commands/invoice-build-templates/fa2.json
@@ -10279,11 +10289,11 @@ var tokenCommand = defineCommand8({
10279
10289
  // src/cli/commands/cert.ts
10280
10290
  import { defineCommand as defineCommand9 } from "citty";
10281
10291
  import { consola as consola13 } from "consola";
10282
- import fs12 from "fs";
10283
- import path9 from "path";
10292
+ import fs12 from "node:fs";
10293
+ import path9 from "node:path";
10284
10294
 
10285
10295
  // src/crypto/certificate-service.ts
10286
- import * as crypto7 from "crypto";
10296
+ import * as crypto7 from "node:crypto";
10287
10297
  import * as x5092 from "@peculiar/x509";
10288
10298
  var CertificateService = class {
10289
10299
  static getSha256Fingerprint(certPem) {
@@ -10722,7 +10732,7 @@ var certCommand = defineCommand9({
10722
10732
  });
10723
10733
 
10724
10734
  // src/cli/commands/qr.ts
10725
- import * as fs13 from "fs";
10735
+ import * as fs13 from "node:fs";
10726
10736
  import { defineCommand as defineCommand10 } from "citty";
10727
10737
 
10728
10738
  // src/qr/qrcode-service.ts
@@ -11874,9 +11884,9 @@ var completionCommand = defineCommand16({
11874
11884
  });
11875
11885
 
11876
11886
  // src/cli/commands/setup.ts
11877
- import * as fs14 from "fs";
11878
- import * as path10 from "path";
11879
- import * as os5 from "os";
11887
+ import * as fs14 from "node:fs";
11888
+ import * as path10 from "node:path";
11889
+ import * as os5 from "node:os";
11880
11890
  import { defineCommand as defineCommand17 } from "citty";
11881
11891
  import { consola as consola16 } from "consola";
11882
11892
  init_patterns();
@@ -11884,7 +11894,7 @@ init_auth_xml_builder();
11884
11894
  init_polling();
11885
11895
 
11886
11896
  // src/cli/utils/open-folder.ts
11887
- import { execFile } from "child_process";
11897
+ import { execFile } from "node:child_process";
11888
11898
  function openFolder(folderPath) {
11889
11899
  return new Promise((resolve2) => {
11890
11900
  const platform = process.platform;
@@ -12143,14 +12153,14 @@ var setupCommand = defineCommand17({
12143
12153
  });
12144
12154
 
12145
12155
  // src/cli/commands/offline.ts
12146
- import * as fs16 from "fs";
12156
+ import * as fs16 from "node:fs";
12147
12157
  import { defineCommand as defineCommand18 } from "citty";
12148
12158
  import { consola as consola17 } from "consola";
12149
12159
 
12150
12160
  // src/offline/file-storage.ts
12151
- import * as fs15 from "fs/promises";
12152
- import * as path11 from "path";
12153
- import * as os6 from "os";
12161
+ import * as fs15 from "node:fs/promises";
12162
+ import * as path11 from "node:path";
12163
+ import * as os6 from "node:os";
12154
12164
 
12155
12165
  // src/offline/storage.ts
12156
12166
  function matchesFilter(invoice3, filter) {