@libpdf/core 0.0.1-beta.8 → 0.0.1-beta.9

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/index.d.mts CHANGED
@@ -2344,18 +2344,22 @@ interface Signer {
2344
2344
  /** Signature algorithm - required for CMS construction */
2345
2345
  readonly signatureAlgorithm: SignatureAlgorithm;
2346
2346
  /**
2347
- * Sign data and return raw signature bytes.
2347
+ * Sign data and return signature bytes.
2348
2348
  *
2349
2349
  * The signer is responsible for hashing the data using the specified algorithm
2350
2350
  * before creating the signature. For WebCrypto-based implementations, this is
2351
2351
  * handled automatically by the sign() function.
2352
2352
  *
2353
- * For RSA: PKCS#1 v1.5 or PSS signature
2354
- * For ECDSA: DER-encoded (r, s) pair
2353
+ * Signature format requirements:
2354
+ * - RSA: PKCS#1 v1.5 or PSS signature bytes
2355
+ * - ECDSA: DER-encoded SEQUENCE { INTEGER r, INTEGER s }
2356
+ *
2357
+ * Note: WebCrypto returns ECDSA signatures in P1363 format (r || s concatenated).
2358
+ * Use pkijs.createCMSECDSASignature() to convert to DER format.
2355
2359
  *
2356
2360
  * @param data - The data to sign (will be hashed internally)
2357
2361
  * @param algorithm - The digest algorithm to use for hashing
2358
- * @returns Raw signature bytes
2362
+ * @returns Signature bytes in the format required by CMS/PKCS#7
2359
2363
  */
2360
2364
  sign(data: Uint8Array, algorithm: DigestAlgorithm): Promise<Uint8Array>;
2361
2365
  }
package/dist/index.mjs CHANGED
@@ -5,10 +5,11 @@ import { md5, sha1 } from "@noble/hashes/legacy.js";
5
5
  import { sha256, sha384, sha512 } from "@noble/hashes/sha2.js";
6
6
  import { Boolean, Constructed, Integer, Null, ObjectIdentifier, OctetString, Sequence, UTCTime, fromBER } from "asn1js";
7
7
  import * as pkijs from "pkijs";
8
+ import { createCMSECDSASignature } from "pkijs";
8
9
  import { base64 } from "@scure/base";
9
10
 
10
11
  //#region package.json
11
- var version = "0.0.1-beta.8";
12
+ var version = "0.0.1-beta.9";
12
13
 
13
14
  //#endregion
14
15
  //#region src/objects/pdf-array.ts
@@ -38241,6 +38242,14 @@ var PDF = class PDF {
38241
38242
  securityHandler = handler;
38242
38243
  }
38243
38244
  }
38245
+ if (useIncremental && !fileId) {
38246
+ const idArray = this.ctx.info.trailer.getArray("ID");
38247
+ if (idArray && idArray.length >= 2) {
38248
+ const id1 = idArray.at(0);
38249
+ const id2 = idArray.at(1);
38250
+ if (id1 instanceof PdfString && id2 instanceof PdfString) fileId = [id1.bytes, id2.bytes];
38251
+ }
38252
+ }
38244
38253
  const useXRefStream = options.useXRefStream ?? (useIncremental ? this.usesXRefStreams : false);
38245
38254
  if (useIncremental) {
38246
38255
  const result$1 = writeIncremental(this.ctx.registry, {
@@ -38396,6 +38405,7 @@ var CryptoKeySigner = class {
38396
38405
  break;
38397
38406
  }
38398
38407
  const signature = await cryptoEngine$1.sign(signAlgorithm, this.privateKey, new Uint8Array(data));
38408
+ if (this.signatureAlgorithm === "ECDSA") return new Uint8Array(createCMSECDSASignature(signature));
38399
38409
  return new Uint8Array(signature);
38400
38410
  }
38401
38411
  /**
@@ -40777,6 +40787,7 @@ var P12Signer = class P12Signer {
40777
40787
  break;
40778
40788
  }
40779
40789
  const signature = await cryptoEngine.sign(signAlgorithm, this.privateKey, new Uint8Array(data));
40790
+ if (this.signatureAlgorithm === "ECDSA") return new Uint8Array(createCMSECDSASignature(signature));
40780
40791
  return new Uint8Array(signature);
40781
40792
  }
40782
40793
  /**