topic.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. /*
  3. This file is part of web3.js.
  4. web3.js is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. web3.js is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with web3.js. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. exports.isTopicInBloom = exports.isTopic = void 0;
  17. const bloom_js_1 = require("./bloom.js");
  18. /**
  19. * Checks if its a valid topic
  20. */
  21. const isTopic = (topic) => {
  22. if (typeof topic !== 'string') {
  23. return false;
  24. }
  25. if (!/^(0x)?[0-9a-f]{64}$/i.test(topic)) {
  26. return false;
  27. }
  28. if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) {
  29. return true;
  30. }
  31. return false;
  32. };
  33. exports.isTopic = isTopic;
  34. /**
  35. * Returns true if the topic is part of the given bloom.
  36. * note: false positives are possible.
  37. */
  38. const isTopicInBloom = (bloom, topic) => {
  39. if (!(0, bloom_js_1.isBloom)(bloom)) {
  40. return false;
  41. }
  42. if (!(0, exports.isTopic)(topic)) {
  43. return false;
  44. }
  45. return (0, bloom_js_1.isInBloom)(bloom, topic);
  46. };
  47. exports.isTopicInBloom = isTopicInBloom;
  48. //# sourceMappingURL=topic.js.map