verify.js 1.1 KB

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.generalVerify = void 0;
  4. const verify_js_1 = require("../flattened/verify.js");
  5. const errors_js_1 = require("../../util/errors.js");
  6. const is_object_js_1 = require("../../lib/is_object.js");
  7. async function generalVerify(jws, key, options) {
  8. if (!(0, is_object_js_1.default)(jws)) {
  9. throw new errors_js_1.JWSInvalid('General JWS must be an object');
  10. }
  11. if (!Array.isArray(jws.signatures) || !jws.signatures.every(is_object_js_1.default)) {
  12. throw new errors_js_1.JWSInvalid('JWS Signatures missing or incorrect type');
  13. }
  14. for (const signature of jws.signatures) {
  15. try {
  16. return await (0, verify_js_1.flattenedVerify)({
  17. header: signature.header,
  18. payload: jws.payload,
  19. protected: signature.protected,
  20. signature: signature.signature,
  21. }, key, options);
  22. }
  23. catch {
  24. }
  25. }
  26. throw new errors_js_1.JWSSignatureVerificationFailed();
  27. }
  28. exports.generalVerify = generalVerify;