helper.js 1.0 KB

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