helper.js 1.2 KB

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