helper.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. if (target) {
  21. const proto = Object.getPrototypeOf(target);
  22. if (proto?.prototype?.constructor === Array) {
  23. return true;
  24. }
  25. return isTypeOfArray(proto);
  26. }
  27. return false;
  28. }
  29. function isArrayEqual(bytes1, bytes2) {
  30. if (!(bytes1 && bytes2)) {
  31. return false;
  32. }
  33. if (bytes1.byteLength !== bytes2.byteLength) {
  34. return false;
  35. }
  36. const b1 = new Uint8Array(bytes1);
  37. const b2 = new Uint8Array(bytes2);
  38. for (let i = 0; i < bytes1.byteLength; i++) {
  39. if (b1[i] !== b2[i]) {
  40. return false;
  41. }
  42. }
  43. return true;
  44. }