@wats/graph 0.3.25 → 0.3.26

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.
@@ -509,6 +509,20 @@ function validateBase64Digest(value, label, code = "invalid_base64", expectedLen
509
509
  throw new MediaCryptoError(code, `Invalid ${label}: malformed base64.`, cause);
510
510
  }
511
511
  }
512
+ function validateSha256Digest(value, label) {
513
+ if (typeof value !== "string" || value.trim().length === 0) {
514
+ throw new MediaValidationError("invalid_options", `Invalid ${label}: expected a non-empty hex or base64 SHA-256 digest string.`);
515
+ }
516
+ const trimmed = value.trim();
517
+ if (/^[0-9a-fA-F]{64}$/u.test(trimmed)) {
518
+ const out = new Uint8Array(32);
519
+ for (let i = 0;i < 32; i += 1) {
520
+ out[i] = Number.parseInt(trimmed.slice(i * 2, i * 2 + 2), 16);
521
+ }
522
+ return out;
523
+ }
524
+ return validateBase64Digest(trimmed, label, "invalid_options", 32);
525
+ }
512
526
  function validateDownloadBytesOptions(options) {
513
527
  if (!isRecord(options)) {
514
528
  throw new MediaValidationError("invalid_options", "Invalid media download bytes options: expected an object.");
@@ -516,7 +530,7 @@ function validateDownloadBytesOptions(options) {
516
530
  const url = validateHttpUrl(options.url);
517
531
  const maxBytes = validateDownloadMaxBytes(options);
518
532
  const signal = validateSignal(options.signal);
519
- const expectedSha256 = options.expectedSha256 === undefined ? undefined : validateBase64Digest(options.expectedSha256, "expectedSha256", "invalid_options", 32);
533
+ const expectedSha256 = options.expectedSha256 === undefined ? undefined : validateSha256Digest(options.expectedSha256, "expectedSha256");
520
534
  return {
521
535
  url,
522
536
  maxBytes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wats/graph",
3
- "version": "0.3.25",
3
+ "version": "0.3.26",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",