gdc-common-utils-ts 2.5.15 → 2.5.16

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.
@@ -242,9 +242,24 @@ export class CryptographyService {
242
242
  throw new Error("Invalid Detached JWS format");
243
243
  const protectedHeaderB64Url = parts[0];
244
244
  const signatureB64Url = parts[1];
245
- const payloadB64Url = Content.bytesToRawBase64UrlSafe(payloadBytes);
246
- const signingInput = `${protectedHeaderB64Url}.${payloadB64Url}`;
247
- const signingInputBytes = Content.stringToBytesUTF8(signingInput);
245
+ const protectedHeader = Content.base64UrlSafeToJSON(protectedHeaderB64Url);
246
+ if (protectedHeader.b64 !== undefined && typeof protectedHeader.b64 !== 'boolean') {
247
+ throw new Error("Detached JWS protected header 'b64' must be boolean.");
248
+ }
249
+ if (protectedHeader.b64 === false
250
+ && (!Array.isArray(protectedHeader.crit) || !protectedHeader.crit.includes('b64'))) {
251
+ throw new Error("RFC 7797 detached JWS with 'b64=false' must mark 'b64' critical.");
252
+ }
253
+ let signingInputBytes;
254
+ if (protectedHeader.b64 === false) {
255
+ const prefix = Content.stringToBytesUTF8(`${protectedHeaderB64Url}.`);
256
+ signingInputBytes = new Uint8Array(prefix.length + payloadBytes.length);
257
+ signingInputBytes.set(prefix);
258
+ signingInputBytes.set(payloadBytes, prefix.length);
259
+ }
260
+ else {
261
+ signingInputBytes = Content.stringToBytesUTF8(`${protectedHeaderB64Url}.${Content.bytesToRawBase64UrlSafe(payloadBytes)}`);
262
+ }
248
263
  const signatureBytes = Content.base64ToBytes(signatureB64Url);
249
264
  return this.verifyBytes(signatureBytes, signingInputBytes, publicJWKey);
250
265
  }
@@ -132,6 +132,7 @@ export interface ICryptography {
132
132
  * @param publicJWKey The signer's public key (JWK) to use for verification.
133
133
  * @returns A boolean indicating if the signature is valid.
134
134
  */
135
+ /** Verifies encoded detached JWS and RFC 7797 `b64=false` detached payloads. */
135
136
  verifyDetachedJws(payloadBytes: Uint8Array, detachedJws: string, publicJWKey: PublicJwk): Promise<boolean>;
136
137
  /**
137
138
  * Converts a JWS Object (with decoded headers and payload) into Compact Serialization format.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdc-common-utils-ts",
3
- "version": "2.5.15",
3
+ "version": "2.5.16",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },