@open-charging-cloud/chargy-core 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -149,11 +149,11 @@ var require_bn = __commonJS({
149
149
  }
150
150
  } catch (e) {
151
151
  }
152
- BN.isBN = function isBN(num) {
153
- if (num instanceof BN) {
152
+ BN.isBN = function isBN(num2) {
153
+ if (num2 instanceof BN) {
154
154
  return true;
155
155
  }
156
- return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
156
+ return num2 !== null && typeof num2 === "object" && num2.constructor.wordSize === BN.wordSize && Array.isArray(num2.words);
157
157
  };
158
158
  BN.max = function max(left, right) {
159
159
  if (left.cmp(right) > 0) return left;
@@ -674,12 +674,12 @@ var require_bn = __commonJS({
674
674
  var hi = this._countBits(w);
675
675
  return (this.length - 1) * 26 + hi;
676
676
  };
677
- function toBitArray(num) {
678
- var w = new Array(num.bitLength());
677
+ function toBitArray(num2) {
678
+ var w = new Array(num2.bitLength());
679
679
  for (var bit = 0; bit < w.length; bit++) {
680
680
  var off = bit / 26 | 0;
681
681
  var wbit = bit % 26;
682
- w[bit] = (num.words[off] & 1 << wbit) >>> wbit;
682
+ w[bit] = (num2.words[off] & 1 << wbit) >>> wbit;
683
683
  }
684
684
  return w;
685
685
  }
@@ -720,60 +720,60 @@ var require_bn = __commonJS({
720
720
  }
721
721
  return this;
722
722
  };
723
- BN.prototype.iuor = function iuor(num) {
724
- while (this.length < num.length) {
723
+ BN.prototype.iuor = function iuor(num2) {
724
+ while (this.length < num2.length) {
725
725
  this.words[this.length++] = 0;
726
726
  }
727
- for (var i = 0; i < num.length; i++) {
728
- this.words[i] = this.words[i] | num.words[i];
727
+ for (var i = 0; i < num2.length; i++) {
728
+ this.words[i] = this.words[i] | num2.words[i];
729
729
  }
730
730
  return this.strip();
731
731
  };
732
- BN.prototype.ior = function ior(num) {
733
- assert((this.negative | num.negative) === 0);
734
- return this.iuor(num);
732
+ BN.prototype.ior = function ior(num2) {
733
+ assert((this.negative | num2.negative) === 0);
734
+ return this.iuor(num2);
735
735
  };
736
- BN.prototype.or = function or(num) {
737
- if (this.length > num.length) return this.clone().ior(num);
738
- return num.clone().ior(this);
736
+ BN.prototype.or = function or(num2) {
737
+ if (this.length > num2.length) return this.clone().ior(num2);
738
+ return num2.clone().ior(this);
739
739
  };
740
- BN.prototype.uor = function uor(num) {
741
- if (this.length > num.length) return this.clone().iuor(num);
742
- return num.clone().iuor(this);
740
+ BN.prototype.uor = function uor(num2) {
741
+ if (this.length > num2.length) return this.clone().iuor(num2);
742
+ return num2.clone().iuor(this);
743
743
  };
744
- BN.prototype.iuand = function iuand(num) {
744
+ BN.prototype.iuand = function iuand(num2) {
745
745
  var b;
746
- if (this.length > num.length) {
747
- b = num;
746
+ if (this.length > num2.length) {
747
+ b = num2;
748
748
  } else {
749
749
  b = this;
750
750
  }
751
751
  for (var i = 0; i < b.length; i++) {
752
- this.words[i] = this.words[i] & num.words[i];
752
+ this.words[i] = this.words[i] & num2.words[i];
753
753
  }
754
754
  this.length = b.length;
755
755
  return this.strip();
756
756
  };
757
- BN.prototype.iand = function iand(num) {
758
- assert((this.negative | num.negative) === 0);
759
- return this.iuand(num);
757
+ BN.prototype.iand = function iand(num2) {
758
+ assert((this.negative | num2.negative) === 0);
759
+ return this.iuand(num2);
760
760
  };
761
- BN.prototype.and = function and(num) {
762
- if (this.length > num.length) return this.clone().iand(num);
763
- return num.clone().iand(this);
761
+ BN.prototype.and = function and(num2) {
762
+ if (this.length > num2.length) return this.clone().iand(num2);
763
+ return num2.clone().iand(this);
764
764
  };
765
- BN.prototype.uand = function uand(num) {
766
- if (this.length > num.length) return this.clone().iuand(num);
767
- return num.clone().iuand(this);
765
+ BN.prototype.uand = function uand(num2) {
766
+ if (this.length > num2.length) return this.clone().iuand(num2);
767
+ return num2.clone().iuand(this);
768
768
  };
769
- BN.prototype.iuxor = function iuxor(num) {
769
+ BN.prototype.iuxor = function iuxor(num2) {
770
770
  var a;
771
771
  var b;
772
- if (this.length > num.length) {
772
+ if (this.length > num2.length) {
773
773
  a = this;
774
- b = num;
774
+ b = num2;
775
775
  } else {
776
- a = num;
776
+ a = num2;
777
777
  b = this;
778
778
  }
779
779
  for (var i = 0; i < b.length; i++) {
@@ -787,17 +787,17 @@ var require_bn = __commonJS({
787
787
  this.length = a.length;
788
788
  return this.strip();
789
789
  };
790
- BN.prototype.ixor = function ixor(num) {
791
- assert((this.negative | num.negative) === 0);
792
- return this.iuxor(num);
790
+ BN.prototype.ixor = function ixor(num2) {
791
+ assert((this.negative | num2.negative) === 0);
792
+ return this.iuxor(num2);
793
793
  };
794
- BN.prototype.xor = function xor(num) {
795
- if (this.length > num.length) return this.clone().ixor(num);
796
- return num.clone().ixor(this);
794
+ BN.prototype.xor = function xor(num2) {
795
+ if (this.length > num2.length) return this.clone().ixor(num2);
796
+ return num2.clone().ixor(this);
797
797
  };
798
- BN.prototype.uxor = function uxor(num) {
799
- if (this.length > num.length) return this.clone().iuxor(num);
800
- return num.clone().iuxor(this);
798
+ BN.prototype.uxor = function uxor(num2) {
799
+ if (this.length > num2.length) return this.clone().iuxor(num2);
800
+ return num2.clone().iuxor(this);
801
801
  };
802
802
  BN.prototype.inotn = function inotn(width) {
803
803
  assert(typeof width === "number" && width >= 0);
@@ -830,25 +830,25 @@ var require_bn = __commonJS({
830
830
  }
831
831
  return this.strip();
832
832
  };
833
- BN.prototype.iadd = function iadd(num) {
833
+ BN.prototype.iadd = function iadd(num2) {
834
834
  var r;
835
- if (this.negative !== 0 && num.negative === 0) {
835
+ if (this.negative !== 0 && num2.negative === 0) {
836
836
  this.negative = 0;
837
- r = this.isub(num);
837
+ r = this.isub(num2);
838
838
  this.negative ^= 1;
839
839
  return this._normSign();
840
- } else if (this.negative === 0 && num.negative !== 0) {
841
- num.negative = 0;
842
- r = this.isub(num);
843
- num.negative = 1;
840
+ } else if (this.negative === 0 && num2.negative !== 0) {
841
+ num2.negative = 0;
842
+ r = this.isub(num2);
843
+ num2.negative = 1;
844
844
  return r._normSign();
845
845
  }
846
846
  var a, b;
847
- if (this.length > num.length) {
847
+ if (this.length > num2.length) {
848
848
  a = this;
849
- b = num;
849
+ b = num2;
850
850
  } else {
851
- a = num;
851
+ a = num2;
852
852
  b = this;
853
853
  }
854
854
  var carry = 0;
@@ -873,35 +873,35 @@ var require_bn = __commonJS({
873
873
  }
874
874
  return this;
875
875
  };
876
- BN.prototype.add = function add(num) {
876
+ BN.prototype.add = function add(num2) {
877
877
  var res;
878
- if (num.negative !== 0 && this.negative === 0) {
879
- num.negative = 0;
880
- res = this.sub(num);
881
- num.negative ^= 1;
878
+ if (num2.negative !== 0 && this.negative === 0) {
879
+ num2.negative = 0;
880
+ res = this.sub(num2);
881
+ num2.negative ^= 1;
882
882
  return res;
883
- } else if (num.negative === 0 && this.negative !== 0) {
883
+ } else if (num2.negative === 0 && this.negative !== 0) {
884
884
  this.negative = 0;
885
- res = num.sub(this);
885
+ res = num2.sub(this);
886
886
  this.negative = 1;
887
887
  return res;
888
888
  }
889
- if (this.length > num.length) return this.clone().iadd(num);
890
- return num.clone().iadd(this);
889
+ if (this.length > num2.length) return this.clone().iadd(num2);
890
+ return num2.clone().iadd(this);
891
891
  };
892
- BN.prototype.isub = function isub(num) {
893
- if (num.negative !== 0) {
894
- num.negative = 0;
895
- var r = this.iadd(num);
896
- num.negative = 1;
892
+ BN.prototype.isub = function isub(num2) {
893
+ if (num2.negative !== 0) {
894
+ num2.negative = 0;
895
+ var r = this.iadd(num2);
896
+ num2.negative = 1;
897
897
  return r._normSign();
898
898
  } else if (this.negative !== 0) {
899
899
  this.negative = 0;
900
- this.iadd(num);
900
+ this.iadd(num2);
901
901
  this.negative = 1;
902
902
  return this._normSign();
903
903
  }
904
- var cmp = this.cmp(num);
904
+ var cmp = this.cmp(num2);
905
905
  if (cmp === 0) {
906
906
  this.negative = 0;
907
907
  this.length = 1;
@@ -911,9 +911,9 @@ var require_bn = __commonJS({
911
911
  var a, b;
912
912
  if (cmp > 0) {
913
913
  a = this;
914
- b = num;
914
+ b = num2;
915
915
  } else {
916
- a = num;
916
+ a = num2;
917
917
  b = this;
918
918
  }
919
919
  var carry = 0;
@@ -938,16 +938,16 @@ var require_bn = __commonJS({
938
938
  }
939
939
  return this.strip();
940
940
  };
941
- BN.prototype.sub = function sub(num) {
942
- return this.clone().isub(num);
941
+ BN.prototype.sub = function sub(num2) {
942
+ return this.clone().isub(num2);
943
943
  };
944
- function smallMulTo(self2, num, out) {
945
- out.negative = num.negative ^ self2.negative;
946
- var len = self2.length + num.length | 0;
944
+ function smallMulTo(self2, num2, out) {
945
+ out.negative = num2.negative ^ self2.negative;
946
+ var len = self2.length + num2.length | 0;
947
947
  out.length = len;
948
948
  len = len - 1 | 0;
949
949
  var a = self2.words[0] | 0;
950
- var b = num.words[0] | 0;
950
+ var b = num2.words[0] | 0;
951
951
  var r = a * b;
952
952
  var lo = r & 67108863;
953
953
  var carry = r / 67108864 | 0;
@@ -955,11 +955,11 @@ var require_bn = __commonJS({
955
955
  for (var k = 1; k < len; k++) {
956
956
  var ncarry = carry >>> 26;
957
957
  var rword = carry & 67108863;
958
- var maxJ = Math.min(k, num.length - 1);
958
+ var maxJ = Math.min(k, num2.length - 1);
959
959
  for (var j = Math.max(0, k - self2.length + 1); j <= maxJ; j++) {
960
960
  var i = k - j | 0;
961
961
  a = self2.words[i] | 0;
962
- b = num.words[j] | 0;
962
+ b = num2.words[j] | 0;
963
963
  r = a * b + rword;
964
964
  ncarry += r / 67108864 | 0;
965
965
  rword = r & 67108863;
@@ -974,9 +974,9 @@ var require_bn = __commonJS({
974
974
  }
975
975
  return out.strip();
976
976
  }
977
- var comb10MulTo = function comb10MulTo2(self2, num, out) {
977
+ var comb10MulTo = function comb10MulTo2(self2, num2, out) {
978
978
  var a = self2.words;
979
- var b = num.words;
979
+ var b = num2.words;
980
980
  var o = out.words;
981
981
  var c = 0;
982
982
  var lo;
@@ -1042,7 +1042,7 @@ var require_bn = __commonJS({
1042
1042
  var b9 = b[9] | 0;
1043
1043
  var bl9 = b9 & 8191;
1044
1044
  var bh9 = b9 >>> 13;
1045
- out.negative = self2.negative ^ num.negative;
1045
+ out.negative = self2.negative ^ num2.negative;
1046
1046
  out.length = 19;
1047
1047
  lo = Math.imul(al0, bl0);
1048
1048
  mid = Math.imul(al0, bh0);
@@ -1529,20 +1529,20 @@ var require_bn = __commonJS({
1529
1529
  if (!Math.imul) {
1530
1530
  comb10MulTo = smallMulTo;
1531
1531
  }
1532
- function bigMulTo(self2, num, out) {
1533
- out.negative = num.negative ^ self2.negative;
1534
- out.length = self2.length + num.length;
1532
+ function bigMulTo(self2, num2, out) {
1533
+ out.negative = num2.negative ^ self2.negative;
1534
+ out.length = self2.length + num2.length;
1535
1535
  var carry = 0;
1536
1536
  var hncarry = 0;
1537
1537
  for (var k = 0; k < out.length - 1; k++) {
1538
1538
  var ncarry = hncarry;
1539
1539
  hncarry = 0;
1540
1540
  var rword = carry & 67108863;
1541
- var maxJ = Math.min(k, num.length - 1);
1541
+ var maxJ = Math.min(k, num2.length - 1);
1542
1542
  for (var j = Math.max(0, k - self2.length + 1); j <= maxJ; j++) {
1543
1543
  var i = k - j;
1544
1544
  var a = self2.words[i] | 0;
1545
- var b = num.words[j] | 0;
1545
+ var b = num2.words[j] | 0;
1546
1546
  var r = a * b;
1547
1547
  var lo = r & 67108863;
1548
1548
  ncarry = ncarry + (r / 67108864 | 0) | 0;
@@ -1563,21 +1563,21 @@ var require_bn = __commonJS({
1563
1563
  }
1564
1564
  return out.strip();
1565
1565
  }
1566
- function jumboMulTo(self2, num, out) {
1566
+ function jumboMulTo(self2, num2, out) {
1567
1567
  var fftm = new FFTM();
1568
- return fftm.mulp(self2, num, out);
1568
+ return fftm.mulp(self2, num2, out);
1569
1569
  }
1570
- BN.prototype.mulTo = function mulTo(num, out) {
1570
+ BN.prototype.mulTo = function mulTo(num2, out) {
1571
1571
  var res;
1572
- var len = this.length + num.length;
1573
- if (this.length === 10 && num.length === 10) {
1574
- res = comb10MulTo(this, num, out);
1572
+ var len = this.length + num2.length;
1573
+ if (this.length === 10 && num2.length === 10) {
1574
+ res = comb10MulTo(this, num2, out);
1575
1575
  } else if (len < 63) {
1576
- res = smallMulTo(this, num, out);
1576
+ res = smallMulTo(this, num2, out);
1577
1577
  } else if (len < 1024) {
1578
- res = bigMulTo(this, num, out);
1578
+ res = bigMulTo(this, num2, out);
1579
1579
  } else {
1580
- res = jumboMulTo(this, num, out);
1580
+ res = jumboMulTo(this, num2, out);
1581
1581
  }
1582
1582
  return res;
1583
1583
  };
@@ -1722,25 +1722,25 @@ var require_bn = __commonJS({
1722
1722
  out.length = x.length + y.length;
1723
1723
  return out.strip();
1724
1724
  };
1725
- BN.prototype.mul = function mul(num) {
1725
+ BN.prototype.mul = function mul(num2) {
1726
1726
  var out = new BN(null);
1727
- out.words = new Array(this.length + num.length);
1728
- return this.mulTo(num, out);
1727
+ out.words = new Array(this.length + num2.length);
1728
+ return this.mulTo(num2, out);
1729
1729
  };
1730
- BN.prototype.mulf = function mulf(num) {
1730
+ BN.prototype.mulf = function mulf(num2) {
1731
1731
  var out = new BN(null);
1732
- out.words = new Array(this.length + num.length);
1733
- return jumboMulTo(this, num, out);
1732
+ out.words = new Array(this.length + num2.length);
1733
+ return jumboMulTo(this, num2, out);
1734
1734
  };
1735
- BN.prototype.imul = function imul(num) {
1736
- return this.clone().mulTo(num, this);
1735
+ BN.prototype.imul = function imul(num2) {
1736
+ return this.clone().mulTo(num2, this);
1737
1737
  };
1738
- BN.prototype.imuln = function imuln(num) {
1739
- assert(typeof num === "number");
1740
- assert(num < 67108864);
1738
+ BN.prototype.imuln = function imuln(num2) {
1739
+ assert(typeof num2 === "number");
1740
+ assert(num2 < 67108864);
1741
1741
  var carry = 0;
1742
1742
  for (var i = 0; i < this.length; i++) {
1743
- var w = (this.words[i] | 0) * num;
1743
+ var w = (this.words[i] | 0) * num2;
1744
1744
  var lo = (w & 67108863) + (carry & 67108863);
1745
1745
  carry >>= 26;
1746
1746
  carry += w / 67108864 | 0;
@@ -1751,11 +1751,11 @@ var require_bn = __commonJS({
1751
1751
  this.words[i] = carry;
1752
1752
  this.length++;
1753
1753
  }
1754
- this.length = num === 0 ? 1 : this.length;
1754
+ this.length = num2 === 0 ? 1 : this.length;
1755
1755
  return this;
1756
1756
  };
1757
- BN.prototype.muln = function muln(num) {
1758
- return this.clone().imuln(num);
1757
+ BN.prototype.muln = function muln(num2) {
1758
+ return this.clone().imuln(num2);
1759
1759
  };
1760
1760
  BN.prototype.sqr = function sqr() {
1761
1761
  return this.mul(this);
@@ -1763,8 +1763,8 @@ var require_bn = __commonJS({
1763
1763
  BN.prototype.isqr = function isqr() {
1764
1764
  return this.imul(this.clone());
1765
1765
  };
1766
- BN.prototype.pow = function pow(num) {
1767
- var w = toBitArray(num);
1766
+ BN.prototype.pow = function pow(num2) {
1767
+ var w = toBitArray(num2);
1768
1768
  if (w.length === 0) return new BN(1);
1769
1769
  var res = this;
1770
1770
  for (var i = 0; i < w.length; i++, res = res.sqr()) {
@@ -1906,25 +1906,25 @@ var require_bn = __commonJS({
1906
1906
  BN.prototype.maskn = function maskn(bits) {
1907
1907
  return this.clone().imaskn(bits);
1908
1908
  };
1909
- BN.prototype.iaddn = function iaddn(num) {
1910
- assert(typeof num === "number");
1911
- assert(num < 67108864);
1912
- if (num < 0) return this.isubn(-num);
1909
+ BN.prototype.iaddn = function iaddn(num2) {
1910
+ assert(typeof num2 === "number");
1911
+ assert(num2 < 67108864);
1912
+ if (num2 < 0) return this.isubn(-num2);
1913
1913
  if (this.negative !== 0) {
1914
- if (this.length === 1 && (this.words[0] | 0) < num) {
1915
- this.words[0] = num - (this.words[0] | 0);
1914
+ if (this.length === 1 && (this.words[0] | 0) < num2) {
1915
+ this.words[0] = num2 - (this.words[0] | 0);
1916
1916
  this.negative = 0;
1917
1917
  return this;
1918
1918
  }
1919
1919
  this.negative = 0;
1920
- this.isubn(num);
1920
+ this.isubn(num2);
1921
1921
  this.negative = 1;
1922
1922
  return this;
1923
1923
  }
1924
- return this._iaddn(num);
1924
+ return this._iaddn(num2);
1925
1925
  };
1926
- BN.prototype._iaddn = function _iaddn(num) {
1927
- this.words[0] += num;
1926
+ BN.prototype._iaddn = function _iaddn(num2) {
1927
+ this.words[0] += num2;
1928
1928
  for (var i = 0; i < this.length && this.words[i] >= 67108864; i++) {
1929
1929
  this.words[i] -= 67108864;
1930
1930
  if (i === this.length - 1) {
@@ -1936,17 +1936,17 @@ var require_bn = __commonJS({
1936
1936
  this.length = Math.max(this.length, i + 1);
1937
1937
  return this;
1938
1938
  };
1939
- BN.prototype.isubn = function isubn(num) {
1940
- assert(typeof num === "number");
1941
- assert(num < 67108864);
1942
- if (num < 0) return this.iaddn(-num);
1939
+ BN.prototype.isubn = function isubn(num2) {
1940
+ assert(typeof num2 === "number");
1941
+ assert(num2 < 67108864);
1942
+ if (num2 < 0) return this.iaddn(-num2);
1943
1943
  if (this.negative !== 0) {
1944
1944
  this.negative = 0;
1945
- this.iaddn(num);
1945
+ this.iaddn(num2);
1946
1946
  this.negative = 1;
1947
1947
  return this;
1948
1948
  }
1949
- this.words[0] -= num;
1949
+ this.words[0] -= num2;
1950
1950
  if (this.length === 1 && this.words[0] < 0) {
1951
1951
  this.words[0] = -this.words[0];
1952
1952
  this.negative = 1;
@@ -1958,11 +1958,11 @@ var require_bn = __commonJS({
1958
1958
  }
1959
1959
  return this.strip();
1960
1960
  };
1961
- BN.prototype.addn = function addn(num) {
1962
- return this.clone().iaddn(num);
1961
+ BN.prototype.addn = function addn(num2) {
1962
+ return this.clone().iaddn(num2);
1963
1963
  };
1964
- BN.prototype.subn = function subn(num) {
1965
- return this.clone().isubn(num);
1964
+ BN.prototype.subn = function subn(num2) {
1965
+ return this.clone().isubn(num2);
1966
1966
  };
1967
1967
  BN.prototype.iabs = function iabs() {
1968
1968
  this.negative = 0;
@@ -1971,15 +1971,15 @@ var require_bn = __commonJS({
1971
1971
  BN.prototype.abs = function abs() {
1972
1972
  return this.clone().iabs();
1973
1973
  };
1974
- BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
1975
- var len = num.length + shift;
1974
+ BN.prototype._ishlnsubmul = function _ishlnsubmul(num2, mul, shift) {
1975
+ var len = num2.length + shift;
1976
1976
  var i;
1977
1977
  this._expand(len);
1978
1978
  var w;
1979
1979
  var carry = 0;
1980
- for (i = 0; i < num.length; i++) {
1980
+ for (i = 0; i < num2.length; i++) {
1981
1981
  w = (this.words[i + shift] | 0) + carry;
1982
- var right = (num.words[i] | 0) * mul;
1982
+ var right = (num2.words[i] | 0) * mul;
1983
1983
  w -= right & 67108863;
1984
1984
  carry = (w >> 26) - (right / 67108864 | 0);
1985
1985
  this.words[i + shift] = w & 67108863;
@@ -2000,10 +2000,10 @@ var require_bn = __commonJS({
2000
2000
  this.negative = 1;
2001
2001
  return this.strip();
2002
2002
  };
2003
- BN.prototype._wordDiv = function _wordDiv(num, mode) {
2004
- var shift = this.length - num.length;
2003
+ BN.prototype._wordDiv = function _wordDiv(num2, mode) {
2004
+ var shift = this.length - num2.length;
2005
2005
  var a = this.clone();
2006
- var b = num;
2006
+ var b = num2;
2007
2007
  var bhi = b.words[b.length - 1] | 0;
2008
2008
  var bhiBits = this._countBits(bhi);
2009
2009
  shift = 26 - bhiBits;
@@ -2057,8 +2057,8 @@ var require_bn = __commonJS({
2057
2057
  mod: a
2058
2058
  };
2059
2059
  };
2060
- BN.prototype.divmod = function divmod(num, mode, positive) {
2061
- assert(!num.isZero());
2060
+ BN.prototype.divmod = function divmod(num2, mode, positive) {
2061
+ assert(!num2.isZero());
2062
2062
  if (this.isZero()) {
2063
2063
  return {
2064
2064
  div: new BN(0),
@@ -2066,15 +2066,15 @@ var require_bn = __commonJS({
2066
2066
  };
2067
2067
  }
2068
2068
  var div, mod, res;
2069
- if (this.negative !== 0 && num.negative === 0) {
2070
- res = this.neg().divmod(num, mode);
2069
+ if (this.negative !== 0 && num2.negative === 0) {
2070
+ res = this.neg().divmod(num2, mode);
2071
2071
  if (mode !== "mod") {
2072
2072
  div = res.div.neg();
2073
2073
  }
2074
2074
  if (mode !== "div") {
2075
2075
  mod = res.mod.neg();
2076
2076
  if (positive && mod.negative !== 0) {
2077
- mod.iadd(num);
2077
+ mod.iadd(num2);
2078
2078
  }
2079
2079
  }
2080
2080
  return {
@@ -2082,8 +2082,8 @@ var require_bn = __commonJS({
2082
2082
  mod
2083
2083
  };
2084
2084
  }
2085
- if (this.negative === 0 && num.negative !== 0) {
2086
- res = this.divmod(num.neg(), mode);
2085
+ if (this.negative === 0 && num2.negative !== 0) {
2086
+ res = this.divmod(num2.neg(), mode);
2087
2087
  if (mode !== "mod") {
2088
2088
  div = res.div.neg();
2089
2089
  }
@@ -2092,12 +2092,12 @@ var require_bn = __commonJS({
2092
2092
  mod: res.mod
2093
2093
  };
2094
2094
  }
2095
- if ((this.negative & num.negative) !== 0) {
2096
- res = this.neg().divmod(num.neg(), mode);
2095
+ if ((this.negative & num2.negative) !== 0) {
2096
+ res = this.neg().divmod(num2.neg(), mode);
2097
2097
  if (mode !== "div") {
2098
2098
  mod = res.mod.neg();
2099
2099
  if (positive && mod.negative !== 0) {
2100
- mod.isub(num);
2100
+ mod.isub(num2);
2101
2101
  }
2102
2102
  }
2103
2103
  return {
@@ -2105,72 +2105,72 @@ var require_bn = __commonJS({
2105
2105
  mod
2106
2106
  };
2107
2107
  }
2108
- if (num.length > this.length || this.cmp(num) < 0) {
2108
+ if (num2.length > this.length || this.cmp(num2) < 0) {
2109
2109
  return {
2110
2110
  div: new BN(0),
2111
2111
  mod: this
2112
2112
  };
2113
2113
  }
2114
- if (num.length === 1) {
2114
+ if (num2.length === 1) {
2115
2115
  if (mode === "div") {
2116
2116
  return {
2117
- div: this.divn(num.words[0]),
2117
+ div: this.divn(num2.words[0]),
2118
2118
  mod: null
2119
2119
  };
2120
2120
  }
2121
2121
  if (mode === "mod") {
2122
2122
  return {
2123
2123
  div: null,
2124
- mod: new BN(this.modn(num.words[0]))
2124
+ mod: new BN(this.modn(num2.words[0]))
2125
2125
  };
2126
2126
  }
2127
2127
  return {
2128
- div: this.divn(num.words[0]),
2129
- mod: new BN(this.modn(num.words[0]))
2128
+ div: this.divn(num2.words[0]),
2129
+ mod: new BN(this.modn(num2.words[0]))
2130
2130
  };
2131
2131
  }
2132
- return this._wordDiv(num, mode);
2132
+ return this._wordDiv(num2, mode);
2133
2133
  };
2134
- BN.prototype.div = function div(num) {
2135
- return this.divmod(num, "div", false).div;
2134
+ BN.prototype.div = function div(num2) {
2135
+ return this.divmod(num2, "div", false).div;
2136
2136
  };
2137
- BN.prototype.mod = function mod(num) {
2138
- return this.divmod(num, "mod", false).mod;
2137
+ BN.prototype.mod = function mod(num2) {
2138
+ return this.divmod(num2, "mod", false).mod;
2139
2139
  };
2140
- BN.prototype.umod = function umod(num) {
2141
- return this.divmod(num, "mod", true).mod;
2140
+ BN.prototype.umod = function umod(num2) {
2141
+ return this.divmod(num2, "mod", true).mod;
2142
2142
  };
2143
- BN.prototype.divRound = function divRound(num) {
2144
- var dm = this.divmod(num);
2143
+ BN.prototype.divRound = function divRound(num2) {
2144
+ var dm = this.divmod(num2);
2145
2145
  if (dm.mod.isZero()) return dm.div;
2146
- var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
2147
- var half = num.ushrn(1);
2148
- var r2 = num.andln(1);
2146
+ var mod = dm.div.negative !== 0 ? dm.mod.isub(num2) : dm.mod;
2147
+ var half = num2.ushrn(1);
2148
+ var r2 = num2.andln(1);
2149
2149
  var cmp = mod.cmp(half);
2150
2150
  if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
2151
2151
  return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
2152
2152
  };
2153
- BN.prototype.modn = function modn(num) {
2154
- assert(num <= 67108863);
2155
- var p = (1 << 26) % num;
2153
+ BN.prototype.modn = function modn(num2) {
2154
+ assert(num2 <= 67108863);
2155
+ var p = (1 << 26) % num2;
2156
2156
  var acc = 0;
2157
2157
  for (var i = this.length - 1; i >= 0; i--) {
2158
- acc = (p * acc + (this.words[i] | 0)) % num;
2158
+ acc = (p * acc + (this.words[i] | 0)) % num2;
2159
2159
  }
2160
2160
  return acc;
2161
2161
  };
2162
- BN.prototype.idivn = function idivn(num) {
2163
- assert(num <= 67108863);
2162
+ BN.prototype.idivn = function idivn(num2) {
2163
+ assert(num2 <= 67108863);
2164
2164
  var carry = 0;
2165
2165
  for (var i = this.length - 1; i >= 0; i--) {
2166
2166
  var w = (this.words[i] | 0) + carry * 67108864;
2167
- this.words[i] = w / num | 0;
2168
- carry = w % num;
2167
+ this.words[i] = w / num2 | 0;
2168
+ carry = w % num2;
2169
2169
  }
2170
2170
  return this.strip();
2171
2171
  };
2172
- BN.prototype.divn = function divn(num) {
2173
- return this.clone().idivn(num);
2172
+ BN.prototype.divn = function divn(num2) {
2173
+ return this.clone().idivn(num2);
2174
2174
  };
2175
2175
  BN.prototype.egcd = function egcd(p) {
2176
2176
  assert(p.negative === 0);
@@ -2288,11 +2288,11 @@ var require_bn = __commonJS({
2288
2288
  }
2289
2289
  return res;
2290
2290
  };
2291
- BN.prototype.gcd = function gcd(num) {
2292
- if (this.isZero()) return num.abs();
2293
- if (num.isZero()) return this.abs();
2291
+ BN.prototype.gcd = function gcd(num2) {
2292
+ if (this.isZero()) return num2.abs();
2293
+ if (num2.isZero()) return this.abs();
2294
2294
  var a = this.clone();
2295
- var b = num.clone();
2295
+ var b = num2.clone();
2296
2296
  a.negative = 0;
2297
2297
  b.negative = 0;
2298
2298
  for (var shift = 0; a.isEven() && b.isEven(); shift++) {
@@ -2318,8 +2318,8 @@ var require_bn = __commonJS({
2318
2318
  } while (true);
2319
2319
  return b.iushln(shift);
2320
2320
  };
2321
- BN.prototype.invm = function invm(num) {
2322
- return this.egcd(num).a.umod(num);
2321
+ BN.prototype.invm = function invm(num2) {
2322
+ return this.egcd(num2).a.umod(num2);
2323
2323
  };
2324
2324
  BN.prototype.isEven = function isEven() {
2325
2325
  return (this.words[0] & 1) === 0;
@@ -2327,8 +2327,8 @@ var require_bn = __commonJS({
2327
2327
  BN.prototype.isOdd = function isOdd() {
2328
2328
  return (this.words[0] & 1) === 1;
2329
2329
  };
2330
- BN.prototype.andln = function andln(num) {
2331
- return this.words[0] & num;
2330
+ BN.prototype.andln = function andln(num2) {
2331
+ return this.words[0] & num2;
2332
2332
  };
2333
2333
  BN.prototype.bincn = function bincn(bit) {
2334
2334
  assert(typeof bit === "number");
@@ -2357,8 +2357,8 @@ var require_bn = __commonJS({
2357
2357
  BN.prototype.isZero = function isZero() {
2358
2358
  return this.length === 1 && this.words[0] === 0;
2359
2359
  };
2360
- BN.prototype.cmpn = function cmpn(num) {
2361
- var negative = num < 0;
2360
+ BN.prototype.cmpn = function cmpn(num2) {
2361
+ var negative = num2 < 0;
2362
2362
  if (this.negative !== 0 && !negative) return -1;
2363
2363
  if (this.negative === 0 && negative) return 1;
2364
2364
  this.strip();
@@ -2367,29 +2367,29 @@ var require_bn = __commonJS({
2367
2367
  res = 1;
2368
2368
  } else {
2369
2369
  if (negative) {
2370
- num = -num;
2370
+ num2 = -num2;
2371
2371
  }
2372
- assert(num <= 67108863, "Number is too big");
2372
+ assert(num2 <= 67108863, "Number is too big");
2373
2373
  var w = this.words[0] | 0;
2374
- res = w === num ? 0 : w < num ? -1 : 1;
2374
+ res = w === num2 ? 0 : w < num2 ? -1 : 1;
2375
2375
  }
2376
2376
  if (this.negative !== 0) return -res | 0;
2377
2377
  return res;
2378
2378
  };
2379
- BN.prototype.cmp = function cmp(num) {
2380
- if (this.negative !== 0 && num.negative === 0) return -1;
2381
- if (this.negative === 0 && num.negative !== 0) return 1;
2382
- var res = this.ucmp(num);
2379
+ BN.prototype.cmp = function cmp(num2) {
2380
+ if (this.negative !== 0 && num2.negative === 0) return -1;
2381
+ if (this.negative === 0 && num2.negative !== 0) return 1;
2382
+ var res = this.ucmp(num2);
2383
2383
  if (this.negative !== 0) return -res | 0;
2384
2384
  return res;
2385
2385
  };
2386
- BN.prototype.ucmp = function ucmp(num) {
2387
- if (this.length > num.length) return 1;
2388
- if (this.length < num.length) return -1;
2386
+ BN.prototype.ucmp = function ucmp(num2) {
2387
+ if (this.length > num2.length) return 1;
2388
+ if (this.length < num2.length) return -1;
2389
2389
  var res = 0;
2390
2390
  for (var i = this.length - 1; i >= 0; i--) {
2391
2391
  var a = this.words[i] | 0;
2392
- var b = num.words[i] | 0;
2392
+ var b = num2.words[i] | 0;
2393
2393
  if (a === b) continue;
2394
2394
  if (a < b) {
2395
2395
  res = -1;
@@ -2400,38 +2400,38 @@ var require_bn = __commonJS({
2400
2400
  }
2401
2401
  return res;
2402
2402
  };
2403
- BN.prototype.gtn = function gtn(num) {
2404
- return this.cmpn(num) === 1;
2403
+ BN.prototype.gtn = function gtn(num2) {
2404
+ return this.cmpn(num2) === 1;
2405
2405
  };
2406
- BN.prototype.gt = function gt(num) {
2407
- return this.cmp(num) === 1;
2406
+ BN.prototype.gt = function gt(num2) {
2407
+ return this.cmp(num2) === 1;
2408
2408
  };
2409
- BN.prototype.gten = function gten(num) {
2410
- return this.cmpn(num) >= 0;
2409
+ BN.prototype.gten = function gten(num2) {
2410
+ return this.cmpn(num2) >= 0;
2411
2411
  };
2412
- BN.prototype.gte = function gte(num) {
2413
- return this.cmp(num) >= 0;
2412
+ BN.prototype.gte = function gte(num2) {
2413
+ return this.cmp(num2) >= 0;
2414
2414
  };
2415
- BN.prototype.ltn = function ltn(num) {
2416
- return this.cmpn(num) === -1;
2415
+ BN.prototype.ltn = function ltn(num2) {
2416
+ return this.cmpn(num2) === -1;
2417
2417
  };
2418
- BN.prototype.lt = function lt(num) {
2419
- return this.cmp(num) === -1;
2418
+ BN.prototype.lt = function lt(num2) {
2419
+ return this.cmp(num2) === -1;
2420
2420
  };
2421
- BN.prototype.lten = function lten(num) {
2422
- return this.cmpn(num) <= 0;
2421
+ BN.prototype.lten = function lten(num2) {
2422
+ return this.cmpn(num2) <= 0;
2423
2423
  };
2424
- BN.prototype.lte = function lte(num) {
2425
- return this.cmp(num) <= 0;
2424
+ BN.prototype.lte = function lte(num2) {
2425
+ return this.cmp(num2) <= 0;
2426
2426
  };
2427
- BN.prototype.eqn = function eqn(num) {
2428
- return this.cmpn(num) === 0;
2427
+ BN.prototype.eqn = function eqn(num2) {
2428
+ return this.cmpn(num2) === 0;
2429
2429
  };
2430
- BN.prototype.eq = function eq(num) {
2431
- return this.cmp(num) === 0;
2430
+ BN.prototype.eq = function eq(num2) {
2431
+ return this.cmp(num2) === 0;
2432
2432
  };
2433
- BN.red = function red(num) {
2434
- return new Red(num);
2433
+ BN.red = function red(num2) {
2434
+ return new Red(num2);
2435
2435
  };
2436
2436
  BN.prototype.toRed = function toRed(ctx) {
2437
2437
  assert(!this.red, "Already a number in reduction context");
@@ -2450,35 +2450,35 @@ var require_bn = __commonJS({
2450
2450
  assert(!this.red, "Already a number in reduction context");
2451
2451
  return this._forceRed(ctx);
2452
2452
  };
2453
- BN.prototype.redAdd = function redAdd(num) {
2453
+ BN.prototype.redAdd = function redAdd(num2) {
2454
2454
  assert(this.red, "redAdd works only with red numbers");
2455
- return this.red.add(this, num);
2455
+ return this.red.add(this, num2);
2456
2456
  };
2457
- BN.prototype.redIAdd = function redIAdd(num) {
2457
+ BN.prototype.redIAdd = function redIAdd(num2) {
2458
2458
  assert(this.red, "redIAdd works only with red numbers");
2459
- return this.red.iadd(this, num);
2459
+ return this.red.iadd(this, num2);
2460
2460
  };
2461
- BN.prototype.redSub = function redSub(num) {
2461
+ BN.prototype.redSub = function redSub(num2) {
2462
2462
  assert(this.red, "redSub works only with red numbers");
2463
- return this.red.sub(this, num);
2463
+ return this.red.sub(this, num2);
2464
2464
  };
2465
- BN.prototype.redISub = function redISub(num) {
2465
+ BN.prototype.redISub = function redISub(num2) {
2466
2466
  assert(this.red, "redISub works only with red numbers");
2467
- return this.red.isub(this, num);
2467
+ return this.red.isub(this, num2);
2468
2468
  };
2469
- BN.prototype.redShl = function redShl(num) {
2469
+ BN.prototype.redShl = function redShl(num2) {
2470
2470
  assert(this.red, "redShl works only with red numbers");
2471
- return this.red.shl(this, num);
2471
+ return this.red.shl(this, num2);
2472
2472
  };
2473
- BN.prototype.redMul = function redMul(num) {
2473
+ BN.prototype.redMul = function redMul(num2) {
2474
2474
  assert(this.red, "redMul works only with red numbers");
2475
- this.red._verify2(this, num);
2476
- return this.red.mul(this, num);
2475
+ this.red._verify2(this, num2);
2476
+ return this.red.mul(this, num2);
2477
2477
  };
2478
- BN.prototype.redIMul = function redIMul(num) {
2478
+ BN.prototype.redIMul = function redIMul(num2) {
2479
2479
  assert(this.red, "redMul works only with red numbers");
2480
- this.red._verify2(this, num);
2481
- return this.red.imul(this, num);
2480
+ this.red._verify2(this, num2);
2481
+ return this.red.imul(this, num2);
2482
2482
  };
2483
2483
  BN.prototype.redSqr = function redSqr() {
2484
2484
  assert(this.red, "redSqr works only with red numbers");
@@ -2505,10 +2505,10 @@ var require_bn = __commonJS({
2505
2505
  this.red._verify1(this);
2506
2506
  return this.red.neg(this);
2507
2507
  };
2508
- BN.prototype.redPow = function redPow(num) {
2509
- assert(this.red && !num.red, "redPow(normalNum)");
2508
+ BN.prototype.redPow = function redPow(num2) {
2509
+ assert(this.red && !num2.red, "redPow(normalNum)");
2510
2510
  this.red._verify1(this);
2511
- return this.red.pow(this, num);
2511
+ return this.red.pow(this, num2);
2512
2512
  };
2513
2513
  var primes = {
2514
2514
  k256: null,
@@ -2528,8 +2528,8 @@ var require_bn = __commonJS({
2528
2528
  tmp.words = new Array(Math.ceil(this.n / 13));
2529
2529
  return tmp;
2530
2530
  };
2531
- MPrime.prototype.ireduce = function ireduce(num) {
2532
- var r = num;
2531
+ MPrime.prototype.ireduce = function ireduce(num2) {
2532
+ var r = num2;
2533
2533
  var rlen;
2534
2534
  do {
2535
2535
  this.split(r, this.tmp);
@@ -2555,8 +2555,8 @@ var require_bn = __commonJS({
2555
2555
  MPrime.prototype.split = function split(input, out) {
2556
2556
  input.iushrn(this.n, 0, out);
2557
2557
  };
2558
- MPrime.prototype.imulK = function imulK(num) {
2559
- return num.imul(this.k);
2558
+ MPrime.prototype.imulK = function imulK(num2) {
2559
+ return num2.imul(this.k);
2560
2560
  };
2561
2561
  function K256() {
2562
2562
  MPrime.call(
@@ -2593,24 +2593,24 @@ var require_bn = __commonJS({
2593
2593
  input.length -= 9;
2594
2594
  }
2595
2595
  };
2596
- K256.prototype.imulK = function imulK(num) {
2597
- num.words[num.length] = 0;
2598
- num.words[num.length + 1] = 0;
2599
- num.length += 2;
2596
+ K256.prototype.imulK = function imulK(num2) {
2597
+ num2.words[num2.length] = 0;
2598
+ num2.words[num2.length + 1] = 0;
2599
+ num2.length += 2;
2600
2600
  var lo = 0;
2601
- for (var i = 0; i < num.length; i++) {
2602
- var w = num.words[i] | 0;
2601
+ for (var i = 0; i < num2.length; i++) {
2602
+ var w = num2.words[i] | 0;
2603
2603
  lo += w * 977;
2604
- num.words[i] = lo & 67108863;
2604
+ num2.words[i] = lo & 67108863;
2605
2605
  lo = w * 64 + (lo / 67108864 | 0);
2606
2606
  }
2607
- if (num.words[num.length - 1] === 0) {
2608
- num.length--;
2609
- if (num.words[num.length - 1] === 0) {
2610
- num.length--;
2607
+ if (num2.words[num2.length - 1] === 0) {
2608
+ num2.length--;
2609
+ if (num2.words[num2.length - 1] === 0) {
2610
+ num2.length--;
2611
2611
  }
2612
2612
  }
2613
- return num;
2613
+ return num2;
2614
2614
  };
2615
2615
  function P224() {
2616
2616
  MPrime.call(
@@ -2636,19 +2636,19 @@ var require_bn = __commonJS({
2636
2636
  );
2637
2637
  }
2638
2638
  inherits(P25519, MPrime);
2639
- P25519.prototype.imulK = function imulK(num) {
2639
+ P25519.prototype.imulK = function imulK(num2) {
2640
2640
  var carry = 0;
2641
- for (var i = 0; i < num.length; i++) {
2642
- var hi = (num.words[i] | 0) * 19 + carry;
2641
+ for (var i = 0; i < num2.length; i++) {
2642
+ var hi = (num2.words[i] | 0) * 19 + carry;
2643
2643
  var lo = hi & 67108863;
2644
2644
  hi >>>= 26;
2645
- num.words[i] = lo;
2645
+ num2.words[i] = lo;
2646
2646
  carry = hi;
2647
2647
  }
2648
2648
  if (carry !== 0) {
2649
- num.words[num.length++] = carry;
2649
+ num2.words[num2.length++] = carry;
2650
2650
  }
2651
- return num;
2651
+ return num2;
2652
2652
  };
2653
2653
  BN._prime = function prime(name) {
2654
2654
  if (primes[name]) return primes[name];
@@ -2731,9 +2731,9 @@ var require_bn = __commonJS({
2731
2731
  }
2732
2732
  return res;
2733
2733
  };
2734
- Red.prototype.shl = function shl(a, num) {
2734
+ Red.prototype.shl = function shl(a, num2) {
2735
2735
  this._verify1(a);
2736
- return this.imod(a.ushln(num));
2736
+ return this.imod(a.ushln(num2));
2737
2737
  };
2738
2738
  Red.prototype.imul = function imul(a, b) {
2739
2739
  this._verify2(a, b);
@@ -2799,9 +2799,9 @@ var require_bn = __commonJS({
2799
2799
  return this.imod(inv);
2800
2800
  }
2801
2801
  };
2802
- Red.prototype.pow = function pow(a, num) {
2803
- if (num.isZero()) return new BN(1).toRed(this);
2804
- if (num.cmpn(1) === 0) return a.clone();
2802
+ Red.prototype.pow = function pow(a, num2) {
2803
+ if (num2.isZero()) return new BN(1).toRed(this);
2804
+ if (num2.cmpn(1) === 0) return a.clone();
2805
2805
  var windowSize = 4;
2806
2806
  var wnd = new Array(1 << windowSize);
2807
2807
  wnd[0] = new BN(1).toRed(this);
@@ -2812,12 +2812,12 @@ var require_bn = __commonJS({
2812
2812
  var res = wnd[0];
2813
2813
  var current = 0;
2814
2814
  var currentLen = 0;
2815
- var start = num.bitLength() % 26;
2815
+ var start = num2.bitLength() % 26;
2816
2816
  if (start === 0) {
2817
2817
  start = 26;
2818
2818
  }
2819
- for (i = num.length - 1; i >= 0; i--) {
2820
- var word = num.words[i];
2819
+ for (i = num2.length - 1; i >= 0; i--) {
2820
+ var word = num2.words[i];
2821
2821
  for (var j = start - 1; j >= 0; j--) {
2822
2822
  var bit = word >> j & 1;
2823
2823
  if (res !== wnd[0]) {
@@ -2839,17 +2839,17 @@ var require_bn = __commonJS({
2839
2839
  }
2840
2840
  return res;
2841
2841
  };
2842
- Red.prototype.convertTo = function convertTo(num) {
2843
- var r = num.umod(this.m);
2844
- return r === num ? r.clone() : r;
2842
+ Red.prototype.convertTo = function convertTo(num2) {
2843
+ var r = num2.umod(this.m);
2844
+ return r === num2 ? r.clone() : r;
2845
2845
  };
2846
- Red.prototype.convertFrom = function convertFrom(num) {
2847
- var res = num.clone();
2846
+ Red.prototype.convertFrom = function convertFrom(num2) {
2847
+ var res = num2.clone();
2848
2848
  res.red = null;
2849
2849
  return res;
2850
2850
  };
2851
- BN.mont = function mont(num) {
2852
- return new Mont(num);
2851
+ BN.mont = function mont(num2) {
2852
+ return new Mont(num2);
2853
2853
  };
2854
2854
  function Mont(m) {
2855
2855
  Red.call(this, m);
@@ -2865,11 +2865,11 @@ var require_bn = __commonJS({
2865
2865
  this.minv = this.r.sub(this.minv);
2866
2866
  }
2867
2867
  inherits(Mont, Red);
2868
- Mont.prototype.convertTo = function convertTo(num) {
2869
- return this.imod(num.ushln(this.shift));
2868
+ Mont.prototype.convertTo = function convertTo(num2) {
2869
+ return this.imod(num2.ushln(this.shift));
2870
2870
  };
2871
- Mont.prototype.convertFrom = function convertFrom(num) {
2872
- var r = this.imod(num.mul(this.rinv));
2871
+ Mont.prototype.convertFrom = function convertFrom(num2) {
2872
+ var r = this.imod(num2.mul(this.rinv));
2873
2873
  r.red = null;
2874
2874
  return r;
2875
2875
  };
@@ -2996,14 +2996,14 @@ var require_utils2 = __commonJS({
2996
2996
  utils.zero2 = minUtils.zero2;
2997
2997
  utils.toHex = minUtils.toHex;
2998
2998
  utils.encode = minUtils.encode;
2999
- function getNAF(num, w, bits) {
3000
- var naf = new Array(Math.max(num.bitLength(), bits) + 1);
2999
+ function getNAF(num2, w, bits) {
3000
+ var naf = new Array(Math.max(num2.bitLength(), bits) + 1);
3001
3001
  var i;
3002
3002
  for (i = 0; i < naf.length; i += 1) {
3003
3003
  naf[i] = 0;
3004
3004
  }
3005
3005
  var ws = 1 << w + 1;
3006
- var k = num.clone();
3006
+ var k = num2.clone();
3007
3007
  for (i = 0; i < naf.length; i++) {
3008
3008
  var z;
3009
3009
  var mod = k.andln(ws - 1);
@@ -3565,8 +3565,8 @@ var require_short = __commonJS({
3565
3565
  basis
3566
3566
  };
3567
3567
  };
3568
- ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) {
3569
- var red = num === this.p ? this.red : BN.mont(num);
3568
+ ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num2) {
3569
+ var red = num2 === this.p ? this.red : BN.mont(num2);
3570
3570
  var tinv = new BN(2).toRed(red).redInvm();
3571
3571
  var ntinv = tinv.redNeg();
3572
3572
  var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);
@@ -4352,17 +4352,17 @@ var require_edwards = __commonJS({
4352
4352
  }
4353
4353
  inherits(EdwardsCurve, Base);
4354
4354
  module.exports = EdwardsCurve;
4355
- EdwardsCurve.prototype._mulA = function _mulA(num) {
4355
+ EdwardsCurve.prototype._mulA = function _mulA(num2) {
4356
4356
  if (this.mOneA)
4357
- return num.redNeg();
4357
+ return num2.redNeg();
4358
4358
  else
4359
- return this.a.redMul(num);
4359
+ return this.a.redMul(num2);
4360
4360
  };
4361
- EdwardsCurve.prototype._mulC = function _mulC(num) {
4361
+ EdwardsCurve.prototype._mulC = function _mulC(num2) {
4362
4362
  if (this.oneC)
4363
- return num;
4363
+ return num2;
4364
4364
  else
4365
- return this.c.redMul(num);
4365
+ return this.c.redMul(num2);
4366
4366
  };
4367
4367
  EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) {
4368
4368
  return this.point(x, y, z, t);
@@ -4861,22 +4861,22 @@ var require_utils3 = __commonJS({
4861
4861
  return lo >>> 0;
4862
4862
  }
4863
4863
  exports.sum64_5_lo = sum64_5_lo;
4864
- function rotr64_hi(ah, al, num) {
4865
- var r = al << 32 - num | ah >>> num;
4864
+ function rotr64_hi(ah, al, num2) {
4865
+ var r = al << 32 - num2 | ah >>> num2;
4866
4866
  return r >>> 0;
4867
4867
  }
4868
4868
  exports.rotr64_hi = rotr64_hi;
4869
- function rotr64_lo(ah, al, num) {
4870
- var r = ah << 32 - num | al >>> num;
4869
+ function rotr64_lo(ah, al, num2) {
4870
+ var r = ah << 32 - num2 | al >>> num2;
4871
4871
  return r >>> 0;
4872
4872
  }
4873
4873
  exports.rotr64_lo = rotr64_lo;
4874
- function shr64_hi(ah, al, num) {
4875
- return ah >>> num;
4874
+ function shr64_hi(ah, al, num2) {
4875
+ return ah >>> num2;
4876
4876
  }
4877
4877
  exports.shr64_hi = shr64_hi;
4878
- function shr64_lo(ah, al, num) {
4879
- var r = ah << 32 - num | al >>> num;
4878
+ function shr64_lo(ah, al, num2) {
4879
+ var r = ah << 32 - num2 | al >>> num2;
4880
4880
  return r >>> 0;
4881
4881
  }
4882
4882
  exports.shr64_lo = shr64_lo;
@@ -7957,8 +7957,8 @@ var require_eddsa = __commonJS({
7957
7957
  var y = utils.intFromLE(normed);
7958
7958
  return this.curve.pointFromY(y, xIsOdd);
7959
7959
  };
7960
- EDDSA.prototype.encodeInt = function encodeInt(num) {
7961
- return num.toArray("le", this.encodingLength);
7960
+ EDDSA.prototype.encodeInt = function encodeInt(num2) {
7961
+ return num2.toArray("le", this.encodingLength);
7962
7962
  };
7963
7963
  EDDSA.prototype.decodeInt = function decodeInt(bytes) {
7964
7964
  return utils.intFromLE(bytes);
@@ -8046,8 +8046,8 @@ var require_base64_js = __commonJS({
8046
8046
  }
8047
8047
  return arr;
8048
8048
  }
8049
- function tripletToBase64(num) {
8050
- return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
8049
+ function tripletToBase64(num2) {
8050
+ return lookup[num2 >> 18 & 63] + lookup[num2 >> 12 & 63] + lookup[num2 >> 6 & 63] + lookup[num2 & 63];
8051
8051
  }
8052
8052
  function encodeChunk(uint8, start, end) {
8053
8053
  var tmp;
@@ -9759,6 +9759,7 @@ var require_buffer2 = __commonJS({
9759
9759
  var chargyInterfaces_exports = {};
9760
9760
  __export(chargyInterfaces_exports, {
9761
9761
  CreateError: () => CreateError,
9762
+ CreateWarning: () => CreateWarning,
9762
9763
  CryptoAlgorithms: () => CryptoAlgorithms,
9763
9764
  CryptoHashAlgorithms: () => CryptoHashAlgorithms,
9764
9765
  DayOfWeek: () => DayOfWeek,
@@ -9834,6 +9835,12 @@ var ErrorLevel = /* @__PURE__ */ ((ErrorLevel2) => {
9834
9835
  ErrorLevel2["high"] = "high";
9835
9836
  return ErrorLevel2;
9836
9837
  })(ErrorLevel || {});
9838
+ function CreateWarning(message, level = "low" /* low */) {
9839
+ return {
9840
+ level,
9841
+ message
9842
+ };
9843
+ }
9837
9844
  function CreateError(message, level = "high" /* high */) {
9838
9845
  return {
9839
9846
  level,
@@ -11151,6 +11158,8 @@ var Alfen = class {
11151
11158
  );
11152
11159
  }
11153
11160
  _CTR["status"] = "Unvalidated" /* Unvalidated */;
11161
+ if (ContainerInfos.warnings !== void 0)
11162
+ _CTR.warnings = [..._CTR.warnings ?? [], ...ContainerInfos.warnings];
11154
11163
  return _CTR;
11155
11164
  } catch (exception) {
11156
11165
  return {
@@ -12377,6 +12386,1051 @@ var BSMCrypt01 = class extends ACrypt {
12377
12386
  // //#endregion
12378
12387
  };
12379
12388
 
12389
+ // src/interfaces/IPublicKeyInfo.ts
12390
+ var IPublicKeyInfo_exports = {};
12391
+ __export(IPublicKeyInfo_exports, {
12392
+ IsAPublicKey: () => IsAPublicKey,
12393
+ IsAPublicKeyLookup: () => IsAPublicKeyLookup,
12394
+ IsAPublicKeySignature: () => IsAPublicKeySignature,
12395
+ IsAPublicKeyXY: () => IsAPublicKeyXY,
12396
+ PublicKeyFormats: () => PublicKeyFormats,
12397
+ isPublicKeySubject: () => isPublicKeySubject
12398
+ });
12399
+ var PublicKeyFormats = /* @__PURE__ */ ((PublicKeyFormats2) => {
12400
+ PublicKeyFormats2["DER"] = "DER";
12401
+ PublicKeyFormats2["XY"] = "XY";
12402
+ return PublicKeyFormats2;
12403
+ })(PublicKeyFormats || {});
12404
+ function IsAPublicKeyLookup(data) {
12405
+ if (!isMandatoryJSONObject(data))
12406
+ return false;
12407
+ return Array.isArray(data["publicKeys"]);
12408
+ }
12409
+ function IsAPublicKey(data) {
12410
+ if (!isMandatoryJSONObject(data))
12411
+ return false;
12412
+ if (data["@context"] !== void 0 && !isStringOrStringArray(data["@context"])) {
12413
+ return false;
12414
+ }
12415
+ if (!isPublicKeySubject(data["subject"]))
12416
+ return false;
12417
+ if (data["value"] !== void 0 && !isString(data["value"])) {
12418
+ return false;
12419
+ }
12420
+ if (data["value"] === void 0 && (data["x"] === void 0 || data["y"] === void 0)) {
12421
+ return false;
12422
+ }
12423
+ if (data["value"] !== void 0 && !isStringOrOIDInfo(data["algorithm"])) {
12424
+ return false;
12425
+ }
12426
+ if (data["certainty"] !== void 0 && (typeof data["certainty"] !== "number" || !Number.isFinite(data["certainty"]))) {
12427
+ return false;
12428
+ }
12429
+ if (data["type"] !== void 0 && !isStringOrOIDInfo(data["type"])) {
12430
+ return false;
12431
+ }
12432
+ if (data["encoding"] !== void 0 && typeof data["encoding"] !== "string") {
12433
+ return false;
12434
+ }
12435
+ if (data["signatures"] !== void 0 && (!Array.isArray(data["signatures"]) || !data["signatures"].every(IsAPublicKeySignature))) {
12436
+ return false;
12437
+ }
12438
+ return true;
12439
+ }
12440
+ function isPublicKeySubject(data) {
12441
+ if (data === void 0)
12442
+ return true;
12443
+ if (isStringOrStringArray(data))
12444
+ return true;
12445
+ if (!isMandatoryJSONObject(data))
12446
+ return false;
12447
+ return Object.values(data).every(
12448
+ (value) => typeof value === "string" || isStringOrStringArray(value)
12449
+ );
12450
+ }
12451
+ function IsAPublicKeySignature(data) {
12452
+ if (!isMandatoryJSONObject(data))
12453
+ return false;
12454
+ if (!isOptionalString(data["@id"]))
12455
+ return false;
12456
+ if (data["@context"] !== void 0 && !isStringOrStringArray(data["@context"]))
12457
+ return false;
12458
+ if (!isOptionalStringOrOIDInfo(data["algorithm"]))
12459
+ return false;
12460
+ if (!isOptionalString(data["format"]))
12461
+ return false;
12462
+ if (!isOptionalString(data["encoding"]))
12463
+ return false;
12464
+ if (data["value"] !== void 0 && !isString(data["value"]))
12465
+ return false;
12466
+ if (data["publicKey"] !== void 0 && !isEncodedValue(data["publicKey"]))
12467
+ return false;
12468
+ if (data["signature"] !== void 0 && !isEncodedValue(data["signature"]))
12469
+ return false;
12470
+ if (!isOptionalString(data["timestamp"]))
12471
+ return false;
12472
+ if (!isOptionalString(data["issuer"]))
12473
+ return false;
12474
+ if (!isOptionalString(data["signer"]))
12475
+ return false;
12476
+ if (!isOptionalString(data["notBefore"]))
12477
+ return false;
12478
+ if (!isOptionalString(data["notAfter"]))
12479
+ return false;
12480
+ if (!isOptionalStringArray(data["keyUsage"]))
12481
+ return false;
12482
+ if (data["operations"] !== void 0 && !isMandatoryJSONObject(data["operations"]))
12483
+ return false;
12484
+ if (data["comment"] !== void 0 && !isMandatoryJSONObject(data["comment"]))
12485
+ return false;
12486
+ return data["value"] !== void 0 || data["signature"] !== void 0 || data["algorithm"] !== void 0 || data["timestamp"] !== void 0 || data["issuer"] !== void 0 || data["signer"] !== void 0 || data["keyUsage"] !== void 0;
12487
+ }
12488
+ function IsAPublicKeyXY(data) {
12489
+ if (!IsAPublicKey(data))
12490
+ return false;
12491
+ if (!isString(data["x"])) {
12492
+ return false;
12493
+ }
12494
+ if (!isString(data["y"])) {
12495
+ return false;
12496
+ }
12497
+ return true;
12498
+ }
12499
+ var EDL40_SESSION_CONTEXT = "https://open.charging.cloud/contexts/SessionSignatureFormats/EDL40+json";
12500
+ var EDL40_SIGNATURE_CONTEXT = "https://open.charging.cloud/contexts/EnergyMeterSignatureFormats/EDL40+json";
12501
+ var EDL40_OBIS = "1-0:1.8.0*255";
12502
+ var EDL40ValidationError = class extends Error {
12503
+ constructor(code, message) {
12504
+ super(message);
12505
+ this.code = code;
12506
+ this.name = "EDL40ValidationError";
12507
+ }
12508
+ code;
12509
+ };
12510
+ var START_ESCAPE = [27, 27, 27, 27, 1, 1, 1, 1];
12511
+ var ESCAPE = [27, 27, 27, 27];
12512
+ var REQUIRED_UNIT = 30;
12513
+ var SIGNATURE_LENGTH = 320;
12514
+ var OBIS_CONTRACT_ID = "8182815401ff";
12515
+ var OBIS_SIGNED_VALUE = "0100011100ff";
12516
+ var OBIS_SIGNED_VALUE_2 = "0100010800ff";
12517
+ var OBIS_EDL_PAGINATION = "8180817101ff";
12518
+ var OBIS_EDL_SECONDS_INDEX = "810060080001";
12519
+ var OBIS_SIGNATURE_VERSION = "00af737672ff";
12520
+ var OBIS_START_EC = "010001080080";
12521
+ var OBIS_ACTUAL_EC = "0100010800ff";
12522
+ var OBIS_ISA_PAGINATION = "8180c7f040ff";
12523
+ var OBIS_ESTH = "8180816101ff";
12524
+ function canParseEDL40(data) {
12525
+ try {
12526
+ parseEDL40(data);
12527
+ return true;
12528
+ } catch {
12529
+ return false;
12530
+ }
12531
+ }
12532
+ function parseEDL40(data) {
12533
+ const res = parseGetListRes(data);
12534
+ try {
12535
+ return buildIsaSignature(res);
12536
+ } catch {
12537
+ return buildEDL40Signature(res);
12538
+ }
12539
+ }
12540
+ async function verifyEDL40Document(document2, publicKey, chargy) {
12541
+ const normalizedPublicKey = cleanHex(publicKey);
12542
+ if (document2.variant === "ISA_EDL_40_P") {
12543
+ const signature2 = document2.dataSignature;
12544
+ const hashValue = await hashSignedData(document2.signedData, 32);
12545
+ if (normalizedPublicKey.length !== 128 || signature2.length !== 64)
12546
+ return {
12547
+ status: "InvalidPublicKey" /* InvalidPublicKey */,
12548
+ curve: "secp256r1",
12549
+ hashValue,
12550
+ signature: signature2
12551
+ };
12552
+ return {
12553
+ status: verifyRawSignature(chargy, "secp256r1", normalizedPublicKey, signature2, hashValue),
12554
+ curve: "secp256r1",
12555
+ hashValue,
12556
+ signature: signature2
12557
+ };
12558
+ }
12559
+ const cutoff = document2.version === 4 || document2.listSignature.length === 50 ? 2 : 0;
12560
+ const signature = document2.listSignature.subarray(0, document2.listSignature.length - cutoff);
12561
+ if (normalizedPublicKey.length === 96 && signature.length === 48) {
12562
+ const hashValue = await hashSignedData(document2.signedData, 24);
12563
+ return {
12564
+ status: verifyRawSignature(chargy, "secp192r1", normalizedPublicKey, signature, hashValue),
12565
+ curve: "secp192r1",
12566
+ hashValue,
12567
+ signature
12568
+ };
12569
+ }
12570
+ if (normalizedPublicKey.length === 128 && signature.length === 64) {
12571
+ const hashValue = await hashSignedData(document2.signedData, 32);
12572
+ return {
12573
+ status: verifyRawSignature(chargy, "secp256r1", normalizedPublicKey, signature, hashValue),
12574
+ curve: "secp256r1",
12575
+ hashValue,
12576
+ signature
12577
+ };
12578
+ }
12579
+ return {
12580
+ status: normalizedPublicKey.length === 96 || normalizedPublicKey.length === 128 ? "InvalidSignature" /* InvalidSignature */ : "InvalidPublicKey" /* InvalidPublicKey */,
12581
+ curve: normalizedPublicKey.length === 128 ? "secp256r1" : "secp192r1",
12582
+ hashValue: await hashSignedData(document2.signedData, normalizedPublicKey.length === 128 ? 32 : 24),
12583
+ signature
12584
+ };
12585
+ }
12586
+ function parseGetListRes(data) {
12587
+ for (const encoding of guessEncoding(data)) {
12588
+ try {
12589
+ const bytes = decodeWithEncoding(encoding, data);
12590
+ const res = findGetListRes(decodeSmlMessages(stripTransport(bytes)));
12591
+ if (res != null)
12592
+ return res;
12593
+ } catch {
12594
+ }
12595
+ }
12596
+ throw new EDL40ValidationError("SML_NO_GETLISTRES", "No verifiable SML data found");
12597
+ }
12598
+ function guessEncoding(data) {
12599
+ const matches = [];
12600
+ if (data == null || data.trim().length === 0)
12601
+ return matches;
12602
+ try {
12603
+ decodeBase32(data);
12604
+ matches.push("base32");
12605
+ } catch {
12606
+ }
12607
+ try {
12608
+ decodeBase64(data);
12609
+ matches.push("base64");
12610
+ } catch {
12611
+ }
12612
+ try {
12613
+ hexToBytes(data);
12614
+ matches.push("hex");
12615
+ } catch {
12616
+ }
12617
+ return matches;
12618
+ }
12619
+ function decodeWithEncoding(encoding, data) {
12620
+ switch (encoding) {
12621
+ case "base32":
12622
+ return decodeBase32(data);
12623
+ case "base64":
12624
+ return decodeBase64(data);
12625
+ default:
12626
+ return hexToBytes(data);
12627
+ }
12628
+ }
12629
+ function decodeBase64(data) {
12630
+ const clean = data.replace(/\s+/g, "");
12631
+ if (clean.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(clean))
12632
+ throw new Error("Invalid base64 data");
12633
+ return base64ToBytes(clean);
12634
+ }
12635
+ function decodeBase32(data) {
12636
+ const clean = data.replace(/\s+/g, "").replace(/=+$/, "").toUpperCase();
12637
+ if (clean.length === 0)
12638
+ return new Uint8Array(0);
12639
+ if (!/^[A-Z2-7]+$/.test(clean))
12640
+ throw new Error("Invalid base32 data");
12641
+ const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
12642
+ let bits = 0;
12643
+ let value = 0;
12644
+ const out = [];
12645
+ for (const ch of clean) {
12646
+ const idx = alphabet.indexOf(ch);
12647
+ value = value << 5 | idx;
12648
+ bits += 5;
12649
+ if (bits >= 8) {
12650
+ bits -= 8;
12651
+ out.push(value >>> bits & 255);
12652
+ }
12653
+ }
12654
+ return Uint8Array.from(out);
12655
+ }
12656
+ function stripTransport(raw) {
12657
+ const start = indexOfSeq(raw, START_ESCAPE);
12658
+ if (start < 0)
12659
+ return raw;
12660
+ let i = start + START_ESCAPE.length;
12661
+ const out = [];
12662
+ while (i < raw.length) {
12663
+ if (matchSeq(raw, i, ESCAPE)) {
12664
+ if (raw[i + 4] === 26)
12665
+ break;
12666
+ if (matchSeq(raw, i + 4, ESCAPE)) {
12667
+ out.push(27, 27, 27, 27);
12668
+ i += 8;
12669
+ continue;
12670
+ }
12671
+ }
12672
+ const byte = raw[i];
12673
+ if (byte === void 0)
12674
+ break;
12675
+ out.push(byte);
12676
+ i++;
12677
+ }
12678
+ return Uint8Array.from(out);
12679
+ }
12680
+ function readTLV(buf, pos) {
12681
+ if (pos >= buf.length)
12682
+ throw new EDL40ValidationError("SML_INCOMPLETE", "Unexpected end of SML data at " + pos.toString());
12683
+ const tl = byteAt(buf, pos);
12684
+ if (tl === 0)
12685
+ return { value: { kind: "empty" }, next: pos + 1 };
12686
+ if (tl === 1)
12687
+ return { value: null, next: pos + 1 };
12688
+ const type = tl >> 4 & 7;
12689
+ let len = tl & 15;
12690
+ let headerBytes = 1;
12691
+ if (tl & 128) {
12692
+ let p = pos + 1;
12693
+ while (p < buf.length && byteAt(buf, p) & 128) {
12694
+ len = len << 4 | byteAt(buf, p) & 15;
12695
+ p++;
12696
+ headerBytes++;
12697
+ }
12698
+ if (p >= buf.length)
12699
+ throw new EDL40ValidationError("SML_INCOMPLETE", "Truncated multi-byte length");
12700
+ len = len << 4 | byteAt(buf, p) & 15;
12701
+ headerBytes++;
12702
+ }
12703
+ if (type === 7) {
12704
+ let p = pos + headerBytes;
12705
+ const items = [];
12706
+ for (let k = 0; k < len; k++) {
12707
+ const r = readTLV(buf, p);
12708
+ items.push(r.value);
12709
+ p = r.next;
12710
+ }
12711
+ return { value: { kind: "list", items }, next: p };
12712
+ }
12713
+ const dataLen = len - headerBytes;
12714
+ if (dataLen < 0 || pos + headerBytes + dataLen > buf.length)
12715
+ throw new EDL40ValidationError("SML_TLV_INVALID", "Invalid TLV length at " + pos.toString());
12716
+ const data = buf.slice(pos + headerBytes, pos + headerBytes + dataLen);
12717
+ const next = pos + headerBytes + dataLen;
12718
+ switch (type) {
12719
+ case 0:
12720
+ return { value: { kind: "octet", bytes: data }, next };
12721
+ case 4:
12722
+ return { value: { kind: "bool", value: data.length > 0 && data[0] !== 0 }, next };
12723
+ case 5:
12724
+ return { value: { kind: "int", value: toSignedBigInt(data) }, next };
12725
+ case 6:
12726
+ return { value: { kind: "uint", value: toUnsignedBigInt(data) }, next };
12727
+ default:
12728
+ throw new EDL40ValidationError("SML_TLV_INVALID", "Unknown SML type 0x" + type.toString(16));
12729
+ }
12730
+ }
12731
+ function decodeSmlMessages(payload) {
12732
+ const messages = [];
12733
+ let pos = 0;
12734
+ while (pos < payload.length) {
12735
+ if (payload[pos] === 0) {
12736
+ pos++;
12737
+ continue;
12738
+ }
12739
+ const r = readTLV(payload, pos);
12740
+ if (r.next <= pos)
12741
+ break;
12742
+ if (r.value?.kind === "list")
12743
+ messages.push(r.value);
12744
+ pos = r.next;
12745
+ }
12746
+ return messages;
12747
+ }
12748
+ function findGetListRes(messages) {
12749
+ for (const msg of messages) {
12750
+ if (msg.kind !== "list" || msg.items.length < 4)
12751
+ continue;
12752
+ const messageBody = msg.items[3];
12753
+ if (messageBody?.kind !== "list" || messageBody.items.length < 2)
12754
+ continue;
12755
+ const tagNode = messageBody.items[0];
12756
+ const bodyNode = messageBody.items[1];
12757
+ if (tagNode == null || tagNode.kind !== "uint" && tagNode.kind !== "int")
12758
+ continue;
12759
+ if (Number(tagNode.value) !== 1793 || bodyNode == null)
12760
+ continue;
12761
+ const res = parseGetListResNode(bodyNode);
12762
+ if (res != null)
12763
+ return res;
12764
+ }
12765
+ return null;
12766
+ }
12767
+ function parseGetListResNode(body) {
12768
+ if (body.kind !== "list" || body.items.length < 6)
12769
+ return null;
12770
+ const serverId = octet(body.items[1]);
12771
+ const listName = octet(body.items[2]);
12772
+ const valListNode = body.items[4];
12773
+ const listSignature = octet(body.items[5]);
12774
+ if (serverId == null || listSignature == null || valListNode?.kind !== "list")
12775
+ return null;
12776
+ const valList = [];
12777
+ for (const entry of valListNode.items) {
12778
+ const parsed = parseListEntry(entry);
12779
+ if (parsed != null)
12780
+ valList.push(parsed);
12781
+ }
12782
+ return { serverId, listName, valList, listSignature };
12783
+ }
12784
+ function parseListEntry(v) {
12785
+ if (v?.kind !== "list")
12786
+ return null;
12787
+ return {
12788
+ objName: octet(v.items[0]),
12789
+ status: v.items[1] ?? null,
12790
+ valTime: parseSmlTime(v.items[2]),
12791
+ unit: num(v.items[3]),
12792
+ scaler: num(v.items[4]),
12793
+ value: v.items[5] ?? null,
12794
+ valueSignature: octet(v.items[6])
12795
+ };
12796
+ }
12797
+ function findEntryByObis(res, obisHex) {
12798
+ const target = obisHex.toLowerCase();
12799
+ for (const entry of res.valList)
12800
+ if (entry.objName != null && bytesToHex2(entry.objName) === target)
12801
+ return entry;
12802
+ return null;
12803
+ }
12804
+ function parseSmlTime(v) {
12805
+ if (v?.kind !== "list" || v.items.length < 2)
12806
+ return null;
12807
+ const tag = asNumber2(v.items[0]);
12808
+ const body = v.items[1];
12809
+ if (tag === 1)
12810
+ return { kind: "secIndex", timestamp: asNumber2(body), localOffsetMin: 0, seasonOffsetMin: 0 };
12811
+ if (tag === 2)
12812
+ return { kind: "timestamp", timestamp: asNumber2(body), localOffsetMin: 0, seasonOffsetMin: 0 };
12813
+ if (tag === 3 && body?.kind === "list" && body.items.length >= 3)
12814
+ return {
12815
+ kind: "timestampLocal",
12816
+ timestamp: asNumber2(body.items[0]),
12817
+ localOffsetMin: asNumber2(body.items[1]),
12818
+ seasonOffsetMin: asNumber2(body.items[2])
12819
+ };
12820
+ return null;
12821
+ }
12822
+ function resolveSmlTime(t) {
12823
+ const offsetSec = (t.localOffsetMin + t.seasonOffsetMin) * 60;
12824
+ return {
12825
+ localEpoch: t.timestamp + offsetSec,
12826
+ date: new Date(t.timestamp * 1e3)
12827
+ };
12828
+ }
12829
+ function buildEDL40Signature(res) {
12830
+ const listSignature = res.listSignature;
12831
+ const isEmoc = listSignature.length === 66;
12832
+ let signedValueEntry = findEntryByObis(res, OBIS_SIGNED_VALUE);
12833
+ signedValueEntry ??= findEntryByObis(res, OBIS_SIGNED_VALUE_2);
12834
+ if (signedValueEntry == null)
12835
+ throw new EDL40ValidationError("MISSING_FIELD", "EDL40: missing signed value entry");
12836
+ const contractEntry = findEntryByObis(res, OBIS_CONTRACT_ID);
12837
+ const paginationEntry = findEntryByObis(res, OBIS_EDL_PAGINATION);
12838
+ const secondsIndexEntry = findEntryByObis(res, OBIS_EDL_SECONDS_INDEX);
12839
+ const versionEntry = findEntryByObis(res, OBIS_SIGNATURE_VERSION);
12840
+ const unit = signedValueEntry.unit ?? 0;
12841
+ if (unit !== REQUIRED_UNIT)
12842
+ throw new EDL40ValidationError("INVALID_UNIT", "EDL40: unit must be 30 (Wh)");
12843
+ const scaler = signedValueEntry.scaler ?? 0;
12844
+ const meterValue = valueAsLong(signedValueEntry);
12845
+ const obisId = signedValueEntry.objName ?? new Uint8Array(6);
12846
+ let status = 0;
12847
+ if (signedValueEntry.status != null && (signedValueEntry.status.kind === "uint" || signedValueEntry.status.kind === "int"))
12848
+ status = Number(BigInt.asUintN(32, signedValueEntry.status.value)) & 255;
12849
+ if (isEmoc && signedValueEntry.status != null && (signedValueEntry.status.kind === "uint" || signedValueEntry.status.kind === "int"))
12850
+ status = transformEDL40Status(Number(BigInt.asUintN(32, signedValueEntry.status.value)));
12851
+ let pagination = 0;
12852
+ const p = deepFirstInt(paginationEntry?.value);
12853
+ if (p != null)
12854
+ pagination = Number(p);
12855
+ let secondsIndex = 0;
12856
+ const s = deepFirstInt(secondsIndexEntry?.value);
12857
+ if (s != null)
12858
+ secondsIndex = Number(s);
12859
+ let version = 0;
12860
+ const ver = deepFirstInt(versionEntry?.value);
12861
+ if (ver != null)
12862
+ version = Number(ver);
12863
+ const contractRaw = contractEntry?.value?.kind === "octet" ? contractEntry.value.bytes : new Uint8Array(0);
12864
+ const contractId = new Uint8Array(128);
12865
+ contractId.set(contractRaw.subarray(0, 128), 0);
12866
+ const out = new Uint8Array(SIGNATURE_LENGTH);
12867
+ out.set(res.serverId.subarray(0, 10), 0);
12868
+ out.set(timeBytes(signedValueEntry), 10);
12869
+ out[14] = status;
12870
+ out.set(reverseBytes(intToBytesBE(secondsIndex >>> 0)), 15);
12871
+ out.set(reverseBytes(intToBytesBE(pagination >>> 0)), 19);
12872
+ out.set(obisId.subarray(0, 6), 23);
12873
+ out[29] = unit & 255;
12874
+ out[30] = scaler & 255;
12875
+ out.set(reverseBytes(longToBytesBE(meterValue)), 31);
12876
+ out.set(listSignature.subarray(listSignature.length - 2), 39);
12877
+ out.set(contractId, 41);
12878
+ if (contractEntry != null)
12879
+ out.set(timeBytes(contractEntry), 169);
12880
+ return {
12881
+ variant: "EDL_40_P",
12882
+ signedData: out,
12883
+ listSignature,
12884
+ version,
12885
+ isEmoc,
12886
+ unit,
12887
+ scaler,
12888
+ serverId: res.serverId,
12889
+ contractId,
12890
+ pagination,
12891
+ meterValue,
12892
+ obisId,
12893
+ status,
12894
+ meterDate: signedValueEntry.valTime != null ? resolveSmlTime(signedValueEntry.valTime).date : /* @__PURE__ */ new Date(0)
12895
+ };
12896
+ }
12897
+ function buildIsaSignature(res) {
12898
+ const contractEntry = requireEntry(res, OBIS_CONTRACT_ID, "contract-id");
12899
+ const startEntry = requireEntry(res, OBIS_START_EC, "start-ec");
12900
+ const actualEntry = requireEntry(res, OBIS_ACTUAL_EC, "actual-ec");
12901
+ const paginationEntry = requireEntry(res, OBIS_ISA_PAGINATION, "pagination");
12902
+ const esthEntry = requireEntry(res, OBIS_ESTH, "esth");
12903
+ const actualUnit = actualEntry.unit ?? 0;
12904
+ const startUnit = startEntry.unit ?? 0;
12905
+ if (actualUnit !== REQUIRED_UNIT || startUnit !== REQUIRED_UNIT)
12906
+ throw new EDL40ValidationError("INVALID_UNIT", "ISA: unit must be 30 (Wh)");
12907
+ if (paginationEntry.value == null || paginationEntry.value.kind !== "uint" && paginationEntry.value.kind !== "int")
12908
+ throw new EDL40ValidationError("MISSING_FIELD", "ISA: pagination is not an unsigned integer");
12909
+ const contractRaw = contractEntry.value?.kind === "octet" ? contractEntry.value.bytes : new Uint8Array(0);
12910
+ const contractId = new Uint8Array(128);
12911
+ contractId.set(contractRaw.subarray(0, 128), 0);
12912
+ const esth = esthEntry.value?.kind === "octet" ? esthEntry.value.bytes : new Uint8Array(20);
12913
+ const actualStatus = status8(actualEntry);
12914
+ const startStatus = status8(startEntry);
12915
+ const actualValue = valueAsLong(actualEntry);
12916
+ const startValue = valueAsLong(startEntry);
12917
+ const actualSig = actualEntry.valueSignature ?? new Uint8Array(66);
12918
+ const listName = res.listName ?? new Uint8Array(6);
12919
+ const listSignature = res.listSignature;
12920
+ const dataSignature = listSignature.subarray(0, listSignature.length - 2);
12921
+ const pagination = Number(paginationEntry.value.value);
12922
+ const out = new Uint8Array(SIGNATURE_LENGTH);
12923
+ out.set(res.serverId.subarray(0, 10), 0);
12924
+ out.set(timeBytes(actualEntry), 10);
12925
+ out[14] = actualStatus[7] ?? 0;
12926
+ out.set((actualEntry.objName ?? new Uint8Array(6)).subarray(0, 6), 15);
12927
+ out[21] = actualUnit & 255;
12928
+ out[22] = (actualEntry.scaler ?? 0) & 255;
12929
+ out.set(reverseBytes(longToBytesBE(actualValue)), 23);
12930
+ out.set(listSignature.subarray(listSignature.length - 2), 31);
12931
+ out.set(actualSig.subarray(0, 66), 33);
12932
+ out.set(contractId, 99);
12933
+ out.set(timeBytes(startEntry), 227);
12934
+ out.set(esth.subarray(0, 20), 231);
12935
+ out[251] = startStatus[7] ?? 0;
12936
+ out.set((startEntry.objName ?? new Uint8Array(6)).subarray(0, 6), 252);
12937
+ out[258] = startUnit & 255;
12938
+ out[259] = (startEntry.scaler ?? 0) & 255;
12939
+ out.set(reverseBytes(longToBytesBE(startValue)), 260);
12940
+ out.set(listName.subarray(0, 6), 268);
12941
+ out.set(reverseBytes(intToBytesBE(pagination >>> 0)), 274);
12942
+ return {
12943
+ variant: "ISA_EDL_40_P",
12944
+ signedData: out,
12945
+ dataSignature,
12946
+ listSignature,
12947
+ serverId: res.serverId,
12948
+ listName: res.listName,
12949
+ contractId,
12950
+ pagination,
12951
+ unit: actualUnit,
12952
+ actualEcValue: actualValue,
12953
+ actualEcScaler: actualEntry.scaler ?? 0,
12954
+ actualEcObis: actualEntry.objName ?? new Uint8Array(6),
12955
+ actualEcStatus: actualStatus,
12956
+ actualEcDate: actualEntry.valTime != null ? resolveSmlTime(actualEntry.valTime).date : /* @__PURE__ */ new Date(0),
12957
+ startEcValue: startValue,
12958
+ startEcScaler: startEntry.scaler ?? 0,
12959
+ startEcObis: startEntry.objName ?? new Uint8Array(6),
12960
+ startEcStatus: startStatus,
12961
+ startEcDate: startEntry.valTime != null ? resolveSmlTime(startEntry.valTime).date : /* @__PURE__ */ new Date(0)
12962
+ };
12963
+ }
12964
+ function isaListNameContext(listName) {
12965
+ const hex = listName != null ? bytesToHex2(listName) : "";
12966
+ if (hex === "8180816201ff")
12967
+ return "UPDATE";
12968
+ if (hex === "8180816202ff")
12969
+ return "STOP";
12970
+ return "START";
12971
+ }
12972
+ function transformEDL40Status(value) {
12973
+ let b = 0;
12974
+ const set = (targetBit, sourceBit) => {
12975
+ if (value & 1 << sourceBit)
12976
+ b |= 1 << targetBit;
12977
+ };
12978
+ set(0, 17);
12979
+ set(3, 31);
12980
+ set(4, 16);
12981
+ set(5, 11);
12982
+ set(6, 9);
12983
+ set(7, 8);
12984
+ return b & 255;
12985
+ }
12986
+ var EDL40Crypt01 = class extends ACrypt {
12987
+ constructor(chargy) {
12988
+ super(
12989
+ "EDL40/ISA-EDL40",
12990
+ chargy
12991
+ );
12992
+ }
12993
+ async VerifyChargingSession(chargingSession) {
12994
+ let sessionResult = "ValidSignature" /* ValidSignature */;
12995
+ let valueCount = 0;
12996
+ for (const measurement of chargingSession.measurements ?? []) {
12997
+ measurement.chargingSession = chargingSession;
12998
+ for (const measurementValue of measurement.values) {
12999
+ valueCount++;
13000
+ measurementValue.measurement = measurement;
13001
+ const result = await this.VerifyMeasurement(measurementValue);
13002
+ if (result.status !== "ValidSignature" /* ValidSignature */)
13003
+ sessionResult = "InvalidSignature" /* InvalidSignature */;
13004
+ }
13005
+ if (measurement.values.length > 0 && measurement.values.every((value) => value.result?.status === "ValidSignature" /* ValidSignature */)) {
13006
+ measurement.verificationResult = {
13007
+ status: "ValidSignature" /* ValidSignature */
13008
+ };
13009
+ } else {
13010
+ measurement.verificationResult = {
13011
+ status: "InvalidSignature" /* InvalidSignature */
13012
+ };
13013
+ }
13014
+ }
13015
+ if (valueCount === 0)
13016
+ sessionResult = "InvalidSessionFormat" /* InvalidSessionFormat */;
13017
+ return {
13018
+ status: sessionResult,
13019
+ certainty: 0.9
13020
+ };
13021
+ }
13022
+ async VerifyMeasurement(measurementValue) {
13023
+ measurementValue.method = this;
13024
+ const document2 = measurementValue.edl40Document;
13025
+ const result = {
13026
+ status: document2.validationStatus,
13027
+ hashValue: document2.hashValue,
13028
+ signedData: document2.signedData,
13029
+ publicKey: document2.publicKey,
13030
+ publicKeyFormat: document2.publicKeyFormat,
13031
+ signature: document2.signature,
13032
+ serverId: document2.serverId,
13033
+ variant: document2.variant,
13034
+ curve: document2.curve,
13035
+ pagination: document2.pagination.toString(),
13036
+ obis: measurementValue.measurement?.obis,
13037
+ unitEncoded: String(measurementValue.measurement?.unitEncoded ?? ""),
13038
+ scaler: String(measurementValue.measurement?.scale ?? ""),
13039
+ value: measurementValue.value.toString()
13040
+ };
13041
+ measurementValue.result = result;
13042
+ return Promise.resolve(result);
13043
+ }
13044
+ async ViewMeasurement(measurementValue, errorDiv, introDiv, infoDiv, PlainTextDiv, HashedPlainTextDiv, PublicKeyDiv, SignatureExpectedDiv, SignatureCheckDiv) {
13045
+ const result = measurementValue.result;
13046
+ introDiv.innerHTML = this.chargy.GetLocalizedMessage("The following data of the charging session is relevant for metrological and legal metrological purposes and therefore part of the digital signature").replace("{methodName}", "EDL40/ISA-EDL40").replace("{cryptoAlgorithm}", result?.curve ?? "");
13047
+ PlainTextDiv.innerHTML = result?.signedData?.match(/.{1,8}/g)?.join(" ") ?? "";
13048
+ HashedPlainTextDiv.innerHTML = result?.hashValue?.match(/.{1,8}/g)?.join(" ") ?? "";
13049
+ PublicKeyDiv.innerHTML = result?.publicKey?.match(/.{1,8}/g)?.join(" ") ?? "";
13050
+ SignatureExpectedDiv.innerHTML = result?.signature != null ? "r: " + (result.signature.r.match(/.{1,8}/g)?.join(" ") ?? "") + "<br />s: " + (result.signature.s.match(/.{1,8}/g)?.join(" ") ?? "") : "";
13051
+ SignatureCheckDiv.innerHTML = result?.status === "ValidSignature" /* ValidSignature */ ? '<i class="fas fa-check-circle"></i><div id="description">' + this.chargy.GetLocalizedMessage("Valid signature") + "</div>" : '<i class="fas fa-times-circle"></i><div id="description">' + this.chargy.GetLocalizedMessage("Invalid signature") + "</div>";
13052
+ return Promise.resolve(void 0);
13053
+ }
13054
+ };
13055
+ var EDL40 = class {
13056
+ constructor(chargy) {
13057
+ this.chargy = chargy;
13058
+ }
13059
+ chargy;
13060
+ async TryToParseEDL40Documents(signedDataValues, publicKey, containerInfos) {
13061
+ try {
13062
+ if (signedDataValues.length === 0)
13063
+ return {
13064
+ status: "InvalidSessionFormat" /* InvalidSessionFormat */,
13065
+ message: this.chargy.GetMultilanguageText("The given EDL40 data could not be parsed!"),
13066
+ certainty: 0
13067
+ };
13068
+ const parsed = signedDataValues.map((signedData) => ({
13069
+ raw: signedData,
13070
+ signature: parseEDL40(signedData)
13071
+ }));
13072
+ const variants = new Set(parsed.map((value) => value.signature.variant));
13073
+ if (variants.size > 1)
13074
+ return {
13075
+ status: "InvalidSessionFormat" /* InvalidSessionFormat */,
13076
+ message: this.chargy.GetMultilanguageText("Invalid mixture of different signed data formats within the given XML container!"),
13077
+ certainty: 0
13078
+ };
13079
+ const documents = [];
13080
+ for (const value of parsed) {
13081
+ const verification = await verifyEDL40Document(value.signature, publicKey, this.chargy);
13082
+ const signatureHex = bytesToHex2(verification.signature);
13083
+ const document2 = {
13084
+ "@context": "EDL40",
13085
+ raw: value.raw,
13086
+ variant: value.signature.variant,
13087
+ curve: verification.curve,
13088
+ encoding: "guessed",
13089
+ serverId: bytesToHex2(value.signature.serverId),
13090
+ contractId: bytesToHex2(trimPaddingAtEnd(value.signature.contractId)),
13091
+ publicKey: cleanHex(publicKey),
13092
+ publicKeyFormat: "XY" /* XY */,
13093
+ signedData: bytesToHex2(value.signature.signedData),
13094
+ hashAlgorithm: "SHA256",
13095
+ hashValue: verification.hashValue,
13096
+ signatureHex,
13097
+ signature: rawSignatureToRS(verification.signature),
13098
+ pagination: value.signature.pagination,
13099
+ validationStatus: verification.status
13100
+ };
13101
+ if (value.signature.variant === "ISA_EDL_40_P")
13102
+ document2.listNameContext = isaListNameContext(value.signature.listName);
13103
+ documents.push(document2);
13104
+ }
13105
+ return this.toChargeTransparencyRecord(parsed.map((value) => value.signature), documents, publicKey, containerInfos);
13106
+ } catch (exception) {
13107
+ return {
13108
+ status: "InvalidSessionFormat" /* InvalidSessionFormat */,
13109
+ message: this.chargy.GetMultilanguageText(exception instanceof Error ? exception.message : String(exception)),
13110
+ certainty: 0
13111
+ };
13112
+ }
13113
+ }
13114
+ toChargeTransparencyRecord(signatures, documents, publicKey, containerInfos) {
13115
+ const first = getFirstArrayElement(signatures, "Missing EDL40 signature data");
13116
+ const values = this.toMeasurementValues(signatures, documents);
13117
+ const firstValue2 = getFirstArrayElement(values, "Missing EDL40 measurement value");
13118
+ const lastValue = values[values.length - 1] ?? firstValue2;
13119
+ const serverId = bytesToHex2(first.serverId);
13120
+ const meterId = serverId;
13121
+ const sessionId = serverId + "-" + String(first.pagination) + "-" + String(signatures[signatures.length - 1]?.pagination ?? first.pagination);
13122
+ const curve = documents[0]?.curve ?? "secp192r1";
13123
+ const variant = first.variant;
13124
+ const evseId = containerInfos?.chargingStations?.[0]?.EVSEs?.[0]?.["@id"] ?? "DE*GEF*EVSE*EDL40*1";
13125
+ const chargingStation = containerInfos?.chargingStations?.[0] ?? {
13126
+ "@id": "DE*GEF*STATION*EDL40*1",
13127
+ "description": { "en": "EDL40 charging station" }
13128
+ };
13129
+ chargingStation.EVSEs ??= [
13130
+ {
13131
+ "@id": evseId
13132
+ }
13133
+ ];
13134
+ let primaryEVSE = chargingStation.EVSEs[0];
13135
+ if (primaryEVSE == null) {
13136
+ primaryEVSE = {
13137
+ "@id": evseId
13138
+ };
13139
+ chargingStation.EVSEs = [primaryEVSE];
13140
+ }
13141
+ primaryEVSE.energyMeters = [
13142
+ {
13143
+ "@id": meterId,
13144
+ "manufacturer": { "name": variant === "ISA_EDL_40_P" ? "ISA" : "EDL40" },
13145
+ "signatureFormat": EDL40_SIGNATURE_CONTEXT,
13146
+ "publicKeys": [
13147
+ {
13148
+ "value": cleanHex(publicKey),
13149
+ "algorithm": curve,
13150
+ "format": "XY" /* XY */,
13151
+ "encoding": "hex" /* hex */
13152
+ }
13153
+ ]
13154
+ }
13155
+ ];
13156
+ const measurement = {
13157
+ "energyMeterId": meterId,
13158
+ "@context": EDL40_SIGNATURE_CONTEXT,
13159
+ "name": OBIS2MeasurementName(EDL40_OBIS),
13160
+ "obis": EDL40_OBIS,
13161
+ "unit": "kWh",
13162
+ "unitEncoded": 30,
13163
+ "scale": -3,
13164
+ "serverId": serverId,
13165
+ "publicKey": cleanHex(publicKey),
13166
+ "variant": variant,
13167
+ "curve": curve,
13168
+ "signatureInfos": {
13169
+ "hash": "SHA256" /* SHA256 */,
13170
+ "hashTruncation": curve === "secp192r1" ? 24 : 32,
13171
+ "algorithm": "ECC" /* ECC */,
13172
+ "curve": curve,
13173
+ "format": "RS" /* RS */,
13174
+ "encoding": "hex" /* hex */
13175
+ },
13176
+ "values": values
13177
+ };
13178
+ const firstDocument = documents[0];
13179
+ const authorizationStart = firstDocument?.contractId != null && firstDocument.contractId.length > 0 ? {
13180
+ "@id": firstDocument.contractId
13181
+ } : void 0;
13182
+ const chargingSession = {
13183
+ "@id": sessionId,
13184
+ "@context": EDL40_SESSION_CONTEXT,
13185
+ "begin": firstValue2.timestamp,
13186
+ "end": lastValue.timestamp,
13187
+ "internalSessionId": sessionId,
13188
+ "EVSEId": evseId,
13189
+ "meterId": meterId,
13190
+ "authorizationStart": authorizationStart,
13191
+ "measurements": [
13192
+ measurement
13193
+ ]
13194
+ };
13195
+ return {
13196
+ "@id": sessionId,
13197
+ "@context": "https://open.charging.cloud/contexts/CTR+json",
13198
+ "begin": chargingSession.begin,
13199
+ "end": chargingSession.end,
13200
+ "description": {
13201
+ "de": "EDL40/ISA-EDL40 Ladevorgang",
13202
+ "en": "EDL40/ISA-EDL40 charging session"
13203
+ },
13204
+ "chargingStations": [
13205
+ chargingStation
13206
+ ],
13207
+ "chargingSessions": [
13208
+ chargingSession
13209
+ ],
13210
+ "publicKeys": [
13211
+ {
13212
+ "@context": "https://open.charging.cloud/contexts/publicKey+json",
13213
+ "subject": meterId,
13214
+ "algorithm": curve,
13215
+ "encoding": "hex" /* hex */,
13216
+ "format": "XY" /* XY */,
13217
+ "value": cleanHex(publicKey),
13218
+ "certainty": 1
13219
+ }
13220
+ ],
13221
+ "warnings": containerInfos?.warnings,
13222
+ "edl40": {
13223
+ variant,
13224
+ serverId,
13225
+ paginationStart: first.pagination,
13226
+ paginationEnd: signatures[signatures.length - 1]?.pagination ?? first.pagination
13227
+ },
13228
+ "certainty": 1,
13229
+ "status": "Unvalidated" /* Unvalidated */
13230
+ };
13231
+ }
13232
+ toMeasurementValues(signatures, documents) {
13233
+ const values = [];
13234
+ for (let index = 0; index < signatures.length; index++) {
13235
+ const signature = getArrayElement(signatures, index, "Missing EDL40 signature data");
13236
+ const document2 = getArrayElement(documents, index, "Missing EDL40 document");
13237
+ if (signature.variant === "ISA_EDL_40_P") {
13238
+ values.push(this.toValue(
13239
+ signature.startEcDate,
13240
+ signature.startEcValue,
13241
+ signature.startEcScaler,
13242
+ bytesToHex2(signature.startEcStatus),
13243
+ signature.pagination,
13244
+ document2
13245
+ ));
13246
+ values.push(this.toValue(
13247
+ signature.actualEcDate,
13248
+ signature.actualEcValue,
13249
+ signature.actualEcScaler,
13250
+ bytesToHex2(signature.actualEcStatus),
13251
+ signature.pagination,
13252
+ document2
13253
+ ));
13254
+ } else {
13255
+ values.push(this.toValue(
13256
+ signature.meterDate,
13257
+ signature.meterValue,
13258
+ signature.scaler,
13259
+ signature.status.toString(16).padStart(2, "0"),
13260
+ signature.pagination,
13261
+ document2
13262
+ ));
13263
+ }
13264
+ }
13265
+ return values.sort((left, right) => left.timestamp.localeCompare(right.timestamp));
13266
+ }
13267
+ toValue(timestamp, valueWh, scaler, statusMeter, pagination, document2) {
13268
+ return {
13269
+ "timestamp": timestamp.toISOString(),
13270
+ "value": scaledWhToKWh(valueWh, scaler),
13271
+ "statusMeter": statusMeter,
13272
+ "paginationId": pagination,
13273
+ "signatures": [
13274
+ document2.signature
13275
+ ],
13276
+ "edl40Document": document2,
13277
+ "result": {
13278
+ "status": document2.validationStatus
13279
+ }
13280
+ };
13281
+ }
13282
+ };
13283
+ async function hashSignedData(signedData, crop) {
13284
+ return bytesToHex2((await sha256____(signedData)).subarray(0, crop));
13285
+ }
13286
+ function verifyRawSignature(chargy, curve, publicKey, signature, hashValue) {
13287
+ try {
13288
+ const ec = curve === "secp192r1" ? new chargy.elliptic.ec("p192") : new chargy.elliptic.ec("p256");
13289
+ const verified = ec.keyFromPublic("04" + publicKey, "hex").verify(hashValue.toUpperCase(), rawSignatureToRS(signature));
13290
+ return verified ? "ValidSignature" /* ValidSignature */ : "InvalidSignature" /* InvalidSignature */;
13291
+ } catch {
13292
+ return "InvalidSignature" /* InvalidSignature */;
13293
+ }
13294
+ }
13295
+ function rawSignatureToRS(signature) {
13296
+ const signatureHex = bytesToHex2(signature);
13297
+ const half = signatureHex.length / 2;
13298
+ return {
13299
+ algorithm: "ECC" /* ECC */,
13300
+ format: "RS" /* RS */,
13301
+ value: signatureHex,
13302
+ r: signatureHex.substring(0, half),
13303
+ s: signatureHex.substring(half)
13304
+ };
13305
+ }
13306
+ function scaledWhToKWh(valueWh, scaler) {
13307
+ return new Decimal(valueWh.toString()).mul(new Decimal(10).pow(scaler)).div(1e3);
13308
+ }
13309
+ function timeBytes(entry) {
13310
+ if (entry.valTime == null)
13311
+ throw new EDL40ValidationError("MISSING_FIELD", "EDL40/ISA: missing valTime");
13312
+ return reverseBytes(intToBytesBE(resolveSmlTime(entry.valTime).localEpoch >>> 0));
13313
+ }
13314
+ function valueAsLong(entry) {
13315
+ if (entry.value?.kind === "int" || entry.value?.kind === "uint")
13316
+ return entry.value.value;
13317
+ if (entry.value?.kind === "octet")
13318
+ return toSignedBigInt(entry.value.bytes);
13319
+ return 0n;
13320
+ }
13321
+ function requireEntry(res, obis, label) {
13322
+ const entry = findEntryByObis(res, obis);
13323
+ if (entry == null)
13324
+ throw new EDL40ValidationError("MISSING_FIELD", "ISA: missing " + label + " entry (OBIS " + obis + ")");
13325
+ return entry;
13326
+ }
13327
+ function status8(entry) {
13328
+ const value = entry.status;
13329
+ if (value != null && (value.kind === "uint" || value.kind === "int"))
13330
+ return longToBytesBE(BigInt.asUintN(64, value.value));
13331
+ return new Uint8Array(8);
13332
+ }
13333
+ function deepFirstInt(value) {
13334
+ if (value == null)
13335
+ return null;
13336
+ if (value.kind === "uint" || value.kind === "int")
13337
+ return value.value;
13338
+ if (value.kind === "list")
13339
+ for (let i = value.items.length - 1; i >= 0; i--) {
13340
+ const result = deepFirstInt(value.items[i]);
13341
+ if (result != null)
13342
+ return result;
13343
+ }
13344
+ return null;
13345
+ }
13346
+ function octet(value) {
13347
+ return value?.kind === "octet" ? value.bytes : null;
13348
+ }
13349
+ function num(value) {
13350
+ if (value?.kind === "uint" || value?.kind === "int")
13351
+ return Number(value.value);
13352
+ return null;
13353
+ }
13354
+ function asNumber2(value) {
13355
+ if (value?.kind === "uint" || value?.kind === "int")
13356
+ return Number(value.value);
13357
+ return 0;
13358
+ }
13359
+ function intToBytesBE(value) {
13360
+ return Uint8Array.from([
13361
+ value >>> 24 & 255,
13362
+ value >>> 16 & 255,
13363
+ value >>> 8 & 255,
13364
+ value & 255
13365
+ ]);
13366
+ }
13367
+ function longToBytesBE(value) {
13368
+ const out = new Uint8Array(8);
13369
+ let v = BigInt.asUintN(64, value);
13370
+ for (let i = 7; i >= 0; i--) {
13371
+ out[i] = Number(v & 0xffn);
13372
+ v >>= 8n;
13373
+ }
13374
+ return out;
13375
+ }
13376
+ function reverseBytes(bytes) {
13377
+ const out = new Uint8Array(bytes.length);
13378
+ for (let i = 0; i < bytes.length; i++) {
13379
+ const byte = bytes[i];
13380
+ if (byte !== void 0)
13381
+ out[bytes.length - 1 - i] = byte;
13382
+ }
13383
+ return out;
13384
+ }
13385
+ function toUnsignedBigInt(bytes) {
13386
+ let value = 0n;
13387
+ for (const byte of bytes)
13388
+ value = value << 8n | BigInt(byte);
13389
+ return value;
13390
+ }
13391
+ function toSignedBigInt(bytes) {
13392
+ if (bytes.length === 0)
13393
+ return 0n;
13394
+ let value = toUnsignedBigInt(bytes);
13395
+ const bits = BigInt(bytes.length * 8);
13396
+ const signBit = 1n << bits - 1n;
13397
+ if (value & signBit)
13398
+ value -= 1n << bits;
13399
+ return value;
13400
+ }
13401
+ function trimPaddingAtEnd(bytes) {
13402
+ let end = bytes.length;
13403
+ while (end > 0 && bytes[end - 1] === 0)
13404
+ end--;
13405
+ return bytes.subarray(0, end);
13406
+ }
13407
+ function indexOfSeq(haystack, needle) {
13408
+ outer: for (let i = 0; i + needle.length <= haystack.length; i++) {
13409
+ for (let j = 0; j < needle.length; j++)
13410
+ if (haystack[i + j] !== needle[j])
13411
+ continue outer;
13412
+ return i;
13413
+ }
13414
+ return -1;
13415
+ }
13416
+ function matchSeq(buf, pos, seq) {
13417
+ if (pos + seq.length > buf.length)
13418
+ return false;
13419
+ for (let i = 0; i < seq.length; i++)
13420
+ if (buf[pos + i] !== seq[i])
13421
+ return false;
13422
+ return true;
13423
+ }
13424
+ function bytesToHex2(bytes) {
13425
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
13426
+ }
13427
+ function byteAt(bytes, index) {
13428
+ const byte = bytes[index];
13429
+ if (byte === void 0)
13430
+ throw new EDL40ValidationError("SML_INCOMPLETE", "Unexpected end of SML data at " + index.toString());
13431
+ return byte;
13432
+ }
13433
+
12380
13434
  // src/interfaces/CryptoUtils.ts
12381
13435
  var import_elliptic = __toESM(require_elliptic());
12382
13436
  var JSONSignatureVerificationStatus = /* @__PURE__ */ ((JSONSignatureVerificationStatus2) => {
@@ -13138,117 +14192,6 @@ var GDFCrypt01 = class extends ACrypt {
13138
14192
  return void 0;
13139
14193
  }
13140
14194
  };
13141
-
13142
- // src/interfaces/IPublicKeyInfo.ts
13143
- var IPublicKeyInfo_exports = {};
13144
- __export(IPublicKeyInfo_exports, {
13145
- IsAPublicKey: () => IsAPublicKey,
13146
- IsAPublicKeyLookup: () => IsAPublicKeyLookup,
13147
- IsAPublicKeySignature: () => IsAPublicKeySignature,
13148
- IsAPublicKeyXY: () => IsAPublicKeyXY,
13149
- PublicKeyFormats: () => PublicKeyFormats,
13150
- isPublicKeySubject: () => isPublicKeySubject
13151
- });
13152
- var PublicKeyFormats = /* @__PURE__ */ ((PublicKeyFormats2) => {
13153
- PublicKeyFormats2["DER"] = "DER";
13154
- PublicKeyFormats2["XY"] = "XY";
13155
- return PublicKeyFormats2;
13156
- })(PublicKeyFormats || {});
13157
- function IsAPublicKeyLookup(data) {
13158
- if (!isMandatoryJSONObject(data))
13159
- return false;
13160
- return Array.isArray(data["publicKeys"]);
13161
- }
13162
- function IsAPublicKey(data) {
13163
- if (!isMandatoryJSONObject(data))
13164
- return false;
13165
- if (data["@context"] !== void 0 && !isStringOrStringArray(data["@context"])) {
13166
- return false;
13167
- }
13168
- if (!isPublicKeySubject(data["subject"]))
13169
- return false;
13170
- if (data["value"] !== void 0 && !isString(data["value"])) {
13171
- return false;
13172
- }
13173
- if (data["value"] === void 0 && (data["x"] === void 0 || data["y"] === void 0)) {
13174
- return false;
13175
- }
13176
- if (data["value"] !== void 0 && !isStringOrOIDInfo(data["algorithm"])) {
13177
- return false;
13178
- }
13179
- if (data["certainty"] !== void 0 && (typeof data["certainty"] !== "number" || !Number.isFinite(data["certainty"]))) {
13180
- return false;
13181
- }
13182
- if (data["type"] !== void 0 && !isStringOrOIDInfo(data["type"])) {
13183
- return false;
13184
- }
13185
- if (data["encoding"] !== void 0 && typeof data["encoding"] !== "string") {
13186
- return false;
13187
- }
13188
- if (data["signatures"] !== void 0 && (!Array.isArray(data["signatures"]) || !data["signatures"].every(IsAPublicKeySignature))) {
13189
- return false;
13190
- }
13191
- return true;
13192
- }
13193
- function isPublicKeySubject(data) {
13194
- if (data === void 0)
13195
- return true;
13196
- if (isStringOrStringArray(data))
13197
- return true;
13198
- if (!isMandatoryJSONObject(data))
13199
- return false;
13200
- return Object.values(data).every(
13201
- (value) => typeof value === "string" || isStringOrStringArray(value)
13202
- );
13203
- }
13204
- function IsAPublicKeySignature(data) {
13205
- if (!isMandatoryJSONObject(data))
13206
- return false;
13207
- if (!isOptionalString(data["@id"]))
13208
- return false;
13209
- if (data["@context"] !== void 0 && !isStringOrStringArray(data["@context"]))
13210
- return false;
13211
- if (!isOptionalStringOrOIDInfo(data["algorithm"]))
13212
- return false;
13213
- if (!isOptionalString(data["format"]))
13214
- return false;
13215
- if (!isOptionalString(data["encoding"]))
13216
- return false;
13217
- if (data["value"] !== void 0 && !isString(data["value"]))
13218
- return false;
13219
- if (data["publicKey"] !== void 0 && !isEncodedValue(data["publicKey"]))
13220
- return false;
13221
- if (data["signature"] !== void 0 && !isEncodedValue(data["signature"]))
13222
- return false;
13223
- if (!isOptionalString(data["timestamp"]))
13224
- return false;
13225
- if (!isOptionalString(data["issuer"]))
13226
- return false;
13227
- if (!isOptionalString(data["signer"]))
13228
- return false;
13229
- if (!isOptionalString(data["notBefore"]))
13230
- return false;
13231
- if (!isOptionalString(data["notAfter"]))
13232
- return false;
13233
- if (!isOptionalStringArray(data["keyUsage"]))
13234
- return false;
13235
- if (data["operations"] !== void 0 && !isMandatoryJSONObject(data["operations"]))
13236
- return false;
13237
- if (data["comment"] !== void 0 && !isMandatoryJSONObject(data["comment"]))
13238
- return false;
13239
- return data["value"] !== void 0 || data["signature"] !== void 0 || data["algorithm"] !== void 0 || data["timestamp"] !== void 0 || data["issuer"] !== void 0 || data["signer"] !== void 0 || data["keyUsage"] !== void 0;
13240
- }
13241
- function IsAPublicKeyXY(data) {
13242
- if (!IsAPublicKey(data))
13243
- return false;
13244
- if (!isString(data["x"])) {
13245
- return false;
13246
- }
13247
- if (!isString(data["y"])) {
13248
- return false;
13249
- }
13250
- return true;
13251
- }
13252
14195
  var MENNEKES_EDL40_XMLNS = "http://www.mennekes.de/Mennekes.EdlVerification.xsd";
13253
14196
  var MENNEKES_EDL40_OBIS = "1-0:1.17.0*255";
13254
14197
  var Mennekes = class {
@@ -13986,6 +14929,9 @@ var OCMF = class {
13986
14929
  //#region (private) tryToParseOCMFv1_0(OCMFDataList, ContainerInfos?)
13987
14930
  tryToParseOCMFv1_0(OCMFJSONDocuments, ContainerInfos) {
13988
14931
  try {
14932
+ const containerChargingStation = ContainerInfos?.chargingStations?.[0];
14933
+ const containerEVSE = containerChargingStation?.EVSEs?.[0] ?? ContainerInfos?.EVSEs?.[0];
14934
+ const containerConnector = containerEVSE?.connectors?.[0] ?? ContainerInfos?.connectors?.[0];
13989
14935
  const firstOCMDJSONDocument = getFirstArrayElement(OCMFJSONDocuments, "Missing first OCMF JSON document");
13990
14936
  const formatVersion = firstOCMDJSONDocument.payload.FV;
13991
14937
  const gatewayInformation = firstOCMDJSONDocument.payload.GI ?? firstOCMDJSONDocument.payload.VI;
@@ -14122,7 +15068,6 @@ var OCMF = class {
14122
15068
  "@context": "https://open.charging.cloud/contexts/SessionSignatureFormats/OCMFv1.0+json",
14123
15069
  "begin": "?",
14124
15070
  "end": "?",
14125
- //"EVSEId": evseId,
14126
15071
  "authorizationStart": {
14127
15072
  "@id": identificationData ?? "?",
14128
15073
  "type": identificationType ?? "?",
@@ -14137,6 +15082,18 @@ var OCMF = class {
14137
15082
  };
14138
15083
  if (ContainerInfos?.chargingStations !== void 0)
14139
15084
  CTR.chargingStations = ContainerInfos.chargingStations;
15085
+ if (containerChargingStation !== void 0 && CTR.chargingSessions?.[0] !== void 0) {
15086
+ CTR.chargingSessions[0].chargingStationId = containerChargingStation["@id"];
15087
+ CTR.chargingSessions[0].chargingStation = containerChargingStation;
15088
+ }
15089
+ if (containerEVSE !== void 0 && CTR.chargingSessions?.[0] !== void 0) {
15090
+ CTR.chargingSessions[0].EVSEId = containerEVSE["@id"];
15091
+ CTR.chargingSessions[0].EVSE = containerEVSE;
15092
+ }
15093
+ if (containerConnector !== void 0 && CTR.chargingSessions?.[0] !== void 0) {
15094
+ CTR.chargingSessions[0].ConnectorId = containerConnector["@id"];
15095
+ CTR.chargingSessions[0].Connector = containerConnector;
15096
+ }
14140
15097
  const measurementsByKey = /* @__PURE__ */ new Map();
14141
15098
  for (const ocmfJSONDocument of OCMFJSONDocuments) {
14142
15099
  let inheritedReading = {};
@@ -14271,6 +15228,8 @@ var OCMF = class {
14271
15228
  }
14272
15229
  if (ContainerInfos?.chargingStations !== void 0)
14273
15230
  CTR.chargingStations = ContainerInfos.chargingStations;
15231
+ if (ContainerInfos?.warnings !== void 0)
15232
+ CTR.warnings = [...CTR.warnings ?? [], ...ContainerInfos.warnings];
14274
15233
  CTR.status = OCMFJSONDocuments.every((ocmfJSONDocument) => ocmfJSONDocument.validationStatus === "ValidSignature" /* ValidSignature */) ? "ValidSignature" /* ValidSignature */ : "InvalidSignature" /* InvalidSignature */;
14275
15234
  if (CTR.chargingSessions != null && CTR.chargingSessions.length > 0 && CTR.chargingSessions[0]) {
14276
15235
  CTR.begin = CTR.chargingSessions[0].begin;
@@ -15794,31 +16753,26 @@ var SAFEXML = class _SAFEXML {
15794
16753
  }
15795
16754
  static ParseContainerInfos(XMLDocument, chargy) {
15796
16755
  const containerInfos = {};
16756
+ const addWarning = (message) => {
16757
+ containerInfos.warnings ??= [];
16758
+ containerInfos.warnings.push(
16759
+ CreateWarning(chargy.GetMultilanguageText(message))
16760
+ );
16761
+ };
15797
16762
  const chargingStationElements = getElementsByLocalName(XMLDocument, "chargingStation");
15798
16763
  if (chargingStationElements.length == 0)
15799
16764
  return containerInfos;
15800
- if (chargingStationElements.length > 1) {
15801
- return {
15802
- status: "InvalidSessionFormat" /* InvalidSessionFormat */,
15803
- message: chargy.GetMultilanguageText("Only one chargingStation element is allowed within the given SAFE XML container!"),
15804
- certainty: 0
15805
- };
15806
- }
16765
+ if (chargingStationElements.length > 1)
16766
+ addWarning("Only one chargingStation element is allowed within the given SAFE XML container!");
15807
16767
  if (chargingStationElements[0] === void 0) {
15808
- return {
15809
- status: "InvalidSessionFormat" /* InvalidSessionFormat */,
15810
- message: chargy.GetMultilanguageText("The chargingStation element within the given SAFE XML container is invalid!"),
15811
- certainty: 0
15812
- };
16768
+ addWarning("The chargingStation element within the given SAFE XML container is invalid!");
16769
+ return containerInfos;
15813
16770
  }
15814
16771
  const chargingStationElement = chargingStationElements[0];
15815
16772
  const chargingStationId = chargingStationElement.getAttribute("id")?.trim();
15816
16773
  if (chargingStationId === void 0 || chargingStationId.length == 0) {
15817
- return {
15818
- status: "InvalidSessionFormat" /* InvalidSessionFormat */,
15819
- message: chargy.GetMultilanguageText("The chargingStation identifier within the given SAFE XML container is invalid!"),
15820
- certainty: 0
15821
- };
16774
+ addWarning("The chargingStation identifier within the given SAFE XML container is invalid!");
16775
+ return containerInfos;
15822
16776
  }
15823
16777
  const chargingStation = {
15824
16778
  "@id": chargingStationId
@@ -15848,19 +16802,11 @@ var SAFEXML = class _SAFEXML {
15848
16802
  chargingStation.geoLocation = geoLocation;
15849
16803
  }
15850
16804
  const evseElements = getElementsByLocalName(chargingStationElement, "EVSE");
15851
- if (evseElements.length > 1) {
15852
- return {
15853
- status: "InvalidSessionFormat" /* InvalidSessionFormat */,
15854
- message: chargy.GetMultilanguageText("Only one EVSE element is allowed within the given SAFE XML chargingStation element!"),
15855
- certainty: 0
15856
- };
15857
- }
16805
+ if (evseElements.length > 1)
16806
+ addWarning("Only one EVSE element is allowed within the given SAFE XML chargingStation element!");
15858
16807
  if (evseElements[0] === void 0) {
15859
- return {
15860
- status: "InvalidSessionFormat" /* InvalidSessionFormat */,
15861
- message: chargy.GetMultilanguageText("The EVSE element within the given SAFE XML chargingStation element is invalid!"),
15862
- certainty: 0
15863
- };
16808
+ addWarning("The EVSE element within the given SAFE XML chargingStation element is invalid!");
16809
+ return containerInfos;
15864
16810
  }
15865
16811
  const evseElement = evseElements[0];
15866
16812
  const evseId = evseElement.getAttribute("id")?.trim();
@@ -15873,19 +16819,11 @@ var SAFEXML = class _SAFEXML {
15873
16819
  if (evseDescription !== void 0)
15874
16820
  evse.description = evseDescription;
15875
16821
  const connectorElements = getElementsByLocalName(evseElement, "connector");
15876
- if (connectorElements.length > 1) {
15877
- return {
15878
- status: "InvalidSessionFormat" /* InvalidSessionFormat */,
15879
- message: chargy.GetMultilanguageText("Only one connector element is allowed within the given SAFE XML EVSE element!"),
15880
- certainty: 0
15881
- };
15882
- }
16822
+ if (connectorElements.length > 1)
16823
+ addWarning("Only one connector element is allowed within the given SAFE XML EVSE element!");
15883
16824
  if (connectorElements[0] === void 0) {
15884
- return {
15885
- status: "InvalidSessionFormat" /* InvalidSessionFormat */,
15886
- message: chargy.GetMultilanguageText("The connector element within the given SAFE XML EVSE element is invalid!"),
15887
- certainty: 0
15888
- };
16825
+ addWarning("The connector element within the given SAFE XML EVSE element is invalid!");
16826
+ return containerInfos;
15889
16827
  }
15890
16828
  const connectorElement = connectorElements[0];
15891
16829
  const connector = {};
@@ -15908,8 +16846,6 @@ var SAFEXML = class _SAFEXML {
15908
16846
  XMLDocument,
15909
16847
  this.chargy
15910
16848
  );
15911
- if (isISessionCryptoResult1(safeXMLContext))
15912
- return safeXMLContext;
15913
16849
  const signedDataValues = new Array();
15914
16850
  let commonSignedDataFormat = "";
15915
16851
  let commonSignedDataEncoding = "";
@@ -16003,6 +16939,14 @@ var SAFEXML = class _SAFEXML {
16003
16939
  commonPublicKeyEncoding,
16004
16940
  safeXMLContext
16005
16941
  );
16942
+ case "edl_40_p":
16943
+ case "isa_edl_40_p":
16944
+ case "sml_edl40_p":
16945
+ return await new EDL40(this.chargy).TryToParseEDL40Documents(
16946
+ signedDataValues,
16947
+ commonPublicKey,
16948
+ safeXMLContext
16949
+ );
16006
16950
  default:
16007
16951
  return {
16008
16952
  status: "InvalidSessionFormat" /* InvalidSessionFormat */,
@@ -18234,45 +19178,6 @@ var Chargy = class {
18234
19178
  return fileName.substring(0, lastDot);
18235
19179
  return fileName;
18236
19180
  }
18237
- tryExtractChargeTransparencyTextFromURL(qrText) {
18238
- if (!qrText.startsWith("http://") && !qrText.startsWith("https://"))
18239
- return qrText;
18240
- try {
18241
- const url = new URL(qrText);
18242
- const candidates = [
18243
- url.hash.startsWith("#") ? url.hash.substring(1) : url.hash,
18244
- url.searchParams.get("data"),
18245
- url.searchParams.get("content"),
18246
- url.searchParams.get("ctr"),
18247
- url.searchParams.get("record"),
18248
- url.searchParams.get("payload"),
18249
- url.searchParams.get("q")
18250
- ];
18251
- for (const candidate of candidates) {
18252
- const decodedCandidate = candidate != null ? decodeURIComponent(candidate).trim() : "";
18253
- if (decodedCandidate.startsWith("<?xml") || decodedCandidate.startsWith("<values") || decodedCandidate.startsWith("{") || decodedCandidate.startsWith("[") || decodedCandidate.startsWith("OCMF") || decodedCandidate.startsWith("AP;")) {
18254
- return decodedCandidate;
18255
- }
18256
- }
18257
- } catch {
18258
- console.log("Invalid URL in QR code: " + qrText);
18259
- }
18260
- return qrText;
18261
- }
18262
- tryExtractSignedDataTextFromXML(qrText) {
18263
- const trimmedQRCodeText = qrText.trim();
18264
- if (!trimmedQRCodeText.startsWith("<?xml") && !trimmedQRCodeText.startsWith("<"))
18265
- return qrText;
18266
- try {
18267
- const xmlDocument = new DOMParser().parseFromString(trimmedQRCodeText, "text/xml");
18268
- const signedDataValues = getElementsByLocalName(xmlDocument, "signedData").filter((signedData) => (signedData.getAttribute("format") ?? "").trim().toLowerCase() === "alfen").map((signedData) => signedData.textContent.trim()).filter((signedData) => signedData.startsWith("AP;"));
18269
- if (signedDataValues.length > 0)
18270
- return signedDataValues.join("\n");
18271
- } catch {
18272
- console.log("Error parsing XML content from QR code: " + qrText);
18273
- }
18274
- return qrText;
18275
- }
18276
19181
  //#region Public key methods...
18277
19182
  PublicKeyIdFromFileName(fileName) {
18278
19183
  return (fileName.includes(".") ? fileName.substring(0, fileName.indexOf(".")) : fileName).replace(/[-_]?public[-_]?key/i, "");
@@ -18358,25 +19263,70 @@ var Chargy = class {
18358
19263
  }
18359
19264
  //#endregion
18360
19265
  //#region QR code image files...
18361
- isSupportedQRCodeImageFile(fileInfo, mimeType) {
18362
- const mimeTypeToCheck = (mimeType ?? fileInfo.type ?? "").toLowerCase();
18363
- const fileName = fileInfo.name.toLowerCase();
18364
- return mimeTypeToCheck === "image/png" || mimeTypeToCheck === "image/jpeg" || mimeTypeToCheck === "image/jpg" || mimeTypeToCheck === "image/gif" || mimeTypeToCheck === "image/webp" || mimeTypeToCheck === "image/bmp" || mimeTypeToCheck === "image/svg+xml" || fileName.endsWith(".png") || fileName.endsWith(".jpg") || fileName.endsWith(".jpeg") || fileName.endsWith(".gif") || fileName.endsWith(".webp") || fileName.endsWith(".bmp") || fileName.endsWith(".svg");
19266
+ normalizeMIMEType(mimeType) {
19267
+ return mimeType?.split(";")[0]?.trim().toLowerCase();
19268
+ }
19269
+ getQRCodeImageMIMETypeFromFileName(fileName) {
19270
+ fileName = fileName.toLowerCase();
19271
+ if (fileName.endsWith(".png"))
19272
+ return "image/png";
19273
+ if (fileName.endsWith(".jpeg"))
19274
+ return "image/jpeg";
19275
+ if (fileName.endsWith(".jpg"))
19276
+ return "image/jpg";
19277
+ if (fileName.endsWith(".gif"))
19278
+ return "image/gif";
19279
+ if (fileName.endsWith(".webp"))
19280
+ return "image/webp";
19281
+ if (fileName.endsWith(".bmp"))
19282
+ return "image/bmp";
19283
+ if (fileName.endsWith(".svg"))
19284
+ return "image/svg+xml";
19285
+ return void 0;
19286
+ }
19287
+ getQRCodeImageMIMEType(fileInfo, mimeType) {
19288
+ const detectedMIMEType = this.normalizeMIMEType(mimeType);
19289
+ const declaredMIMEType = this.normalizeMIMEType(fileInfo.type);
19290
+ const fileNameMIMEType = this.getQRCodeImageMIMETypeFromFileName(fileInfo.name);
19291
+ if (this.isSupportedQRCodeImageFileType(detectedMIMEType))
19292
+ return detectedMIMEType;
19293
+ if (this.isSupportedQRCodeImageFileType(declaredMIMEType))
19294
+ return declaredMIMEType;
19295
+ if (fileNameMIMEType !== void 0)
19296
+ return fileNameMIMEType;
19297
+ return detectedMIMEType ?? declaredMIMEType;
19298
+ }
19299
+ isSupportedQRCodeImageFileType(MIMEType) {
19300
+ switch (MIMEType) {
19301
+ case void 0:
19302
+ return false;
19303
+ case "image/png":
19304
+ case "image/jpeg":
19305
+ case "image/jpg":
19306
+ case "image/gif":
19307
+ case "image/webp":
19308
+ case "image/bmp":
19309
+ case "image/svg":
19310
+ case "image/svg+xml":
19311
+ return true;
19312
+ }
19313
+ return false;
18365
19314
  }
18366
19315
  async expandQRCodeImageFiles(FileInfos) {
18367
19316
  const expandedFileInfos = new Array();
18368
19317
  for (const fileInfo of FileInfos) {
18369
- if (fileInfo.data != null && this.isSupportedQRCodeImageFile(fileInfo)) {
18370
- const qrText = await readQRCodeTextFromImage(fileInfo.data, fileInfo.type);
19318
+ const mimeType = this.getQRCodeImageMIMEType(fileInfo);
19319
+ if (fileInfo.data != null && this.isSupportedQRCodeImageFileType(mimeType)) {
19320
+ const qrText = await readQRCodeTextFromImage(
19321
+ fileInfo.data,
19322
+ mimeType
19323
+ );
18371
19324
  if (qrText != null) {
18372
- const extractedText = this.tryExtractSignedDataTextFromXML(
18373
- this.tryExtractChargeTransparencyTextFromURL(qrText)
18374
- );
18375
19325
  expandedFileInfos.push({
18376
- name: this.textFileNameForQRCodeContent(fileInfo.name, extractedText),
19326
+ name: this.textFileNameForQRCodeContent(fileInfo.name, qrText),
18377
19327
  path: fileInfo.path,
18378
19328
  type: "text/plain",
18379
- data: new TextEncoder().encode(extractedText),
19329
+ data: new TextEncoder().encode(qrText),
18380
19330
  info: "Text extracted from QR code image"
18381
19331
  });
18382
19332
  continue;
@@ -18575,55 +19525,42 @@ var Chargy = class {
18575
19525
  if (FileInfo.data != null && FileInfo.data.byteLength > 0) {
18576
19526
  try {
18577
19527
  const filetype = await fileTypeFromBuffer(FileInfo.data);
18578
- if (filetype?.mime == void 0) {
18579
- if (this.isSupportedQRCodeImageFile(FileInfo))
18580
- expandedFileInfos.push({
18581
- name: FileInfo.name,
18582
- data: FileInfo.data,
18583
- type: FileInfo.type,
18584
- info: "QR code image file"
18585
- });
18586
- else if (FileInfo.name.endsWith(".chargy"))
18587
- expandedFileInfos.push({
18588
- name: FileInfo.name,
18589
- data: FileInfo.data,
18590
- info: ".chargy file"
18591
- });
18592
- else
18593
- expandedFileInfos.push({
18594
- name: FileInfo.name,
18595
- data: FileInfo.data,
18596
- exception: "Unknown file type!"
18597
- });
19528
+ const mimeType = this.getQRCodeImageMIMEType(FileInfo, filetype?.mime);
19529
+ if (this.isSupportedQRCodeImageFileType(mimeType)) {
19530
+ expandedFileInfos.push({
19531
+ name: FileInfo.name,
19532
+ data: FileInfo.data,
19533
+ type: FileInfo.type ?? mimeType,
19534
+ info: "QR code image file"
19535
+ });
18598
19536
  continue;
18599
- } else if (filetype.mime === "text/xml" || filetype.mime === "application/xml") {
19537
+ } else if (FileInfo.name.endsWith(".chargy")) {
18600
19538
  expandedFileInfos.push({
18601
19539
  name: FileInfo.name,
18602
19540
  data: FileInfo.data,
18603
- info: "XML file"
19541
+ info: ".chargy file"
18604
19542
  });
18605
19543
  continue;
18606
- } else if (filetype.mime === "text/json" || filetype.mime === "application/json") {
19544
+ } else if (mimeType === "text/xml" || mimeType === "application/xml") {
18607
19545
  expandedFileInfos.push({
18608
19546
  name: FileInfo.name,
18609
19547
  data: FileInfo.data,
18610
- info: "JSON file"
19548
+ info: "XML file"
18611
19549
  });
18612
19550
  continue;
18613
- } else if (this.isSupportedQRCodeImageFile(FileInfo, filetype.mime)) {
19551
+ } else if (mimeType === "text/json" || mimeType === "application/json") {
18614
19552
  expandedFileInfos.push({
18615
19553
  name: FileInfo.name,
18616
19554
  data: FileInfo.data,
18617
- type: filetype.mime,
18618
- info: "QR code image file"
19555
+ info: "JSON file"
18619
19556
  });
18620
19557
  continue;
18621
- } else if (filetype.mime === "application/zip" || filetype.mime === "application/x-bzip2" || filetype.mime === "application/gzip" || filetype.mime === "application/x-tar") {
19558
+ } else if (mimeType === "application/zip" || mimeType === "application/x-bzip2" || mimeType === "application/gzip" || mimeType === "application/x-tar") {
18622
19559
  try {
18623
19560
  const compressedFiles = await this.extractArchive(
18624
19561
  FileInfo.name,
18625
19562
  FileInfo.data,
18626
- filetype.mime
19563
+ mimeType
18627
19564
  );
18628
19565
  if (compressedFiles.length == 0)
18629
19566
  continue;
@@ -18695,6 +19632,12 @@ var Chargy = class {
18695
19632
  }
18696
19633
  continue;
18697
19634
  }
19635
+ expandedFileInfos.push({
19636
+ name: FileInfo.name,
19637
+ data: FileInfo.data,
19638
+ exception: "Unknown file type!"
19639
+ });
19640
+ continue;
18698
19641
  } catch (exception) {
18699
19642
  expandedFileInfos.push({
18700
19643
  name: FileInfo.name,
@@ -19410,6 +20353,10 @@ var Chargy = class {
19410
20353
  chargingSession.method = new PCDFCrypt01(this);
19411
20354
  verificationResult2 = await chargingSession.method.VerifyChargingSession(chargingSession);
19412
20355
  break;
20356
+ case "https://open.charging.cloud/contexts/SessionSignatureFormats/EDL40+json":
20357
+ chargingSession.method = new EDL40Crypt01(this);
20358
+ verificationResult2 = await chargingSession.method.VerifyChargingSession(chargingSession);
20359
+ break;
19413
20360
  case "https://open.charging.cloud/contexts/SessionSignatureFormats/bsm-ws36a-v0+json":
19414
20361
  chargingSession.method = new BSMCrypt01(this);
19415
20362
  verificationResult2 = await chargingSession.method.VerifyChargingSession(chargingSession);
@@ -19503,6 +20450,6 @@ buffer/index.js:
19503
20450
  *)
19504
20451
  */
19505
20452
 
19506
- export { ACrypt, Alfen, AlfenCrypt01, BSMCrypt01, CanonicalJSONError, ChargeIT, ChargePoint, ChargePointCrypt01, IChargeTransparencyLiveLink_exports as ChargeTransparencyLiveLink, ChargeTransparencyLiveLinkContext, IChargeTransparencyRecord_exports as ChargeTransparencyRecord, Chargy, chargyInterfaces_exports as ChargyInterfaces, Clone, CloneCTR, ConcatenateBuffers, CreateDiv, CreateDiv2, CreateError, CryptoAlgorithms, CryptoHashAlgorithms, DayOfWeek, DisplayPrefixes, EMHCrypt01, ErrorLevel, GDFCrypt01, IECCurves, IEncoding, InformationRelevance, InformationRelevanceToString, IsAChargeTransparencyLiveLink, IsAChargeTransparencyRecord, IsAPublicKey, IsAPublicKeyLookup, IsAPublicKeySignature, IsAPublicKeyXY, IsASessionCryptoResult, IsNullOrEmpty, JSONSignatureVerificationStatus, MENNEKES_EDL40_OBIS, MENNEKES_EDL40_XMLNS, Mennekes, MennekesCrypt01, OBIS2Hex, OBIS2MeasurementName, OBIS_RegExpr, OCMF, OCMFTransactionTypes, OCMFv1_x, OCPI, OIDInfo, PCDF, PCDFCrypt01, PCDFParseError, PCDFValidationError, PCDF_FIELD_ORDER, PCDF_PREFIX, ParseJSON_LD, PublicKeyFormats, IPublicKeyInfo_exports as PublicKeyInfo, SAFEXML, SessionVerificationResult, SetHex, SetInt8, SetText, SetText_withLength, SetTimestamp, SetTimestamp32, SetUInt32, SetUInt32_withCode, SetUInt64, SetUInt64D, SignMessage, SignatureFormats, TimeStatusTypes, UTC2human, VerificationResult, VerifyJSONMessageSignatures, WarningLevel, WhenNullOrEmpty, XMLContainer, asJSONArray, asJSONObject, asNumber, asString, base64ToBytes, buf2hex, buildMennekesSignatureData, bytesToBase64, bytesToHex, canonicalJSONBytes, canonicalJSONStringify, cleanHex, closeFullscreen, createHexString, dateToMennekesLocalEpochSeconds, extractMennekesChargingProcesses, firstKey, firstValue, getArrayElement, getArrayLikeElement, getDirectChildByLocalName, getDirectChildrenByLocalName, getElementsByLocalName, getFirstArrayElement, getInt16Bytes, getInt32Bytes, getInt64Bytes, getInt8Bytes, getLastArrayElement, getTrimmedTextContent, hashFile, hex2bin, hex32, hexToArrayBuffer, hexToBytes, intFromBytes, isEncodedValue, isGeoLocation, isI18NString, isICryptoResult, isIFileInfo, isISessionCryptoResult1, isISessionCryptoResult2, isJSONLDObject, isMandatoryArrayOfStrings, isMandatoryBoolean, isMandatoryDecimal, isMandatoryJSONArray, isMandatoryJSONObject, isMandatoryNumber, isMandatoryString, isMandatoryURL, isOIDInfo, isObject, isOptionalArrayOfStrings, isOptionalDecimal, isOptionalJSONArray, isOptionalJSONArrayError, isOptionalJSONArrayOk, isOptionalJSONObject, isOptionalNumber, isOptionalString, isOptionalStringArray, isOptionalStringOrOIDInfo, isOptionalURL, isPCDFText, isPublicKeySubject, isString, isStringArray, isStringOrOIDInfo, isStringOrStringArray, jsonPrettyPrinter, measurementName2human, normalizePCDFPublicKeyHex, normalizeXMLText, openFullscreen, pad, parseAndVerifyJSONSignatures, parseDescription, parseHexString, parseMennekesXMLDocument, parseNumber, parseOBIS, parsePCDFDocument, parsePCDFPublicKey, parsePCDFSignature, parseUTC, readQRCodeTextFromImage, readQRCodeTextFromImageData, secp224k1, setUILocale, sha256, sha256____, sha384, sha384____, sha512, sha512____, signJSONMessage, signMessage, stripPCDFControlCharacters, time2human, toArrayBuffer, toSessionVerificationResults, toUint8Array, unquotePCDFText, validatePCDFFields, verifyJSONMessageSignatureResults, verifyJSONMessageSignatures, verifyJSONSignature, verifyJSONSignatureResult, verifyPCDFDocument };
20453
+ export { ACrypt, Alfen, AlfenCrypt01, BSMCrypt01, CanonicalJSONError, ChargeIT, ChargePoint, ChargePointCrypt01, IChargeTransparencyLiveLink_exports as ChargeTransparencyLiveLink, ChargeTransparencyLiveLinkContext, IChargeTransparencyRecord_exports as ChargeTransparencyRecord, Chargy, chargyInterfaces_exports as ChargyInterfaces, Clone, CloneCTR, ConcatenateBuffers, CreateDiv, CreateDiv2, CreateError, CreateWarning, CryptoAlgorithms, CryptoHashAlgorithms, DayOfWeek, DisplayPrefixes, EDL40, EDL40Crypt01, EDL40ValidationError, EDL40_OBIS, EDL40_SESSION_CONTEXT, EDL40_SIGNATURE_CONTEXT, EMHCrypt01, ErrorLevel, GDFCrypt01, IECCurves, IEncoding, InformationRelevance, InformationRelevanceToString, IsAChargeTransparencyLiveLink, IsAChargeTransparencyRecord, IsAPublicKey, IsAPublicKeyLookup, IsAPublicKeySignature, IsAPublicKeyXY, IsASessionCryptoResult, IsNullOrEmpty, JSONSignatureVerificationStatus, MENNEKES_EDL40_OBIS, MENNEKES_EDL40_XMLNS, Mennekes, MennekesCrypt01, OBIS2Hex, OBIS2MeasurementName, OBIS_RegExpr, OCMF, OCMFTransactionTypes, OCMFv1_x, OCPI, OIDInfo, PCDF, PCDFCrypt01, PCDFParseError, PCDFValidationError, PCDF_FIELD_ORDER, PCDF_PREFIX, ParseJSON_LD, PublicKeyFormats, IPublicKeyInfo_exports as PublicKeyInfo, SAFEXML, SessionVerificationResult, SetHex, SetInt8, SetText, SetText_withLength, SetTimestamp, SetTimestamp32, SetUInt32, SetUInt32_withCode, SetUInt64, SetUInt64D, SignMessage, SignatureFormats, TimeStatusTypes, UTC2human, VerificationResult, VerifyJSONMessageSignatures, WarningLevel, WhenNullOrEmpty, XMLContainer, asJSONArray, asJSONObject, asNumber, asString, base64ToBytes, buf2hex, buildEDL40Signature, buildIsaSignature, buildMennekesSignatureData, bytesToBase64, bytesToHex, canParseEDL40, canonicalJSONBytes, canonicalJSONStringify, cleanHex, closeFullscreen, createHexString, dateToMennekesLocalEpochSeconds, decodeSmlMessages, extractMennekesChargingProcesses, findEntryByObis, findGetListRes, firstKey, firstValue, getArrayElement, getArrayLikeElement, getDirectChildByLocalName, getDirectChildrenByLocalName, getElementsByLocalName, getFirstArrayElement, getInt16Bytes, getInt32Bytes, getInt64Bytes, getInt8Bytes, getLastArrayElement, getTrimmedTextContent, hashFile, hex2bin, hex32, hexToArrayBuffer, hexToBytes, intFromBytes, isEncodedValue, isGeoLocation, isI18NString, isICryptoResult, isIFileInfo, isISessionCryptoResult1, isISessionCryptoResult2, isJSONLDObject, isMandatoryArrayOfStrings, isMandatoryBoolean, isMandatoryDecimal, isMandatoryJSONArray, isMandatoryJSONObject, isMandatoryNumber, isMandatoryString, isMandatoryURL, isOIDInfo, isObject, isOptionalArrayOfStrings, isOptionalDecimal, isOptionalJSONArray, isOptionalJSONArrayError, isOptionalJSONArrayOk, isOptionalJSONObject, isOptionalNumber, isOptionalString, isOptionalStringArray, isOptionalStringOrOIDInfo, isOptionalURL, isPCDFText, isPublicKeySubject, isString, isStringArray, isStringOrOIDInfo, isStringOrStringArray, isaListNameContext, jsonPrettyPrinter, measurementName2human, normalizePCDFPublicKeyHex, normalizeXMLText, openFullscreen, pad, parseAndVerifyJSONSignatures, parseDescription, parseEDL40, parseHexString, parseMennekesXMLDocument, parseNumber, parseOBIS, parsePCDFDocument, parsePCDFPublicKey, parsePCDFSignature, parseSmlTime, parseUTC, readQRCodeTextFromImage, readQRCodeTextFromImageData, readTLV, secp224k1, setUILocale, sha256, sha256____, sha384, sha384____, sha512, sha512____, signJSONMessage, signMessage, stripPCDFControlCharacters, stripTransport, time2human, toArrayBuffer, toSessionVerificationResults, toUint8Array, transformEDL40Status, unquotePCDFText, validatePCDFFields, verifyEDL40Document, verifyJSONMessageSignatureResults, verifyJSONMessageSignatures, verifyJSONSignature, verifyJSONSignatureResult, verifyPCDFDocument };
19507
20454
  //# sourceMappingURL=index.js.map
19508
20455
  //# sourceMappingURL=index.js.map