helper.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.isConvertible = isConvertible;
  4. exports.isTypeOfArray = isTypeOfArray;
  5. exports.isArrayEqual = isArrayEqual;
  6. function isConvertible(target) {
  7. if (typeof target === "function" && target.prototype) {
  8. if (target.prototype.toASN && target.prototype.fromASN) {
  9. return true;
  10. }
  11. else {
  12. return isConvertible(target.prototype);
  13. }
  14. }
  15. else {
  16. return !!(target && typeof target === "object" && "toASN" in target && "fromASN" in target);
  17. }
  18. }
  19. function isTypeOfArray(target) {
  20. var _a;
  21. if (target) {
  22. const proto = Object.getPrototypeOf(target);
  23. if (((_a = proto === null || proto === void 0 ? void 0 : proto.prototype) === null || _a === void 0 ? void 0 : _a.constructor) === Array) {
  24. return true;
  25. }
  26. return isTypeOfArray(proto);
  27. }
  28. return false;
  29. }
  30. function isArrayEqual(bytes1, bytes2) {
  31. if (!(bytes1 && bytes2)) {
  32. return false;
  33. }
  34. if (bytes1.byteLength !== bytes2.byteLength) {
  35. return false;
  36. }
  37. const b1 = new Uint8Array(bytes1);
  38. const b2 = new Uint8Array(bytes2);
  39. for (let i = 0; i < bytes1.byteLength; i++) {
  40. if (b1[i] !== b2[i]) {
  41. return false;
  42. }
  43. }
  44. return true;
  45. }