@peac/protocol 0.16.3 → 0.16.5

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.
@@ -238,13 +238,32 @@ function validateTypeExtensionMappingInternal(input) {
238
238
  }
239
239
 
240
240
  // src/_internal/record-core/validators/jose-hardening.ts
241
- var KID_MAX_LENGTH = 256;
241
+ var KID_MAX_UTF8_BYTES = 256;
242
+ function isAcceptableKid(kid) {
243
+ if (typeof kid !== "string" || kid.length === 0) return false;
244
+ let bytes = 0;
245
+ for (let i = 0; i < kid.length; i++) {
246
+ const c = kid.charCodeAt(i);
247
+ if (c < 128) bytes += 1;
248
+ else if (c < 2048) bytes += 2;
249
+ else if (c >= 55296 && c <= 56319) {
250
+ const next = i + 1 < kid.length ? kid.charCodeAt(i + 1) : 0;
251
+ if (next < 56320 || next > 57343) return false;
252
+ bytes += 4;
253
+ i++;
254
+ } else if (c >= 56320 && c <= 57343) {
255
+ return false;
256
+ } else bytes += 3;
257
+ if (bytes > KID_MAX_UTF8_BYTES) return false;
258
+ }
259
+ return true;
260
+ }
242
261
  var ACCEPTED = { accepted: true };
243
262
  function rejected(errorCode) {
244
263
  return { accepted: false, errorCode };
245
264
  }
246
265
  function validateJoseHardeningInternal(header) {
247
- if (!header.kid || typeof header.kid !== "string" || header.kid.length === 0 || header.kid.length > KID_MAX_LENGTH) {
266
+ if (!isAcceptableKid(header.kid)) {
248
267
  return rejected("CRYPTO_JWS_MISSING_KID");
249
268
  }
250
269
  if (header.jwk !== void 0 || header.x5c !== void 0 || header.x5u !== void 0 || header.jku !== void 0) {