@open-charging-cloud/chargy-core 0.7.1 → 0.9.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.
- package/README.md +54 -10
- package/dist/Alfen.d.ts.map +1 -1
- package/dist/EDL40.d.ts +178 -0
- package/dist/EDL40.d.ts.map +1 -0
- package/dist/OCMF.d.ts +15 -2
- package/dist/OCMF.d.ts.map +1 -1
- package/dist/OCMF_BET_TariffTextExtension.d.ts +33 -0
- package/dist/OCMF_BET_TariffTextExtension.d.ts.map +1 -0
- package/dist/PTBContainer.d.ts +49 -0
- package/dist/PTBContainer.d.ts.map +1 -0
- package/dist/SAFE_XML.d.ts.map +1 -1
- package/dist/browser/index.js +1778 -430
- package/dist/browser/index.js.map +1 -1
- package/dist/chargy.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/interfaces/IChargeTransparencyRecord.d.ts +2 -0
- package/dist/interfaces/IChargeTransparencyRecord.d.ts.map +1 -1
- package/dist/interfaces/chargyInterfaces.d.ts +17 -14
- package/dist/interfaces/chargyInterfaces.d.ts.map +1 -1
- package/dist/node/index.js +1776 -428
- package/dist/node/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/verificationResults.d.ts +0 -2
- package/dist/verificationResults.d.ts.map +0 -1
package/dist/node/index.js
CHANGED
|
@@ -150,11 +150,11 @@ var require_bn = __commonJS({
|
|
|
150
150
|
}
|
|
151
151
|
} catch (e) {
|
|
152
152
|
}
|
|
153
|
-
BN.isBN = function isBN(
|
|
154
|
-
if (
|
|
153
|
+
BN.isBN = function isBN(num2) {
|
|
154
|
+
if (num2 instanceof BN) {
|
|
155
155
|
return true;
|
|
156
156
|
}
|
|
157
|
-
return
|
|
157
|
+
return num2 !== null && typeof num2 === "object" && num2.constructor.wordSize === BN.wordSize && Array.isArray(num2.words);
|
|
158
158
|
};
|
|
159
159
|
BN.max = function max(left, right) {
|
|
160
160
|
if (left.cmp(right) > 0) return left;
|
|
@@ -675,12 +675,12 @@ var require_bn = __commonJS({
|
|
|
675
675
|
var hi = this._countBits(w);
|
|
676
676
|
return (this.length - 1) * 26 + hi;
|
|
677
677
|
};
|
|
678
|
-
function toBitArray(
|
|
679
|
-
var w = new Array(
|
|
678
|
+
function toBitArray(num2) {
|
|
679
|
+
var w = new Array(num2.bitLength());
|
|
680
680
|
for (var bit = 0; bit < w.length; bit++) {
|
|
681
681
|
var off = bit / 26 | 0;
|
|
682
682
|
var wbit = bit % 26;
|
|
683
|
-
w[bit] = (
|
|
683
|
+
w[bit] = (num2.words[off] & 1 << wbit) >>> wbit;
|
|
684
684
|
}
|
|
685
685
|
return w;
|
|
686
686
|
}
|
|
@@ -721,60 +721,60 @@ var require_bn = __commonJS({
|
|
|
721
721
|
}
|
|
722
722
|
return this;
|
|
723
723
|
};
|
|
724
|
-
BN.prototype.iuor = function iuor(
|
|
725
|
-
while (this.length <
|
|
724
|
+
BN.prototype.iuor = function iuor(num2) {
|
|
725
|
+
while (this.length < num2.length) {
|
|
726
726
|
this.words[this.length++] = 0;
|
|
727
727
|
}
|
|
728
|
-
for (var i = 0; i <
|
|
729
|
-
this.words[i] = this.words[i] |
|
|
728
|
+
for (var i = 0; i < num2.length; i++) {
|
|
729
|
+
this.words[i] = this.words[i] | num2.words[i];
|
|
730
730
|
}
|
|
731
731
|
return this.strip();
|
|
732
732
|
};
|
|
733
|
-
BN.prototype.ior = function ior(
|
|
734
|
-
assert((this.negative |
|
|
735
|
-
return this.iuor(
|
|
733
|
+
BN.prototype.ior = function ior(num2) {
|
|
734
|
+
assert((this.negative | num2.negative) === 0);
|
|
735
|
+
return this.iuor(num2);
|
|
736
736
|
};
|
|
737
|
-
BN.prototype.or = function or(
|
|
738
|
-
if (this.length >
|
|
739
|
-
return
|
|
737
|
+
BN.prototype.or = function or(num2) {
|
|
738
|
+
if (this.length > num2.length) return this.clone().ior(num2);
|
|
739
|
+
return num2.clone().ior(this);
|
|
740
740
|
};
|
|
741
|
-
BN.prototype.uor = function uor(
|
|
742
|
-
if (this.length >
|
|
743
|
-
return
|
|
741
|
+
BN.prototype.uor = function uor(num2) {
|
|
742
|
+
if (this.length > num2.length) return this.clone().iuor(num2);
|
|
743
|
+
return num2.clone().iuor(this);
|
|
744
744
|
};
|
|
745
|
-
BN.prototype.iuand = function iuand(
|
|
745
|
+
BN.prototype.iuand = function iuand(num2) {
|
|
746
746
|
var b;
|
|
747
|
-
if (this.length >
|
|
748
|
-
b =
|
|
747
|
+
if (this.length > num2.length) {
|
|
748
|
+
b = num2;
|
|
749
749
|
} else {
|
|
750
750
|
b = this;
|
|
751
751
|
}
|
|
752
752
|
for (var i = 0; i < b.length; i++) {
|
|
753
|
-
this.words[i] = this.words[i] &
|
|
753
|
+
this.words[i] = this.words[i] & num2.words[i];
|
|
754
754
|
}
|
|
755
755
|
this.length = b.length;
|
|
756
756
|
return this.strip();
|
|
757
757
|
};
|
|
758
|
-
BN.prototype.iand = function iand(
|
|
759
|
-
assert((this.negative |
|
|
760
|
-
return this.iuand(
|
|
758
|
+
BN.prototype.iand = function iand(num2) {
|
|
759
|
+
assert((this.negative | num2.negative) === 0);
|
|
760
|
+
return this.iuand(num2);
|
|
761
761
|
};
|
|
762
|
-
BN.prototype.and = function and(
|
|
763
|
-
if (this.length >
|
|
764
|
-
return
|
|
762
|
+
BN.prototype.and = function and(num2) {
|
|
763
|
+
if (this.length > num2.length) return this.clone().iand(num2);
|
|
764
|
+
return num2.clone().iand(this);
|
|
765
765
|
};
|
|
766
|
-
BN.prototype.uand = function uand(
|
|
767
|
-
if (this.length >
|
|
768
|
-
return
|
|
766
|
+
BN.prototype.uand = function uand(num2) {
|
|
767
|
+
if (this.length > num2.length) return this.clone().iuand(num2);
|
|
768
|
+
return num2.clone().iuand(this);
|
|
769
769
|
};
|
|
770
|
-
BN.prototype.iuxor = function iuxor(
|
|
770
|
+
BN.prototype.iuxor = function iuxor(num2) {
|
|
771
771
|
var a;
|
|
772
772
|
var b;
|
|
773
|
-
if (this.length >
|
|
773
|
+
if (this.length > num2.length) {
|
|
774
774
|
a = this;
|
|
775
|
-
b =
|
|
775
|
+
b = num2;
|
|
776
776
|
} else {
|
|
777
|
-
a =
|
|
777
|
+
a = num2;
|
|
778
778
|
b = this;
|
|
779
779
|
}
|
|
780
780
|
for (var i = 0; i < b.length; i++) {
|
|
@@ -788,17 +788,17 @@ var require_bn = __commonJS({
|
|
|
788
788
|
this.length = a.length;
|
|
789
789
|
return this.strip();
|
|
790
790
|
};
|
|
791
|
-
BN.prototype.ixor = function ixor(
|
|
792
|
-
assert((this.negative |
|
|
793
|
-
return this.iuxor(
|
|
791
|
+
BN.prototype.ixor = function ixor(num2) {
|
|
792
|
+
assert((this.negative | num2.negative) === 0);
|
|
793
|
+
return this.iuxor(num2);
|
|
794
794
|
};
|
|
795
|
-
BN.prototype.xor = function xor(
|
|
796
|
-
if (this.length >
|
|
797
|
-
return
|
|
795
|
+
BN.prototype.xor = function xor(num2) {
|
|
796
|
+
if (this.length > num2.length) return this.clone().ixor(num2);
|
|
797
|
+
return num2.clone().ixor(this);
|
|
798
798
|
};
|
|
799
|
-
BN.prototype.uxor = function uxor(
|
|
800
|
-
if (this.length >
|
|
801
|
-
return
|
|
799
|
+
BN.prototype.uxor = function uxor(num2) {
|
|
800
|
+
if (this.length > num2.length) return this.clone().iuxor(num2);
|
|
801
|
+
return num2.clone().iuxor(this);
|
|
802
802
|
};
|
|
803
803
|
BN.prototype.inotn = function inotn(width) {
|
|
804
804
|
assert(typeof width === "number" && width >= 0);
|
|
@@ -831,25 +831,25 @@ var require_bn = __commonJS({
|
|
|
831
831
|
}
|
|
832
832
|
return this.strip();
|
|
833
833
|
};
|
|
834
|
-
BN.prototype.iadd = function iadd(
|
|
834
|
+
BN.prototype.iadd = function iadd(num2) {
|
|
835
835
|
var r;
|
|
836
|
-
if (this.negative !== 0 &&
|
|
836
|
+
if (this.negative !== 0 && num2.negative === 0) {
|
|
837
837
|
this.negative = 0;
|
|
838
|
-
r = this.isub(
|
|
838
|
+
r = this.isub(num2);
|
|
839
839
|
this.negative ^= 1;
|
|
840
840
|
return this._normSign();
|
|
841
|
-
} else if (this.negative === 0 &&
|
|
842
|
-
|
|
843
|
-
r = this.isub(
|
|
844
|
-
|
|
841
|
+
} else if (this.negative === 0 && num2.negative !== 0) {
|
|
842
|
+
num2.negative = 0;
|
|
843
|
+
r = this.isub(num2);
|
|
844
|
+
num2.negative = 1;
|
|
845
845
|
return r._normSign();
|
|
846
846
|
}
|
|
847
847
|
var a, b;
|
|
848
|
-
if (this.length >
|
|
848
|
+
if (this.length > num2.length) {
|
|
849
849
|
a = this;
|
|
850
|
-
b =
|
|
850
|
+
b = num2;
|
|
851
851
|
} else {
|
|
852
|
-
a =
|
|
852
|
+
a = num2;
|
|
853
853
|
b = this;
|
|
854
854
|
}
|
|
855
855
|
var carry = 0;
|
|
@@ -874,35 +874,35 @@ var require_bn = __commonJS({
|
|
|
874
874
|
}
|
|
875
875
|
return this;
|
|
876
876
|
};
|
|
877
|
-
BN.prototype.add = function add(
|
|
877
|
+
BN.prototype.add = function add(num2) {
|
|
878
878
|
var res;
|
|
879
|
-
if (
|
|
880
|
-
|
|
881
|
-
res = this.sub(
|
|
882
|
-
|
|
879
|
+
if (num2.negative !== 0 && this.negative === 0) {
|
|
880
|
+
num2.negative = 0;
|
|
881
|
+
res = this.sub(num2);
|
|
882
|
+
num2.negative ^= 1;
|
|
883
883
|
return res;
|
|
884
|
-
} else if (
|
|
884
|
+
} else if (num2.negative === 0 && this.negative !== 0) {
|
|
885
885
|
this.negative = 0;
|
|
886
|
-
res =
|
|
886
|
+
res = num2.sub(this);
|
|
887
887
|
this.negative = 1;
|
|
888
888
|
return res;
|
|
889
889
|
}
|
|
890
|
-
if (this.length >
|
|
891
|
-
return
|
|
890
|
+
if (this.length > num2.length) return this.clone().iadd(num2);
|
|
891
|
+
return num2.clone().iadd(this);
|
|
892
892
|
};
|
|
893
|
-
BN.prototype.isub = function isub(
|
|
894
|
-
if (
|
|
895
|
-
|
|
896
|
-
var r = this.iadd(
|
|
897
|
-
|
|
893
|
+
BN.prototype.isub = function isub(num2) {
|
|
894
|
+
if (num2.negative !== 0) {
|
|
895
|
+
num2.negative = 0;
|
|
896
|
+
var r = this.iadd(num2);
|
|
897
|
+
num2.negative = 1;
|
|
898
898
|
return r._normSign();
|
|
899
899
|
} else if (this.negative !== 0) {
|
|
900
900
|
this.negative = 0;
|
|
901
|
-
this.iadd(
|
|
901
|
+
this.iadd(num2);
|
|
902
902
|
this.negative = 1;
|
|
903
903
|
return this._normSign();
|
|
904
904
|
}
|
|
905
|
-
var cmp = this.cmp(
|
|
905
|
+
var cmp = this.cmp(num2);
|
|
906
906
|
if (cmp === 0) {
|
|
907
907
|
this.negative = 0;
|
|
908
908
|
this.length = 1;
|
|
@@ -912,9 +912,9 @@ var require_bn = __commonJS({
|
|
|
912
912
|
var a, b;
|
|
913
913
|
if (cmp > 0) {
|
|
914
914
|
a = this;
|
|
915
|
-
b =
|
|
915
|
+
b = num2;
|
|
916
916
|
} else {
|
|
917
|
-
a =
|
|
917
|
+
a = num2;
|
|
918
918
|
b = this;
|
|
919
919
|
}
|
|
920
920
|
var carry = 0;
|
|
@@ -939,16 +939,16 @@ var require_bn = __commonJS({
|
|
|
939
939
|
}
|
|
940
940
|
return this.strip();
|
|
941
941
|
};
|
|
942
|
-
BN.prototype.sub = function sub(
|
|
943
|
-
return this.clone().isub(
|
|
942
|
+
BN.prototype.sub = function sub(num2) {
|
|
943
|
+
return this.clone().isub(num2);
|
|
944
944
|
};
|
|
945
|
-
function smallMulTo(self2,
|
|
946
|
-
out.negative =
|
|
947
|
-
var len = self2.length +
|
|
945
|
+
function smallMulTo(self2, num2, out) {
|
|
946
|
+
out.negative = num2.negative ^ self2.negative;
|
|
947
|
+
var len = self2.length + num2.length | 0;
|
|
948
948
|
out.length = len;
|
|
949
949
|
len = len - 1 | 0;
|
|
950
950
|
var a = self2.words[0] | 0;
|
|
951
|
-
var b =
|
|
951
|
+
var b = num2.words[0] | 0;
|
|
952
952
|
var r = a * b;
|
|
953
953
|
var lo = r & 67108863;
|
|
954
954
|
var carry = r / 67108864 | 0;
|
|
@@ -956,11 +956,11 @@ var require_bn = __commonJS({
|
|
|
956
956
|
for (var k = 1; k < len; k++) {
|
|
957
957
|
var ncarry = carry >>> 26;
|
|
958
958
|
var rword = carry & 67108863;
|
|
959
|
-
var maxJ = Math.min(k,
|
|
959
|
+
var maxJ = Math.min(k, num2.length - 1);
|
|
960
960
|
for (var j = Math.max(0, k - self2.length + 1); j <= maxJ; j++) {
|
|
961
961
|
var i = k - j | 0;
|
|
962
962
|
a = self2.words[i] | 0;
|
|
963
|
-
b =
|
|
963
|
+
b = num2.words[j] | 0;
|
|
964
964
|
r = a * b + rword;
|
|
965
965
|
ncarry += r / 67108864 | 0;
|
|
966
966
|
rword = r & 67108863;
|
|
@@ -975,9 +975,9 @@ var require_bn = __commonJS({
|
|
|
975
975
|
}
|
|
976
976
|
return out.strip();
|
|
977
977
|
}
|
|
978
|
-
var comb10MulTo = function comb10MulTo2(self2,
|
|
978
|
+
var comb10MulTo = function comb10MulTo2(self2, num2, out) {
|
|
979
979
|
var a = self2.words;
|
|
980
|
-
var b =
|
|
980
|
+
var b = num2.words;
|
|
981
981
|
var o = out.words;
|
|
982
982
|
var c = 0;
|
|
983
983
|
var lo;
|
|
@@ -1043,7 +1043,7 @@ var require_bn = __commonJS({
|
|
|
1043
1043
|
var b9 = b[9] | 0;
|
|
1044
1044
|
var bl9 = b9 & 8191;
|
|
1045
1045
|
var bh9 = b9 >>> 13;
|
|
1046
|
-
out.negative = self2.negative ^
|
|
1046
|
+
out.negative = self2.negative ^ num2.negative;
|
|
1047
1047
|
out.length = 19;
|
|
1048
1048
|
lo = Math.imul(al0, bl0);
|
|
1049
1049
|
mid = Math.imul(al0, bh0);
|
|
@@ -1530,20 +1530,20 @@ var require_bn = __commonJS({
|
|
|
1530
1530
|
if (!Math.imul) {
|
|
1531
1531
|
comb10MulTo = smallMulTo;
|
|
1532
1532
|
}
|
|
1533
|
-
function bigMulTo(self2,
|
|
1534
|
-
out.negative =
|
|
1535
|
-
out.length = self2.length +
|
|
1533
|
+
function bigMulTo(self2, num2, out) {
|
|
1534
|
+
out.negative = num2.negative ^ self2.negative;
|
|
1535
|
+
out.length = self2.length + num2.length;
|
|
1536
1536
|
var carry = 0;
|
|
1537
1537
|
var hncarry = 0;
|
|
1538
1538
|
for (var k = 0; k < out.length - 1; k++) {
|
|
1539
1539
|
var ncarry = hncarry;
|
|
1540
1540
|
hncarry = 0;
|
|
1541
1541
|
var rword = carry & 67108863;
|
|
1542
|
-
var maxJ = Math.min(k,
|
|
1542
|
+
var maxJ = Math.min(k, num2.length - 1);
|
|
1543
1543
|
for (var j = Math.max(0, k - self2.length + 1); j <= maxJ; j++) {
|
|
1544
1544
|
var i = k - j;
|
|
1545
1545
|
var a = self2.words[i] | 0;
|
|
1546
|
-
var b =
|
|
1546
|
+
var b = num2.words[j] | 0;
|
|
1547
1547
|
var r = a * b;
|
|
1548
1548
|
var lo = r & 67108863;
|
|
1549
1549
|
ncarry = ncarry + (r / 67108864 | 0) | 0;
|
|
@@ -1564,21 +1564,21 @@ var require_bn = __commonJS({
|
|
|
1564
1564
|
}
|
|
1565
1565
|
return out.strip();
|
|
1566
1566
|
}
|
|
1567
|
-
function jumboMulTo(self2,
|
|
1567
|
+
function jumboMulTo(self2, num2, out) {
|
|
1568
1568
|
var fftm = new FFTM();
|
|
1569
|
-
return fftm.mulp(self2,
|
|
1569
|
+
return fftm.mulp(self2, num2, out);
|
|
1570
1570
|
}
|
|
1571
|
-
BN.prototype.mulTo = function mulTo(
|
|
1571
|
+
BN.prototype.mulTo = function mulTo(num2, out) {
|
|
1572
1572
|
var res;
|
|
1573
|
-
var len = this.length +
|
|
1574
|
-
if (this.length === 10 &&
|
|
1575
|
-
res = comb10MulTo(this,
|
|
1573
|
+
var len = this.length + num2.length;
|
|
1574
|
+
if (this.length === 10 && num2.length === 10) {
|
|
1575
|
+
res = comb10MulTo(this, num2, out);
|
|
1576
1576
|
} else if (len < 63) {
|
|
1577
|
-
res = smallMulTo(this,
|
|
1577
|
+
res = smallMulTo(this, num2, out);
|
|
1578
1578
|
} else if (len < 1024) {
|
|
1579
|
-
res = bigMulTo(this,
|
|
1579
|
+
res = bigMulTo(this, num2, out);
|
|
1580
1580
|
} else {
|
|
1581
|
-
res = jumboMulTo(this,
|
|
1581
|
+
res = jumboMulTo(this, num2, out);
|
|
1582
1582
|
}
|
|
1583
1583
|
return res;
|
|
1584
1584
|
};
|
|
@@ -1723,25 +1723,25 @@ var require_bn = __commonJS({
|
|
|
1723
1723
|
out.length = x.length + y.length;
|
|
1724
1724
|
return out.strip();
|
|
1725
1725
|
};
|
|
1726
|
-
BN.prototype.mul = function mul(
|
|
1726
|
+
BN.prototype.mul = function mul(num2) {
|
|
1727
1727
|
var out = new BN(null);
|
|
1728
|
-
out.words = new Array(this.length +
|
|
1729
|
-
return this.mulTo(
|
|
1728
|
+
out.words = new Array(this.length + num2.length);
|
|
1729
|
+
return this.mulTo(num2, out);
|
|
1730
1730
|
};
|
|
1731
|
-
BN.prototype.mulf = function mulf(
|
|
1731
|
+
BN.prototype.mulf = function mulf(num2) {
|
|
1732
1732
|
var out = new BN(null);
|
|
1733
|
-
out.words = new Array(this.length +
|
|
1734
|
-
return jumboMulTo(this,
|
|
1733
|
+
out.words = new Array(this.length + num2.length);
|
|
1734
|
+
return jumboMulTo(this, num2, out);
|
|
1735
1735
|
};
|
|
1736
|
-
BN.prototype.imul = function imul(
|
|
1737
|
-
return this.clone().mulTo(
|
|
1736
|
+
BN.prototype.imul = function imul(num2) {
|
|
1737
|
+
return this.clone().mulTo(num2, this);
|
|
1738
1738
|
};
|
|
1739
|
-
BN.prototype.imuln = function imuln(
|
|
1740
|
-
assert(typeof
|
|
1741
|
-
assert(
|
|
1739
|
+
BN.prototype.imuln = function imuln(num2) {
|
|
1740
|
+
assert(typeof num2 === "number");
|
|
1741
|
+
assert(num2 < 67108864);
|
|
1742
1742
|
var carry = 0;
|
|
1743
1743
|
for (var i = 0; i < this.length; i++) {
|
|
1744
|
-
var w = (this.words[i] | 0) *
|
|
1744
|
+
var w = (this.words[i] | 0) * num2;
|
|
1745
1745
|
var lo = (w & 67108863) + (carry & 67108863);
|
|
1746
1746
|
carry >>= 26;
|
|
1747
1747
|
carry += w / 67108864 | 0;
|
|
@@ -1752,11 +1752,11 @@ var require_bn = __commonJS({
|
|
|
1752
1752
|
this.words[i] = carry;
|
|
1753
1753
|
this.length++;
|
|
1754
1754
|
}
|
|
1755
|
-
this.length =
|
|
1755
|
+
this.length = num2 === 0 ? 1 : this.length;
|
|
1756
1756
|
return this;
|
|
1757
1757
|
};
|
|
1758
|
-
BN.prototype.muln = function muln(
|
|
1759
|
-
return this.clone().imuln(
|
|
1758
|
+
BN.prototype.muln = function muln(num2) {
|
|
1759
|
+
return this.clone().imuln(num2);
|
|
1760
1760
|
};
|
|
1761
1761
|
BN.prototype.sqr = function sqr() {
|
|
1762
1762
|
return this.mul(this);
|
|
@@ -1764,8 +1764,8 @@ var require_bn = __commonJS({
|
|
|
1764
1764
|
BN.prototype.isqr = function isqr() {
|
|
1765
1765
|
return this.imul(this.clone());
|
|
1766
1766
|
};
|
|
1767
|
-
BN.prototype.pow = function pow(
|
|
1768
|
-
var w = toBitArray(
|
|
1767
|
+
BN.prototype.pow = function pow(num2) {
|
|
1768
|
+
var w = toBitArray(num2);
|
|
1769
1769
|
if (w.length === 0) return new BN(1);
|
|
1770
1770
|
var res = this;
|
|
1771
1771
|
for (var i = 0; i < w.length; i++, res = res.sqr()) {
|
|
@@ -1907,25 +1907,25 @@ var require_bn = __commonJS({
|
|
|
1907
1907
|
BN.prototype.maskn = function maskn(bits) {
|
|
1908
1908
|
return this.clone().imaskn(bits);
|
|
1909
1909
|
};
|
|
1910
|
-
BN.prototype.iaddn = function iaddn(
|
|
1911
|
-
assert(typeof
|
|
1912
|
-
assert(
|
|
1913
|
-
if (
|
|
1910
|
+
BN.prototype.iaddn = function iaddn(num2) {
|
|
1911
|
+
assert(typeof num2 === "number");
|
|
1912
|
+
assert(num2 < 67108864);
|
|
1913
|
+
if (num2 < 0) return this.isubn(-num2);
|
|
1914
1914
|
if (this.negative !== 0) {
|
|
1915
|
-
if (this.length === 1 && (this.words[0] | 0) <
|
|
1916
|
-
this.words[0] =
|
|
1915
|
+
if (this.length === 1 && (this.words[0] | 0) < num2) {
|
|
1916
|
+
this.words[0] = num2 - (this.words[0] | 0);
|
|
1917
1917
|
this.negative = 0;
|
|
1918
1918
|
return this;
|
|
1919
1919
|
}
|
|
1920
1920
|
this.negative = 0;
|
|
1921
|
-
this.isubn(
|
|
1921
|
+
this.isubn(num2);
|
|
1922
1922
|
this.negative = 1;
|
|
1923
1923
|
return this;
|
|
1924
1924
|
}
|
|
1925
|
-
return this._iaddn(
|
|
1925
|
+
return this._iaddn(num2);
|
|
1926
1926
|
};
|
|
1927
|
-
BN.prototype._iaddn = function _iaddn(
|
|
1928
|
-
this.words[0] +=
|
|
1927
|
+
BN.prototype._iaddn = function _iaddn(num2) {
|
|
1928
|
+
this.words[0] += num2;
|
|
1929
1929
|
for (var i = 0; i < this.length && this.words[i] >= 67108864; i++) {
|
|
1930
1930
|
this.words[i] -= 67108864;
|
|
1931
1931
|
if (i === this.length - 1) {
|
|
@@ -1937,17 +1937,17 @@ var require_bn = __commonJS({
|
|
|
1937
1937
|
this.length = Math.max(this.length, i + 1);
|
|
1938
1938
|
return this;
|
|
1939
1939
|
};
|
|
1940
|
-
BN.prototype.isubn = function isubn(
|
|
1941
|
-
assert(typeof
|
|
1942
|
-
assert(
|
|
1943
|
-
if (
|
|
1940
|
+
BN.prototype.isubn = function isubn(num2) {
|
|
1941
|
+
assert(typeof num2 === "number");
|
|
1942
|
+
assert(num2 < 67108864);
|
|
1943
|
+
if (num2 < 0) return this.iaddn(-num2);
|
|
1944
1944
|
if (this.negative !== 0) {
|
|
1945
1945
|
this.negative = 0;
|
|
1946
|
-
this.iaddn(
|
|
1946
|
+
this.iaddn(num2);
|
|
1947
1947
|
this.negative = 1;
|
|
1948
1948
|
return this;
|
|
1949
1949
|
}
|
|
1950
|
-
this.words[0] -=
|
|
1950
|
+
this.words[0] -= num2;
|
|
1951
1951
|
if (this.length === 1 && this.words[0] < 0) {
|
|
1952
1952
|
this.words[0] = -this.words[0];
|
|
1953
1953
|
this.negative = 1;
|
|
@@ -1959,11 +1959,11 @@ var require_bn = __commonJS({
|
|
|
1959
1959
|
}
|
|
1960
1960
|
return this.strip();
|
|
1961
1961
|
};
|
|
1962
|
-
BN.prototype.addn = function addn(
|
|
1963
|
-
return this.clone().iaddn(
|
|
1962
|
+
BN.prototype.addn = function addn(num2) {
|
|
1963
|
+
return this.clone().iaddn(num2);
|
|
1964
1964
|
};
|
|
1965
|
-
BN.prototype.subn = function subn(
|
|
1966
|
-
return this.clone().isubn(
|
|
1965
|
+
BN.prototype.subn = function subn(num2) {
|
|
1966
|
+
return this.clone().isubn(num2);
|
|
1967
1967
|
};
|
|
1968
1968
|
BN.prototype.iabs = function iabs() {
|
|
1969
1969
|
this.negative = 0;
|
|
@@ -1972,15 +1972,15 @@ var require_bn = __commonJS({
|
|
|
1972
1972
|
BN.prototype.abs = function abs() {
|
|
1973
1973
|
return this.clone().iabs();
|
|
1974
1974
|
};
|
|
1975
|
-
BN.prototype._ishlnsubmul = function _ishlnsubmul(
|
|
1976
|
-
var len =
|
|
1975
|
+
BN.prototype._ishlnsubmul = function _ishlnsubmul(num2, mul, shift) {
|
|
1976
|
+
var len = num2.length + shift;
|
|
1977
1977
|
var i;
|
|
1978
1978
|
this._expand(len);
|
|
1979
1979
|
var w;
|
|
1980
1980
|
var carry = 0;
|
|
1981
|
-
for (i = 0; i <
|
|
1981
|
+
for (i = 0; i < num2.length; i++) {
|
|
1982
1982
|
w = (this.words[i + shift] | 0) + carry;
|
|
1983
|
-
var right = (
|
|
1983
|
+
var right = (num2.words[i] | 0) * mul;
|
|
1984
1984
|
w -= right & 67108863;
|
|
1985
1985
|
carry = (w >> 26) - (right / 67108864 | 0);
|
|
1986
1986
|
this.words[i + shift] = w & 67108863;
|
|
@@ -2001,10 +2001,10 @@ var require_bn = __commonJS({
|
|
|
2001
2001
|
this.negative = 1;
|
|
2002
2002
|
return this.strip();
|
|
2003
2003
|
};
|
|
2004
|
-
BN.prototype._wordDiv = function _wordDiv(
|
|
2005
|
-
var shift = this.length -
|
|
2004
|
+
BN.prototype._wordDiv = function _wordDiv(num2, mode) {
|
|
2005
|
+
var shift = this.length - num2.length;
|
|
2006
2006
|
var a = this.clone();
|
|
2007
|
-
var b =
|
|
2007
|
+
var b = num2;
|
|
2008
2008
|
var bhi = b.words[b.length - 1] | 0;
|
|
2009
2009
|
var bhiBits = this._countBits(bhi);
|
|
2010
2010
|
shift = 26 - bhiBits;
|
|
@@ -2058,8 +2058,8 @@ var require_bn = __commonJS({
|
|
|
2058
2058
|
mod: a
|
|
2059
2059
|
};
|
|
2060
2060
|
};
|
|
2061
|
-
BN.prototype.divmod = function divmod(
|
|
2062
|
-
assert(!
|
|
2061
|
+
BN.prototype.divmod = function divmod(num2, mode, positive) {
|
|
2062
|
+
assert(!num2.isZero());
|
|
2063
2063
|
if (this.isZero()) {
|
|
2064
2064
|
return {
|
|
2065
2065
|
div: new BN(0),
|
|
@@ -2067,15 +2067,15 @@ var require_bn = __commonJS({
|
|
|
2067
2067
|
};
|
|
2068
2068
|
}
|
|
2069
2069
|
var div, mod, res;
|
|
2070
|
-
if (this.negative !== 0 &&
|
|
2071
|
-
res = this.neg().divmod(
|
|
2070
|
+
if (this.negative !== 0 && num2.negative === 0) {
|
|
2071
|
+
res = this.neg().divmod(num2, mode);
|
|
2072
2072
|
if (mode !== "mod") {
|
|
2073
2073
|
div = res.div.neg();
|
|
2074
2074
|
}
|
|
2075
2075
|
if (mode !== "div") {
|
|
2076
2076
|
mod = res.mod.neg();
|
|
2077
2077
|
if (positive && mod.negative !== 0) {
|
|
2078
|
-
mod.iadd(
|
|
2078
|
+
mod.iadd(num2);
|
|
2079
2079
|
}
|
|
2080
2080
|
}
|
|
2081
2081
|
return {
|
|
@@ -2083,8 +2083,8 @@ var require_bn = __commonJS({
|
|
|
2083
2083
|
mod
|
|
2084
2084
|
};
|
|
2085
2085
|
}
|
|
2086
|
-
if (this.negative === 0 &&
|
|
2087
|
-
res = this.divmod(
|
|
2086
|
+
if (this.negative === 0 && num2.negative !== 0) {
|
|
2087
|
+
res = this.divmod(num2.neg(), mode);
|
|
2088
2088
|
if (mode !== "mod") {
|
|
2089
2089
|
div = res.div.neg();
|
|
2090
2090
|
}
|
|
@@ -2093,12 +2093,12 @@ var require_bn = __commonJS({
|
|
|
2093
2093
|
mod: res.mod
|
|
2094
2094
|
};
|
|
2095
2095
|
}
|
|
2096
|
-
if ((this.negative &
|
|
2097
|
-
res = this.neg().divmod(
|
|
2096
|
+
if ((this.negative & num2.negative) !== 0) {
|
|
2097
|
+
res = this.neg().divmod(num2.neg(), mode);
|
|
2098
2098
|
if (mode !== "div") {
|
|
2099
2099
|
mod = res.mod.neg();
|
|
2100
2100
|
if (positive && mod.negative !== 0) {
|
|
2101
|
-
mod.isub(
|
|
2101
|
+
mod.isub(num2);
|
|
2102
2102
|
}
|
|
2103
2103
|
}
|
|
2104
2104
|
return {
|
|
@@ -2106,72 +2106,72 @@ var require_bn = __commonJS({
|
|
|
2106
2106
|
mod
|
|
2107
2107
|
};
|
|
2108
2108
|
}
|
|
2109
|
-
if (
|
|
2109
|
+
if (num2.length > this.length || this.cmp(num2) < 0) {
|
|
2110
2110
|
return {
|
|
2111
2111
|
div: new BN(0),
|
|
2112
2112
|
mod: this
|
|
2113
2113
|
};
|
|
2114
2114
|
}
|
|
2115
|
-
if (
|
|
2115
|
+
if (num2.length === 1) {
|
|
2116
2116
|
if (mode === "div") {
|
|
2117
2117
|
return {
|
|
2118
|
-
div: this.divn(
|
|
2118
|
+
div: this.divn(num2.words[0]),
|
|
2119
2119
|
mod: null
|
|
2120
2120
|
};
|
|
2121
2121
|
}
|
|
2122
2122
|
if (mode === "mod") {
|
|
2123
2123
|
return {
|
|
2124
2124
|
div: null,
|
|
2125
|
-
mod: new BN(this.modn(
|
|
2125
|
+
mod: new BN(this.modn(num2.words[0]))
|
|
2126
2126
|
};
|
|
2127
2127
|
}
|
|
2128
2128
|
return {
|
|
2129
|
-
div: this.divn(
|
|
2130
|
-
mod: new BN(this.modn(
|
|
2129
|
+
div: this.divn(num2.words[0]),
|
|
2130
|
+
mod: new BN(this.modn(num2.words[0]))
|
|
2131
2131
|
};
|
|
2132
2132
|
}
|
|
2133
|
-
return this._wordDiv(
|
|
2133
|
+
return this._wordDiv(num2, mode);
|
|
2134
2134
|
};
|
|
2135
|
-
BN.prototype.div = function div(
|
|
2136
|
-
return this.divmod(
|
|
2135
|
+
BN.prototype.div = function div(num2) {
|
|
2136
|
+
return this.divmod(num2, "div", false).div;
|
|
2137
2137
|
};
|
|
2138
|
-
BN.prototype.mod = function mod(
|
|
2139
|
-
return this.divmod(
|
|
2138
|
+
BN.prototype.mod = function mod(num2) {
|
|
2139
|
+
return this.divmod(num2, "mod", false).mod;
|
|
2140
2140
|
};
|
|
2141
|
-
BN.prototype.umod = function umod(
|
|
2142
|
-
return this.divmod(
|
|
2141
|
+
BN.prototype.umod = function umod(num2) {
|
|
2142
|
+
return this.divmod(num2, "mod", true).mod;
|
|
2143
2143
|
};
|
|
2144
|
-
BN.prototype.divRound = function divRound(
|
|
2145
|
-
var dm = this.divmod(
|
|
2144
|
+
BN.prototype.divRound = function divRound(num2) {
|
|
2145
|
+
var dm = this.divmod(num2);
|
|
2146
2146
|
if (dm.mod.isZero()) return dm.div;
|
|
2147
|
-
var mod = dm.div.negative !== 0 ? dm.mod.isub(
|
|
2148
|
-
var half =
|
|
2149
|
-
var r2 =
|
|
2147
|
+
var mod = dm.div.negative !== 0 ? dm.mod.isub(num2) : dm.mod;
|
|
2148
|
+
var half = num2.ushrn(1);
|
|
2149
|
+
var r2 = num2.andln(1);
|
|
2150
2150
|
var cmp = mod.cmp(half);
|
|
2151
2151
|
if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
|
|
2152
2152
|
return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
|
|
2153
2153
|
};
|
|
2154
|
-
BN.prototype.modn = function modn(
|
|
2155
|
-
assert(
|
|
2156
|
-
var p = (1 << 26) %
|
|
2154
|
+
BN.prototype.modn = function modn(num2) {
|
|
2155
|
+
assert(num2 <= 67108863);
|
|
2156
|
+
var p = (1 << 26) % num2;
|
|
2157
2157
|
var acc = 0;
|
|
2158
2158
|
for (var i = this.length - 1; i >= 0; i--) {
|
|
2159
|
-
acc = (p * acc + (this.words[i] | 0)) %
|
|
2159
|
+
acc = (p * acc + (this.words[i] | 0)) % num2;
|
|
2160
2160
|
}
|
|
2161
2161
|
return acc;
|
|
2162
2162
|
};
|
|
2163
|
-
BN.prototype.idivn = function idivn(
|
|
2164
|
-
assert(
|
|
2163
|
+
BN.prototype.idivn = function idivn(num2) {
|
|
2164
|
+
assert(num2 <= 67108863);
|
|
2165
2165
|
var carry = 0;
|
|
2166
2166
|
for (var i = this.length - 1; i >= 0; i--) {
|
|
2167
2167
|
var w = (this.words[i] | 0) + carry * 67108864;
|
|
2168
|
-
this.words[i] = w /
|
|
2169
|
-
carry = w %
|
|
2168
|
+
this.words[i] = w / num2 | 0;
|
|
2169
|
+
carry = w % num2;
|
|
2170
2170
|
}
|
|
2171
2171
|
return this.strip();
|
|
2172
2172
|
};
|
|
2173
|
-
BN.prototype.divn = function divn(
|
|
2174
|
-
return this.clone().idivn(
|
|
2173
|
+
BN.prototype.divn = function divn(num2) {
|
|
2174
|
+
return this.clone().idivn(num2);
|
|
2175
2175
|
};
|
|
2176
2176
|
BN.prototype.egcd = function egcd(p) {
|
|
2177
2177
|
assert(p.negative === 0);
|
|
@@ -2289,11 +2289,11 @@ var require_bn = __commonJS({
|
|
|
2289
2289
|
}
|
|
2290
2290
|
return res;
|
|
2291
2291
|
};
|
|
2292
|
-
BN.prototype.gcd = function gcd(
|
|
2293
|
-
if (this.isZero()) return
|
|
2294
|
-
if (
|
|
2292
|
+
BN.prototype.gcd = function gcd(num2) {
|
|
2293
|
+
if (this.isZero()) return num2.abs();
|
|
2294
|
+
if (num2.isZero()) return this.abs();
|
|
2295
2295
|
var a = this.clone();
|
|
2296
|
-
var b =
|
|
2296
|
+
var b = num2.clone();
|
|
2297
2297
|
a.negative = 0;
|
|
2298
2298
|
b.negative = 0;
|
|
2299
2299
|
for (var shift = 0; a.isEven() && b.isEven(); shift++) {
|
|
@@ -2319,8 +2319,8 @@ var require_bn = __commonJS({
|
|
|
2319
2319
|
} while (true);
|
|
2320
2320
|
return b.iushln(shift);
|
|
2321
2321
|
};
|
|
2322
|
-
BN.prototype.invm = function invm(
|
|
2323
|
-
return this.egcd(
|
|
2322
|
+
BN.prototype.invm = function invm(num2) {
|
|
2323
|
+
return this.egcd(num2).a.umod(num2);
|
|
2324
2324
|
};
|
|
2325
2325
|
BN.prototype.isEven = function isEven() {
|
|
2326
2326
|
return (this.words[0] & 1) === 0;
|
|
@@ -2328,8 +2328,8 @@ var require_bn = __commonJS({
|
|
|
2328
2328
|
BN.prototype.isOdd = function isOdd() {
|
|
2329
2329
|
return (this.words[0] & 1) === 1;
|
|
2330
2330
|
};
|
|
2331
|
-
BN.prototype.andln = function andln(
|
|
2332
|
-
return this.words[0] &
|
|
2331
|
+
BN.prototype.andln = function andln(num2) {
|
|
2332
|
+
return this.words[0] & num2;
|
|
2333
2333
|
};
|
|
2334
2334
|
BN.prototype.bincn = function bincn(bit) {
|
|
2335
2335
|
assert(typeof bit === "number");
|
|
@@ -2358,8 +2358,8 @@ var require_bn = __commonJS({
|
|
|
2358
2358
|
BN.prototype.isZero = function isZero() {
|
|
2359
2359
|
return this.length === 1 && this.words[0] === 0;
|
|
2360
2360
|
};
|
|
2361
|
-
BN.prototype.cmpn = function cmpn(
|
|
2362
|
-
var negative =
|
|
2361
|
+
BN.prototype.cmpn = function cmpn(num2) {
|
|
2362
|
+
var negative = num2 < 0;
|
|
2363
2363
|
if (this.negative !== 0 && !negative) return -1;
|
|
2364
2364
|
if (this.negative === 0 && negative) return 1;
|
|
2365
2365
|
this.strip();
|
|
@@ -2368,29 +2368,29 @@ var require_bn = __commonJS({
|
|
|
2368
2368
|
res = 1;
|
|
2369
2369
|
} else {
|
|
2370
2370
|
if (negative) {
|
|
2371
|
-
|
|
2371
|
+
num2 = -num2;
|
|
2372
2372
|
}
|
|
2373
|
-
assert(
|
|
2373
|
+
assert(num2 <= 67108863, "Number is too big");
|
|
2374
2374
|
var w = this.words[0] | 0;
|
|
2375
|
-
res = w ===
|
|
2375
|
+
res = w === num2 ? 0 : w < num2 ? -1 : 1;
|
|
2376
2376
|
}
|
|
2377
2377
|
if (this.negative !== 0) return -res | 0;
|
|
2378
2378
|
return res;
|
|
2379
2379
|
};
|
|
2380
|
-
BN.prototype.cmp = function cmp(
|
|
2381
|
-
if (this.negative !== 0 &&
|
|
2382
|
-
if (this.negative === 0 &&
|
|
2383
|
-
var res = this.ucmp(
|
|
2380
|
+
BN.prototype.cmp = function cmp(num2) {
|
|
2381
|
+
if (this.negative !== 0 && num2.negative === 0) return -1;
|
|
2382
|
+
if (this.negative === 0 && num2.negative !== 0) return 1;
|
|
2383
|
+
var res = this.ucmp(num2);
|
|
2384
2384
|
if (this.negative !== 0) return -res | 0;
|
|
2385
2385
|
return res;
|
|
2386
2386
|
};
|
|
2387
|
-
BN.prototype.ucmp = function ucmp(
|
|
2388
|
-
if (this.length >
|
|
2389
|
-
if (this.length <
|
|
2387
|
+
BN.prototype.ucmp = function ucmp(num2) {
|
|
2388
|
+
if (this.length > num2.length) return 1;
|
|
2389
|
+
if (this.length < num2.length) return -1;
|
|
2390
2390
|
var res = 0;
|
|
2391
2391
|
for (var i = this.length - 1; i >= 0; i--) {
|
|
2392
2392
|
var a = this.words[i] | 0;
|
|
2393
|
-
var b =
|
|
2393
|
+
var b = num2.words[i] | 0;
|
|
2394
2394
|
if (a === b) continue;
|
|
2395
2395
|
if (a < b) {
|
|
2396
2396
|
res = -1;
|
|
@@ -2401,38 +2401,38 @@ var require_bn = __commonJS({
|
|
|
2401
2401
|
}
|
|
2402
2402
|
return res;
|
|
2403
2403
|
};
|
|
2404
|
-
BN.prototype.gtn = function gtn(
|
|
2405
|
-
return this.cmpn(
|
|
2404
|
+
BN.prototype.gtn = function gtn(num2) {
|
|
2405
|
+
return this.cmpn(num2) === 1;
|
|
2406
2406
|
};
|
|
2407
|
-
BN.prototype.gt = function gt(
|
|
2408
|
-
return this.cmp(
|
|
2407
|
+
BN.prototype.gt = function gt(num2) {
|
|
2408
|
+
return this.cmp(num2) === 1;
|
|
2409
2409
|
};
|
|
2410
|
-
BN.prototype.gten = function gten(
|
|
2411
|
-
return this.cmpn(
|
|
2410
|
+
BN.prototype.gten = function gten(num2) {
|
|
2411
|
+
return this.cmpn(num2) >= 0;
|
|
2412
2412
|
};
|
|
2413
|
-
BN.prototype.gte = function gte(
|
|
2414
|
-
return this.cmp(
|
|
2413
|
+
BN.prototype.gte = function gte(num2) {
|
|
2414
|
+
return this.cmp(num2) >= 0;
|
|
2415
2415
|
};
|
|
2416
|
-
BN.prototype.ltn = function ltn(
|
|
2417
|
-
return this.cmpn(
|
|
2416
|
+
BN.prototype.ltn = function ltn(num2) {
|
|
2417
|
+
return this.cmpn(num2) === -1;
|
|
2418
2418
|
};
|
|
2419
|
-
BN.prototype.lt = function lt(
|
|
2420
|
-
return this.cmp(
|
|
2419
|
+
BN.prototype.lt = function lt(num2) {
|
|
2420
|
+
return this.cmp(num2) === -1;
|
|
2421
2421
|
};
|
|
2422
|
-
BN.prototype.lten = function lten(
|
|
2423
|
-
return this.cmpn(
|
|
2422
|
+
BN.prototype.lten = function lten(num2) {
|
|
2423
|
+
return this.cmpn(num2) <= 0;
|
|
2424
2424
|
};
|
|
2425
|
-
BN.prototype.lte = function lte(
|
|
2426
|
-
return this.cmp(
|
|
2425
|
+
BN.prototype.lte = function lte(num2) {
|
|
2426
|
+
return this.cmp(num2) <= 0;
|
|
2427
2427
|
};
|
|
2428
|
-
BN.prototype.eqn = function eqn(
|
|
2429
|
-
return this.cmpn(
|
|
2428
|
+
BN.prototype.eqn = function eqn(num2) {
|
|
2429
|
+
return this.cmpn(num2) === 0;
|
|
2430
2430
|
};
|
|
2431
|
-
BN.prototype.eq = function eq(
|
|
2432
|
-
return this.cmp(
|
|
2431
|
+
BN.prototype.eq = function eq(num2) {
|
|
2432
|
+
return this.cmp(num2) === 0;
|
|
2433
2433
|
};
|
|
2434
|
-
BN.red = function red(
|
|
2435
|
-
return new Red(
|
|
2434
|
+
BN.red = function red(num2) {
|
|
2435
|
+
return new Red(num2);
|
|
2436
2436
|
};
|
|
2437
2437
|
BN.prototype.toRed = function toRed(ctx) {
|
|
2438
2438
|
assert(!this.red, "Already a number in reduction context");
|
|
@@ -2451,35 +2451,35 @@ var require_bn = __commonJS({
|
|
|
2451
2451
|
assert(!this.red, "Already a number in reduction context");
|
|
2452
2452
|
return this._forceRed(ctx);
|
|
2453
2453
|
};
|
|
2454
|
-
BN.prototype.redAdd = function redAdd(
|
|
2454
|
+
BN.prototype.redAdd = function redAdd(num2) {
|
|
2455
2455
|
assert(this.red, "redAdd works only with red numbers");
|
|
2456
|
-
return this.red.add(this,
|
|
2456
|
+
return this.red.add(this, num2);
|
|
2457
2457
|
};
|
|
2458
|
-
BN.prototype.redIAdd = function redIAdd(
|
|
2458
|
+
BN.prototype.redIAdd = function redIAdd(num2) {
|
|
2459
2459
|
assert(this.red, "redIAdd works only with red numbers");
|
|
2460
|
-
return this.red.iadd(this,
|
|
2460
|
+
return this.red.iadd(this, num2);
|
|
2461
2461
|
};
|
|
2462
|
-
BN.prototype.redSub = function redSub(
|
|
2462
|
+
BN.prototype.redSub = function redSub(num2) {
|
|
2463
2463
|
assert(this.red, "redSub works only with red numbers");
|
|
2464
|
-
return this.red.sub(this,
|
|
2464
|
+
return this.red.sub(this, num2);
|
|
2465
2465
|
};
|
|
2466
|
-
BN.prototype.redISub = function redISub(
|
|
2466
|
+
BN.prototype.redISub = function redISub(num2) {
|
|
2467
2467
|
assert(this.red, "redISub works only with red numbers");
|
|
2468
|
-
return this.red.isub(this,
|
|
2468
|
+
return this.red.isub(this, num2);
|
|
2469
2469
|
};
|
|
2470
|
-
BN.prototype.redShl = function redShl(
|
|
2470
|
+
BN.prototype.redShl = function redShl(num2) {
|
|
2471
2471
|
assert(this.red, "redShl works only with red numbers");
|
|
2472
|
-
return this.red.shl(this,
|
|
2472
|
+
return this.red.shl(this, num2);
|
|
2473
2473
|
};
|
|
2474
|
-
BN.prototype.redMul = function redMul(
|
|
2474
|
+
BN.prototype.redMul = function redMul(num2) {
|
|
2475
2475
|
assert(this.red, "redMul works only with red numbers");
|
|
2476
|
-
this.red._verify2(this,
|
|
2477
|
-
return this.red.mul(this,
|
|
2476
|
+
this.red._verify2(this, num2);
|
|
2477
|
+
return this.red.mul(this, num2);
|
|
2478
2478
|
};
|
|
2479
|
-
BN.prototype.redIMul = function redIMul(
|
|
2479
|
+
BN.prototype.redIMul = function redIMul(num2) {
|
|
2480
2480
|
assert(this.red, "redMul works only with red numbers");
|
|
2481
|
-
this.red._verify2(this,
|
|
2482
|
-
return this.red.imul(this,
|
|
2481
|
+
this.red._verify2(this, num2);
|
|
2482
|
+
return this.red.imul(this, num2);
|
|
2483
2483
|
};
|
|
2484
2484
|
BN.prototype.redSqr = function redSqr() {
|
|
2485
2485
|
assert(this.red, "redSqr works only with red numbers");
|
|
@@ -2506,10 +2506,10 @@ var require_bn = __commonJS({
|
|
|
2506
2506
|
this.red._verify1(this);
|
|
2507
2507
|
return this.red.neg(this);
|
|
2508
2508
|
};
|
|
2509
|
-
BN.prototype.redPow = function redPow(
|
|
2510
|
-
assert(this.red && !
|
|
2509
|
+
BN.prototype.redPow = function redPow(num2) {
|
|
2510
|
+
assert(this.red && !num2.red, "redPow(normalNum)");
|
|
2511
2511
|
this.red._verify1(this);
|
|
2512
|
-
return this.red.pow(this,
|
|
2512
|
+
return this.red.pow(this, num2);
|
|
2513
2513
|
};
|
|
2514
2514
|
var primes = {
|
|
2515
2515
|
k256: null,
|
|
@@ -2529,8 +2529,8 @@ var require_bn = __commonJS({
|
|
|
2529
2529
|
tmp.words = new Array(Math.ceil(this.n / 13));
|
|
2530
2530
|
return tmp;
|
|
2531
2531
|
};
|
|
2532
|
-
MPrime.prototype.ireduce = function ireduce(
|
|
2533
|
-
var r =
|
|
2532
|
+
MPrime.prototype.ireduce = function ireduce(num2) {
|
|
2533
|
+
var r = num2;
|
|
2534
2534
|
var rlen;
|
|
2535
2535
|
do {
|
|
2536
2536
|
this.split(r, this.tmp);
|
|
@@ -2556,8 +2556,8 @@ var require_bn = __commonJS({
|
|
|
2556
2556
|
MPrime.prototype.split = function split(input, out) {
|
|
2557
2557
|
input.iushrn(this.n, 0, out);
|
|
2558
2558
|
};
|
|
2559
|
-
MPrime.prototype.imulK = function imulK(
|
|
2560
|
-
return
|
|
2559
|
+
MPrime.prototype.imulK = function imulK(num2) {
|
|
2560
|
+
return num2.imul(this.k);
|
|
2561
2561
|
};
|
|
2562
2562
|
function K256() {
|
|
2563
2563
|
MPrime.call(
|
|
@@ -2594,24 +2594,24 @@ var require_bn = __commonJS({
|
|
|
2594
2594
|
input.length -= 9;
|
|
2595
2595
|
}
|
|
2596
2596
|
};
|
|
2597
|
-
K256.prototype.imulK = function imulK(
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2597
|
+
K256.prototype.imulK = function imulK(num2) {
|
|
2598
|
+
num2.words[num2.length] = 0;
|
|
2599
|
+
num2.words[num2.length + 1] = 0;
|
|
2600
|
+
num2.length += 2;
|
|
2601
2601
|
var lo = 0;
|
|
2602
|
-
for (var i = 0; i <
|
|
2603
|
-
var w =
|
|
2602
|
+
for (var i = 0; i < num2.length; i++) {
|
|
2603
|
+
var w = num2.words[i] | 0;
|
|
2604
2604
|
lo += w * 977;
|
|
2605
|
-
|
|
2605
|
+
num2.words[i] = lo & 67108863;
|
|
2606
2606
|
lo = w * 64 + (lo / 67108864 | 0);
|
|
2607
2607
|
}
|
|
2608
|
-
if (
|
|
2609
|
-
|
|
2610
|
-
if (
|
|
2611
|
-
|
|
2608
|
+
if (num2.words[num2.length - 1] === 0) {
|
|
2609
|
+
num2.length--;
|
|
2610
|
+
if (num2.words[num2.length - 1] === 0) {
|
|
2611
|
+
num2.length--;
|
|
2612
2612
|
}
|
|
2613
2613
|
}
|
|
2614
|
-
return
|
|
2614
|
+
return num2;
|
|
2615
2615
|
};
|
|
2616
2616
|
function P224() {
|
|
2617
2617
|
MPrime.call(
|
|
@@ -2637,19 +2637,19 @@ var require_bn = __commonJS({
|
|
|
2637
2637
|
);
|
|
2638
2638
|
}
|
|
2639
2639
|
inherits(P25519, MPrime);
|
|
2640
|
-
P25519.prototype.imulK = function imulK(
|
|
2640
|
+
P25519.prototype.imulK = function imulK(num2) {
|
|
2641
2641
|
var carry = 0;
|
|
2642
|
-
for (var i = 0; i <
|
|
2643
|
-
var hi = (
|
|
2642
|
+
for (var i = 0; i < num2.length; i++) {
|
|
2643
|
+
var hi = (num2.words[i] | 0) * 19 + carry;
|
|
2644
2644
|
var lo = hi & 67108863;
|
|
2645
2645
|
hi >>>= 26;
|
|
2646
|
-
|
|
2646
|
+
num2.words[i] = lo;
|
|
2647
2647
|
carry = hi;
|
|
2648
2648
|
}
|
|
2649
2649
|
if (carry !== 0) {
|
|
2650
|
-
|
|
2650
|
+
num2.words[num2.length++] = carry;
|
|
2651
2651
|
}
|
|
2652
|
-
return
|
|
2652
|
+
return num2;
|
|
2653
2653
|
};
|
|
2654
2654
|
BN._prime = function prime(name) {
|
|
2655
2655
|
if (primes[name]) return primes[name];
|
|
@@ -2732,9 +2732,9 @@ var require_bn = __commonJS({
|
|
|
2732
2732
|
}
|
|
2733
2733
|
return res;
|
|
2734
2734
|
};
|
|
2735
|
-
Red.prototype.shl = function shl(a,
|
|
2735
|
+
Red.prototype.shl = function shl(a, num2) {
|
|
2736
2736
|
this._verify1(a);
|
|
2737
|
-
return this.imod(a.ushln(
|
|
2737
|
+
return this.imod(a.ushln(num2));
|
|
2738
2738
|
};
|
|
2739
2739
|
Red.prototype.imul = function imul(a, b) {
|
|
2740
2740
|
this._verify2(a, b);
|
|
@@ -2800,9 +2800,9 @@ var require_bn = __commonJS({
|
|
|
2800
2800
|
return this.imod(inv);
|
|
2801
2801
|
}
|
|
2802
2802
|
};
|
|
2803
|
-
Red.prototype.pow = function pow(a,
|
|
2804
|
-
if (
|
|
2805
|
-
if (
|
|
2803
|
+
Red.prototype.pow = function pow(a, num2) {
|
|
2804
|
+
if (num2.isZero()) return new BN(1).toRed(this);
|
|
2805
|
+
if (num2.cmpn(1) === 0) return a.clone();
|
|
2806
2806
|
var windowSize = 4;
|
|
2807
2807
|
var wnd = new Array(1 << windowSize);
|
|
2808
2808
|
wnd[0] = new BN(1).toRed(this);
|
|
@@ -2813,12 +2813,12 @@ var require_bn = __commonJS({
|
|
|
2813
2813
|
var res = wnd[0];
|
|
2814
2814
|
var current = 0;
|
|
2815
2815
|
var currentLen = 0;
|
|
2816
|
-
var start =
|
|
2816
|
+
var start = num2.bitLength() % 26;
|
|
2817
2817
|
if (start === 0) {
|
|
2818
2818
|
start = 26;
|
|
2819
2819
|
}
|
|
2820
|
-
for (i =
|
|
2821
|
-
var word =
|
|
2820
|
+
for (i = num2.length - 1; i >= 0; i--) {
|
|
2821
|
+
var word = num2.words[i];
|
|
2822
2822
|
for (var j = start - 1; j >= 0; j--) {
|
|
2823
2823
|
var bit = word >> j & 1;
|
|
2824
2824
|
if (res !== wnd[0]) {
|
|
@@ -2840,17 +2840,17 @@ var require_bn = __commonJS({
|
|
|
2840
2840
|
}
|
|
2841
2841
|
return res;
|
|
2842
2842
|
};
|
|
2843
|
-
Red.prototype.convertTo = function convertTo(
|
|
2844
|
-
var r =
|
|
2845
|
-
return r ===
|
|
2843
|
+
Red.prototype.convertTo = function convertTo(num2) {
|
|
2844
|
+
var r = num2.umod(this.m);
|
|
2845
|
+
return r === num2 ? r.clone() : r;
|
|
2846
2846
|
};
|
|
2847
|
-
Red.prototype.convertFrom = function convertFrom(
|
|
2848
|
-
var res =
|
|
2847
|
+
Red.prototype.convertFrom = function convertFrom(num2) {
|
|
2848
|
+
var res = num2.clone();
|
|
2849
2849
|
res.red = null;
|
|
2850
2850
|
return res;
|
|
2851
2851
|
};
|
|
2852
|
-
BN.mont = function mont(
|
|
2853
|
-
return new Mont(
|
|
2852
|
+
BN.mont = function mont(num2) {
|
|
2853
|
+
return new Mont(num2);
|
|
2854
2854
|
};
|
|
2855
2855
|
function Mont(m) {
|
|
2856
2856
|
Red.call(this, m);
|
|
@@ -2866,11 +2866,11 @@ var require_bn = __commonJS({
|
|
|
2866
2866
|
this.minv = this.r.sub(this.minv);
|
|
2867
2867
|
}
|
|
2868
2868
|
inherits(Mont, Red);
|
|
2869
|
-
Mont.prototype.convertTo = function convertTo(
|
|
2870
|
-
return this.imod(
|
|
2869
|
+
Mont.prototype.convertTo = function convertTo(num2) {
|
|
2870
|
+
return this.imod(num2.ushln(this.shift));
|
|
2871
2871
|
};
|
|
2872
|
-
Mont.prototype.convertFrom = function convertFrom(
|
|
2873
|
-
var r = this.imod(
|
|
2872
|
+
Mont.prototype.convertFrom = function convertFrom(num2) {
|
|
2873
|
+
var r = this.imod(num2.mul(this.rinv));
|
|
2874
2874
|
r.red = null;
|
|
2875
2875
|
return r;
|
|
2876
2876
|
};
|
|
@@ -2997,14 +2997,14 @@ var require_utils2 = __commonJS({
|
|
|
2997
2997
|
utils.zero2 = minUtils.zero2;
|
|
2998
2998
|
utils.toHex = minUtils.toHex;
|
|
2999
2999
|
utils.encode = minUtils.encode;
|
|
3000
|
-
function getNAF(
|
|
3001
|
-
var naf = new Array(Math.max(
|
|
3000
|
+
function getNAF(num2, w, bits) {
|
|
3001
|
+
var naf = new Array(Math.max(num2.bitLength(), bits) + 1);
|
|
3002
3002
|
var i;
|
|
3003
3003
|
for (i = 0; i < naf.length; i += 1) {
|
|
3004
3004
|
naf[i] = 0;
|
|
3005
3005
|
}
|
|
3006
3006
|
var ws = 1 << w + 1;
|
|
3007
|
-
var k =
|
|
3007
|
+
var k = num2.clone();
|
|
3008
3008
|
for (i = 0; i < naf.length; i++) {
|
|
3009
3009
|
var z;
|
|
3010
3010
|
var mod = k.andln(ws - 1);
|
|
@@ -3574,8 +3574,8 @@ var require_short = __commonJS({
|
|
|
3574
3574
|
basis
|
|
3575
3575
|
};
|
|
3576
3576
|
};
|
|
3577
|
-
ShortCurve.prototype._getEndoRoots = function _getEndoRoots(
|
|
3578
|
-
var red =
|
|
3577
|
+
ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num2) {
|
|
3578
|
+
var red = num2 === this.p ? this.red : BN.mont(num2);
|
|
3579
3579
|
var tinv = new BN(2).toRed(red).redInvm();
|
|
3580
3580
|
var ntinv = tinv.redNeg();
|
|
3581
3581
|
var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);
|
|
@@ -4361,17 +4361,17 @@ var require_edwards = __commonJS({
|
|
|
4361
4361
|
}
|
|
4362
4362
|
inherits(EdwardsCurve, Base);
|
|
4363
4363
|
module.exports = EdwardsCurve;
|
|
4364
|
-
EdwardsCurve.prototype._mulA = function _mulA(
|
|
4364
|
+
EdwardsCurve.prototype._mulA = function _mulA(num2) {
|
|
4365
4365
|
if (this.mOneA)
|
|
4366
|
-
return
|
|
4366
|
+
return num2.redNeg();
|
|
4367
4367
|
else
|
|
4368
|
-
return this.a.redMul(
|
|
4368
|
+
return this.a.redMul(num2);
|
|
4369
4369
|
};
|
|
4370
|
-
EdwardsCurve.prototype._mulC = function _mulC(
|
|
4370
|
+
EdwardsCurve.prototype._mulC = function _mulC(num2) {
|
|
4371
4371
|
if (this.oneC)
|
|
4372
|
-
return
|
|
4372
|
+
return num2;
|
|
4373
4373
|
else
|
|
4374
|
-
return this.c.redMul(
|
|
4374
|
+
return this.c.redMul(num2);
|
|
4375
4375
|
};
|
|
4376
4376
|
EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) {
|
|
4377
4377
|
return this.point(x, y, z, t);
|
|
@@ -4870,22 +4870,22 @@ var require_utils3 = __commonJS({
|
|
|
4870
4870
|
return lo >>> 0;
|
|
4871
4871
|
}
|
|
4872
4872
|
exports.sum64_5_lo = sum64_5_lo;
|
|
4873
|
-
function rotr64_hi(ah, al,
|
|
4874
|
-
var r = al << 32 -
|
|
4873
|
+
function rotr64_hi(ah, al, num2) {
|
|
4874
|
+
var r = al << 32 - num2 | ah >>> num2;
|
|
4875
4875
|
return r >>> 0;
|
|
4876
4876
|
}
|
|
4877
4877
|
exports.rotr64_hi = rotr64_hi;
|
|
4878
|
-
function rotr64_lo(ah, al,
|
|
4879
|
-
var r = ah << 32 -
|
|
4878
|
+
function rotr64_lo(ah, al, num2) {
|
|
4879
|
+
var r = ah << 32 - num2 | al >>> num2;
|
|
4880
4880
|
return r >>> 0;
|
|
4881
4881
|
}
|
|
4882
4882
|
exports.rotr64_lo = rotr64_lo;
|
|
4883
|
-
function shr64_hi(ah, al,
|
|
4884
|
-
return ah >>>
|
|
4883
|
+
function shr64_hi(ah, al, num2) {
|
|
4884
|
+
return ah >>> num2;
|
|
4885
4885
|
}
|
|
4886
4886
|
exports.shr64_hi = shr64_hi;
|
|
4887
|
-
function shr64_lo(ah, al,
|
|
4888
|
-
var r = ah << 32 -
|
|
4887
|
+
function shr64_lo(ah, al, num2) {
|
|
4888
|
+
var r = ah << 32 - num2 | al >>> num2;
|
|
4889
4889
|
return r >>> 0;
|
|
4890
4890
|
}
|
|
4891
4891
|
exports.shr64_lo = shr64_lo;
|
|
@@ -7966,8 +7966,8 @@ var require_eddsa = __commonJS({
|
|
|
7966
7966
|
var y = utils.intFromLE(normed);
|
|
7967
7967
|
return this.curve.pointFromY(y, xIsOdd);
|
|
7968
7968
|
};
|
|
7969
|
-
EDDSA.prototype.encodeInt = function encodeInt(
|
|
7970
|
-
return
|
|
7969
|
+
EDDSA.prototype.encodeInt = function encodeInt(num2) {
|
|
7970
|
+
return num2.toArray("le", this.encodingLength);
|
|
7971
7971
|
};
|
|
7972
7972
|
EDDSA.prototype.decodeInt = function decodeInt(bytes) {
|
|
7973
7973
|
return utils.intFromLE(bytes);
|
|
@@ -9294,8 +9294,7 @@ var Alfen = class {
|
|
|
9294
9294
|
"connectors": [{
|
|
9295
9295
|
"type": asString(connector?.["type"]) ?? "",
|
|
9296
9296
|
"cable": {
|
|
9297
|
-
"length": asNumber(connector?.["cableLength"]) ?? 0
|
|
9298
|
-
"looses": asNumber(connector?.["cableLooses"]) ?? 0
|
|
9297
|
+
"length": asNumber(connector?.["cableLength"]) ?? 0
|
|
9299
9298
|
}
|
|
9300
9299
|
}],
|
|
9301
9300
|
"energyMeters": [
|
|
@@ -10623,6 +10622,1051 @@ var BSMCrypt01 = class extends ACrypt {
|
|
|
10623
10622
|
// //#endregion
|
|
10624
10623
|
};
|
|
10625
10624
|
|
|
10625
|
+
// src/interfaces/IPublicKeyInfo.ts
|
|
10626
|
+
var IPublicKeyInfo_exports = {};
|
|
10627
|
+
__export(IPublicKeyInfo_exports, {
|
|
10628
|
+
IsAPublicKey: () => IsAPublicKey,
|
|
10629
|
+
IsAPublicKeyLookup: () => IsAPublicKeyLookup,
|
|
10630
|
+
IsAPublicKeySignature: () => IsAPublicKeySignature,
|
|
10631
|
+
IsAPublicKeyXY: () => IsAPublicKeyXY,
|
|
10632
|
+
PublicKeyFormats: () => PublicKeyFormats,
|
|
10633
|
+
isPublicKeySubject: () => isPublicKeySubject
|
|
10634
|
+
});
|
|
10635
|
+
var PublicKeyFormats = /* @__PURE__ */ ((PublicKeyFormats2) => {
|
|
10636
|
+
PublicKeyFormats2["DER"] = "DER";
|
|
10637
|
+
PublicKeyFormats2["XY"] = "XY";
|
|
10638
|
+
return PublicKeyFormats2;
|
|
10639
|
+
})(PublicKeyFormats || {});
|
|
10640
|
+
function IsAPublicKeyLookup(data) {
|
|
10641
|
+
if (!isMandatoryJSONObject(data))
|
|
10642
|
+
return false;
|
|
10643
|
+
return Array.isArray(data["publicKeys"]);
|
|
10644
|
+
}
|
|
10645
|
+
function IsAPublicKey(data) {
|
|
10646
|
+
if (!isMandatoryJSONObject(data))
|
|
10647
|
+
return false;
|
|
10648
|
+
if (data["@context"] !== void 0 && !isStringOrStringArray(data["@context"])) {
|
|
10649
|
+
return false;
|
|
10650
|
+
}
|
|
10651
|
+
if (!isPublicKeySubject(data["subject"]))
|
|
10652
|
+
return false;
|
|
10653
|
+
if (data["value"] !== void 0 && !isString(data["value"])) {
|
|
10654
|
+
return false;
|
|
10655
|
+
}
|
|
10656
|
+
if (data["value"] === void 0 && (data["x"] === void 0 || data["y"] === void 0)) {
|
|
10657
|
+
return false;
|
|
10658
|
+
}
|
|
10659
|
+
if (data["value"] !== void 0 && !isStringOrOIDInfo(data["algorithm"])) {
|
|
10660
|
+
return false;
|
|
10661
|
+
}
|
|
10662
|
+
if (data["certainty"] !== void 0 && (typeof data["certainty"] !== "number" || !Number.isFinite(data["certainty"]))) {
|
|
10663
|
+
return false;
|
|
10664
|
+
}
|
|
10665
|
+
if (data["type"] !== void 0 && !isStringOrOIDInfo(data["type"])) {
|
|
10666
|
+
return false;
|
|
10667
|
+
}
|
|
10668
|
+
if (data["encoding"] !== void 0 && typeof data["encoding"] !== "string") {
|
|
10669
|
+
return false;
|
|
10670
|
+
}
|
|
10671
|
+
if (data["signatures"] !== void 0 && (!Array.isArray(data["signatures"]) || !data["signatures"].every(IsAPublicKeySignature))) {
|
|
10672
|
+
return false;
|
|
10673
|
+
}
|
|
10674
|
+
return true;
|
|
10675
|
+
}
|
|
10676
|
+
function isPublicKeySubject(data) {
|
|
10677
|
+
if (data === void 0)
|
|
10678
|
+
return true;
|
|
10679
|
+
if (isStringOrStringArray(data))
|
|
10680
|
+
return true;
|
|
10681
|
+
if (!isMandatoryJSONObject(data))
|
|
10682
|
+
return false;
|
|
10683
|
+
return Object.values(data).every(
|
|
10684
|
+
(value) => typeof value === "string" || isStringOrStringArray(value)
|
|
10685
|
+
);
|
|
10686
|
+
}
|
|
10687
|
+
function IsAPublicKeySignature(data) {
|
|
10688
|
+
if (!isMandatoryJSONObject(data))
|
|
10689
|
+
return false;
|
|
10690
|
+
if (!isOptionalString(data["@id"]))
|
|
10691
|
+
return false;
|
|
10692
|
+
if (data["@context"] !== void 0 && !isStringOrStringArray(data["@context"]))
|
|
10693
|
+
return false;
|
|
10694
|
+
if (!isOptionalStringOrOIDInfo(data["algorithm"]))
|
|
10695
|
+
return false;
|
|
10696
|
+
if (!isOptionalString(data["format"]))
|
|
10697
|
+
return false;
|
|
10698
|
+
if (!isOptionalString(data["encoding"]))
|
|
10699
|
+
return false;
|
|
10700
|
+
if (data["value"] !== void 0 && !isString(data["value"]))
|
|
10701
|
+
return false;
|
|
10702
|
+
if (data["publicKey"] !== void 0 && !isEncodedValue(data["publicKey"]))
|
|
10703
|
+
return false;
|
|
10704
|
+
if (data["signature"] !== void 0 && !isEncodedValue(data["signature"]))
|
|
10705
|
+
return false;
|
|
10706
|
+
if (!isOptionalString(data["timestamp"]))
|
|
10707
|
+
return false;
|
|
10708
|
+
if (!isOptionalString(data["issuer"]))
|
|
10709
|
+
return false;
|
|
10710
|
+
if (!isOptionalString(data["signer"]))
|
|
10711
|
+
return false;
|
|
10712
|
+
if (!isOptionalString(data["notBefore"]))
|
|
10713
|
+
return false;
|
|
10714
|
+
if (!isOptionalString(data["notAfter"]))
|
|
10715
|
+
return false;
|
|
10716
|
+
if (!isOptionalStringArray(data["keyUsage"]))
|
|
10717
|
+
return false;
|
|
10718
|
+
if (data["operations"] !== void 0 && !isMandatoryJSONObject(data["operations"]))
|
|
10719
|
+
return false;
|
|
10720
|
+
if (data["comment"] !== void 0 && !isMandatoryJSONObject(data["comment"]))
|
|
10721
|
+
return false;
|
|
10722
|
+
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;
|
|
10723
|
+
}
|
|
10724
|
+
function IsAPublicKeyXY(data) {
|
|
10725
|
+
if (!IsAPublicKey(data))
|
|
10726
|
+
return false;
|
|
10727
|
+
if (!isString(data["x"])) {
|
|
10728
|
+
return false;
|
|
10729
|
+
}
|
|
10730
|
+
if (!isString(data["y"])) {
|
|
10731
|
+
return false;
|
|
10732
|
+
}
|
|
10733
|
+
return true;
|
|
10734
|
+
}
|
|
10735
|
+
var EDL40_SESSION_CONTEXT = "https://open.charging.cloud/contexts/SessionSignatureFormats/EDL40+json";
|
|
10736
|
+
var EDL40_SIGNATURE_CONTEXT = "https://open.charging.cloud/contexts/EnergyMeterSignatureFormats/EDL40+json";
|
|
10737
|
+
var EDL40_OBIS = "1-0:1.8.0*255";
|
|
10738
|
+
var EDL40ValidationError = class extends Error {
|
|
10739
|
+
constructor(code, message) {
|
|
10740
|
+
super(message);
|
|
10741
|
+
this.code = code;
|
|
10742
|
+
this.name = "EDL40ValidationError";
|
|
10743
|
+
}
|
|
10744
|
+
code;
|
|
10745
|
+
};
|
|
10746
|
+
var START_ESCAPE = [27, 27, 27, 27, 1, 1, 1, 1];
|
|
10747
|
+
var ESCAPE = [27, 27, 27, 27];
|
|
10748
|
+
var REQUIRED_UNIT = 30;
|
|
10749
|
+
var SIGNATURE_LENGTH = 320;
|
|
10750
|
+
var OBIS_CONTRACT_ID = "8182815401ff";
|
|
10751
|
+
var OBIS_SIGNED_VALUE = "0100011100ff";
|
|
10752
|
+
var OBIS_SIGNED_VALUE_2 = "0100010800ff";
|
|
10753
|
+
var OBIS_EDL_PAGINATION = "8180817101ff";
|
|
10754
|
+
var OBIS_EDL_SECONDS_INDEX = "810060080001";
|
|
10755
|
+
var OBIS_SIGNATURE_VERSION = "00af737672ff";
|
|
10756
|
+
var OBIS_START_EC = "010001080080";
|
|
10757
|
+
var OBIS_ACTUAL_EC = "0100010800ff";
|
|
10758
|
+
var OBIS_ISA_PAGINATION = "8180c7f040ff";
|
|
10759
|
+
var OBIS_ESTH = "8180816101ff";
|
|
10760
|
+
function canParseEDL40(data) {
|
|
10761
|
+
try {
|
|
10762
|
+
parseEDL40(data);
|
|
10763
|
+
return true;
|
|
10764
|
+
} catch {
|
|
10765
|
+
return false;
|
|
10766
|
+
}
|
|
10767
|
+
}
|
|
10768
|
+
function parseEDL40(data) {
|
|
10769
|
+
const res = parseGetListRes(data);
|
|
10770
|
+
try {
|
|
10771
|
+
return buildIsaSignature(res);
|
|
10772
|
+
} catch {
|
|
10773
|
+
return buildEDL40Signature(res);
|
|
10774
|
+
}
|
|
10775
|
+
}
|
|
10776
|
+
async function verifyEDL40Document(document2, publicKey, chargy) {
|
|
10777
|
+
const normalizedPublicKey = cleanHex(publicKey);
|
|
10778
|
+
if (document2.variant === "ISA_EDL_40_P") {
|
|
10779
|
+
const signature2 = document2.dataSignature;
|
|
10780
|
+
const hashValue = await hashSignedData(document2.signedData, 32);
|
|
10781
|
+
if (normalizedPublicKey.length !== 128 || signature2.length !== 64)
|
|
10782
|
+
return {
|
|
10783
|
+
status: "InvalidPublicKey" /* InvalidPublicKey */,
|
|
10784
|
+
curve: "secp256r1",
|
|
10785
|
+
hashValue,
|
|
10786
|
+
signature: signature2
|
|
10787
|
+
};
|
|
10788
|
+
return {
|
|
10789
|
+
status: verifyRawSignature(chargy, "secp256r1", normalizedPublicKey, signature2, hashValue),
|
|
10790
|
+
curve: "secp256r1",
|
|
10791
|
+
hashValue,
|
|
10792
|
+
signature: signature2
|
|
10793
|
+
};
|
|
10794
|
+
}
|
|
10795
|
+
const cutoff = document2.version === 4 || document2.listSignature.length === 50 ? 2 : 0;
|
|
10796
|
+
const signature = document2.listSignature.subarray(0, document2.listSignature.length - cutoff);
|
|
10797
|
+
if (normalizedPublicKey.length === 96 && signature.length === 48) {
|
|
10798
|
+
const hashValue = await hashSignedData(document2.signedData, 24);
|
|
10799
|
+
return {
|
|
10800
|
+
status: verifyRawSignature(chargy, "secp192r1", normalizedPublicKey, signature, hashValue),
|
|
10801
|
+
curve: "secp192r1",
|
|
10802
|
+
hashValue,
|
|
10803
|
+
signature
|
|
10804
|
+
};
|
|
10805
|
+
}
|
|
10806
|
+
if (normalizedPublicKey.length === 128 && signature.length === 64) {
|
|
10807
|
+
const hashValue = await hashSignedData(document2.signedData, 32);
|
|
10808
|
+
return {
|
|
10809
|
+
status: verifyRawSignature(chargy, "secp256r1", normalizedPublicKey, signature, hashValue),
|
|
10810
|
+
curve: "secp256r1",
|
|
10811
|
+
hashValue,
|
|
10812
|
+
signature
|
|
10813
|
+
};
|
|
10814
|
+
}
|
|
10815
|
+
return {
|
|
10816
|
+
status: normalizedPublicKey.length === 96 || normalizedPublicKey.length === 128 ? "InvalidSignature" /* InvalidSignature */ : "InvalidPublicKey" /* InvalidPublicKey */,
|
|
10817
|
+
curve: normalizedPublicKey.length === 128 ? "secp256r1" : "secp192r1",
|
|
10818
|
+
hashValue: await hashSignedData(document2.signedData, normalizedPublicKey.length === 128 ? 32 : 24),
|
|
10819
|
+
signature
|
|
10820
|
+
};
|
|
10821
|
+
}
|
|
10822
|
+
function parseGetListRes(data) {
|
|
10823
|
+
for (const encoding of guessEncoding(data)) {
|
|
10824
|
+
try {
|
|
10825
|
+
const bytes = decodeWithEncoding(encoding, data);
|
|
10826
|
+
const res = findGetListRes(decodeSmlMessages(stripTransport(bytes)));
|
|
10827
|
+
if (res != null)
|
|
10828
|
+
return res;
|
|
10829
|
+
} catch {
|
|
10830
|
+
}
|
|
10831
|
+
}
|
|
10832
|
+
throw new EDL40ValidationError("SML_NO_GETLISTRES", "No verifiable SML data found");
|
|
10833
|
+
}
|
|
10834
|
+
function guessEncoding(data) {
|
|
10835
|
+
const matches = [];
|
|
10836
|
+
if (data == null || data.trim().length === 0)
|
|
10837
|
+
return matches;
|
|
10838
|
+
try {
|
|
10839
|
+
decodeBase32(data);
|
|
10840
|
+
matches.push("base32");
|
|
10841
|
+
} catch {
|
|
10842
|
+
}
|
|
10843
|
+
try {
|
|
10844
|
+
decodeBase64(data);
|
|
10845
|
+
matches.push("base64");
|
|
10846
|
+
} catch {
|
|
10847
|
+
}
|
|
10848
|
+
try {
|
|
10849
|
+
hexToBytes(data);
|
|
10850
|
+
matches.push("hex");
|
|
10851
|
+
} catch {
|
|
10852
|
+
}
|
|
10853
|
+
return matches;
|
|
10854
|
+
}
|
|
10855
|
+
function decodeWithEncoding(encoding, data) {
|
|
10856
|
+
switch (encoding) {
|
|
10857
|
+
case "base32":
|
|
10858
|
+
return decodeBase32(data);
|
|
10859
|
+
case "base64":
|
|
10860
|
+
return decodeBase64(data);
|
|
10861
|
+
default:
|
|
10862
|
+
return hexToBytes(data);
|
|
10863
|
+
}
|
|
10864
|
+
}
|
|
10865
|
+
function decodeBase64(data) {
|
|
10866
|
+
const clean = data.replace(/\s+/g, "");
|
|
10867
|
+
if (clean.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(clean))
|
|
10868
|
+
throw new Error("Invalid base64 data");
|
|
10869
|
+
return base64ToBytes(clean);
|
|
10870
|
+
}
|
|
10871
|
+
function decodeBase32(data) {
|
|
10872
|
+
const clean = data.replace(/\s+/g, "").replace(/=+$/, "").toUpperCase();
|
|
10873
|
+
if (clean.length === 0)
|
|
10874
|
+
return new Uint8Array(0);
|
|
10875
|
+
if (!/^[A-Z2-7]+$/.test(clean))
|
|
10876
|
+
throw new Error("Invalid base32 data");
|
|
10877
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
10878
|
+
let bits = 0;
|
|
10879
|
+
let value = 0;
|
|
10880
|
+
const out = [];
|
|
10881
|
+
for (const ch of clean) {
|
|
10882
|
+
const idx = alphabet.indexOf(ch);
|
|
10883
|
+
value = value << 5 | idx;
|
|
10884
|
+
bits += 5;
|
|
10885
|
+
if (bits >= 8) {
|
|
10886
|
+
bits -= 8;
|
|
10887
|
+
out.push(value >>> bits & 255);
|
|
10888
|
+
}
|
|
10889
|
+
}
|
|
10890
|
+
return Uint8Array.from(out);
|
|
10891
|
+
}
|
|
10892
|
+
function stripTransport(raw) {
|
|
10893
|
+
const start = indexOfSeq(raw, START_ESCAPE);
|
|
10894
|
+
if (start < 0)
|
|
10895
|
+
return raw;
|
|
10896
|
+
let i = start + START_ESCAPE.length;
|
|
10897
|
+
const out = [];
|
|
10898
|
+
while (i < raw.length) {
|
|
10899
|
+
if (matchSeq(raw, i, ESCAPE)) {
|
|
10900
|
+
if (raw[i + 4] === 26)
|
|
10901
|
+
break;
|
|
10902
|
+
if (matchSeq(raw, i + 4, ESCAPE)) {
|
|
10903
|
+
out.push(27, 27, 27, 27);
|
|
10904
|
+
i += 8;
|
|
10905
|
+
continue;
|
|
10906
|
+
}
|
|
10907
|
+
}
|
|
10908
|
+
const byte = raw[i];
|
|
10909
|
+
if (byte === void 0)
|
|
10910
|
+
break;
|
|
10911
|
+
out.push(byte);
|
|
10912
|
+
i++;
|
|
10913
|
+
}
|
|
10914
|
+
return Uint8Array.from(out);
|
|
10915
|
+
}
|
|
10916
|
+
function readTLV(buf, pos) {
|
|
10917
|
+
if (pos >= buf.length)
|
|
10918
|
+
throw new EDL40ValidationError("SML_INCOMPLETE", "Unexpected end of SML data at " + pos.toString());
|
|
10919
|
+
const tl = byteAt(buf, pos);
|
|
10920
|
+
if (tl === 0)
|
|
10921
|
+
return { value: { kind: "empty" }, next: pos + 1 };
|
|
10922
|
+
if (tl === 1)
|
|
10923
|
+
return { value: null, next: pos + 1 };
|
|
10924
|
+
const type = tl >> 4 & 7;
|
|
10925
|
+
let len = tl & 15;
|
|
10926
|
+
let headerBytes = 1;
|
|
10927
|
+
if (tl & 128) {
|
|
10928
|
+
let p = pos + 1;
|
|
10929
|
+
while (p < buf.length && byteAt(buf, p) & 128) {
|
|
10930
|
+
len = len << 4 | byteAt(buf, p) & 15;
|
|
10931
|
+
p++;
|
|
10932
|
+
headerBytes++;
|
|
10933
|
+
}
|
|
10934
|
+
if (p >= buf.length)
|
|
10935
|
+
throw new EDL40ValidationError("SML_INCOMPLETE", "Truncated multi-byte length");
|
|
10936
|
+
len = len << 4 | byteAt(buf, p) & 15;
|
|
10937
|
+
headerBytes++;
|
|
10938
|
+
}
|
|
10939
|
+
if (type === 7) {
|
|
10940
|
+
let p = pos + headerBytes;
|
|
10941
|
+
const items = [];
|
|
10942
|
+
for (let k = 0; k < len; k++) {
|
|
10943
|
+
const r = readTLV(buf, p);
|
|
10944
|
+
items.push(r.value);
|
|
10945
|
+
p = r.next;
|
|
10946
|
+
}
|
|
10947
|
+
return { value: { kind: "list", items }, next: p };
|
|
10948
|
+
}
|
|
10949
|
+
const dataLen = len - headerBytes;
|
|
10950
|
+
if (dataLen < 0 || pos + headerBytes + dataLen > buf.length)
|
|
10951
|
+
throw new EDL40ValidationError("SML_TLV_INVALID", "Invalid TLV length at " + pos.toString());
|
|
10952
|
+
const data = buf.slice(pos + headerBytes, pos + headerBytes + dataLen);
|
|
10953
|
+
const next = pos + headerBytes + dataLen;
|
|
10954
|
+
switch (type) {
|
|
10955
|
+
case 0:
|
|
10956
|
+
return { value: { kind: "octet", bytes: data }, next };
|
|
10957
|
+
case 4:
|
|
10958
|
+
return { value: { kind: "bool", value: data.length > 0 && data[0] !== 0 }, next };
|
|
10959
|
+
case 5:
|
|
10960
|
+
return { value: { kind: "int", value: toSignedBigInt(data) }, next };
|
|
10961
|
+
case 6:
|
|
10962
|
+
return { value: { kind: "uint", value: toUnsignedBigInt(data) }, next };
|
|
10963
|
+
default:
|
|
10964
|
+
throw new EDL40ValidationError("SML_TLV_INVALID", "Unknown SML type 0x" + type.toString(16));
|
|
10965
|
+
}
|
|
10966
|
+
}
|
|
10967
|
+
function decodeSmlMessages(payload) {
|
|
10968
|
+
const messages = [];
|
|
10969
|
+
let pos = 0;
|
|
10970
|
+
while (pos < payload.length) {
|
|
10971
|
+
if (payload[pos] === 0) {
|
|
10972
|
+
pos++;
|
|
10973
|
+
continue;
|
|
10974
|
+
}
|
|
10975
|
+
const r = readTLV(payload, pos);
|
|
10976
|
+
if (r.next <= pos)
|
|
10977
|
+
break;
|
|
10978
|
+
if (r.value?.kind === "list")
|
|
10979
|
+
messages.push(r.value);
|
|
10980
|
+
pos = r.next;
|
|
10981
|
+
}
|
|
10982
|
+
return messages;
|
|
10983
|
+
}
|
|
10984
|
+
function findGetListRes(messages) {
|
|
10985
|
+
for (const msg of messages) {
|
|
10986
|
+
if (msg.kind !== "list" || msg.items.length < 4)
|
|
10987
|
+
continue;
|
|
10988
|
+
const messageBody = msg.items[3];
|
|
10989
|
+
if (messageBody?.kind !== "list" || messageBody.items.length < 2)
|
|
10990
|
+
continue;
|
|
10991
|
+
const tagNode = messageBody.items[0];
|
|
10992
|
+
const bodyNode = messageBody.items[1];
|
|
10993
|
+
if (tagNode == null || tagNode.kind !== "uint" && tagNode.kind !== "int")
|
|
10994
|
+
continue;
|
|
10995
|
+
if (Number(tagNode.value) !== 1793 || bodyNode == null)
|
|
10996
|
+
continue;
|
|
10997
|
+
const res = parseGetListResNode(bodyNode);
|
|
10998
|
+
if (res != null)
|
|
10999
|
+
return res;
|
|
11000
|
+
}
|
|
11001
|
+
return null;
|
|
11002
|
+
}
|
|
11003
|
+
function parseGetListResNode(body) {
|
|
11004
|
+
if (body.kind !== "list" || body.items.length < 6)
|
|
11005
|
+
return null;
|
|
11006
|
+
const serverId = octet(body.items[1]);
|
|
11007
|
+
const listName = octet(body.items[2]);
|
|
11008
|
+
const valListNode = body.items[4];
|
|
11009
|
+
const listSignature = octet(body.items[5]);
|
|
11010
|
+
if (serverId == null || listSignature == null || valListNode?.kind !== "list")
|
|
11011
|
+
return null;
|
|
11012
|
+
const valList = [];
|
|
11013
|
+
for (const entry of valListNode.items) {
|
|
11014
|
+
const parsed = parseListEntry(entry);
|
|
11015
|
+
if (parsed != null)
|
|
11016
|
+
valList.push(parsed);
|
|
11017
|
+
}
|
|
11018
|
+
return { serverId, listName, valList, listSignature };
|
|
11019
|
+
}
|
|
11020
|
+
function parseListEntry(v) {
|
|
11021
|
+
if (v?.kind !== "list")
|
|
11022
|
+
return null;
|
|
11023
|
+
return {
|
|
11024
|
+
objName: octet(v.items[0]),
|
|
11025
|
+
status: v.items[1] ?? null,
|
|
11026
|
+
valTime: parseSmlTime(v.items[2]),
|
|
11027
|
+
unit: num(v.items[3]),
|
|
11028
|
+
scaler: num(v.items[4]),
|
|
11029
|
+
value: v.items[5] ?? null,
|
|
11030
|
+
valueSignature: octet(v.items[6])
|
|
11031
|
+
};
|
|
11032
|
+
}
|
|
11033
|
+
function findEntryByObis(res, obisHex) {
|
|
11034
|
+
const target = obisHex.toLowerCase();
|
|
11035
|
+
for (const entry of res.valList)
|
|
11036
|
+
if (entry.objName != null && bytesToHex2(entry.objName) === target)
|
|
11037
|
+
return entry;
|
|
11038
|
+
return null;
|
|
11039
|
+
}
|
|
11040
|
+
function parseSmlTime(v) {
|
|
11041
|
+
if (v?.kind !== "list" || v.items.length < 2)
|
|
11042
|
+
return null;
|
|
11043
|
+
const tag = asNumber2(v.items[0]);
|
|
11044
|
+
const body = v.items[1];
|
|
11045
|
+
if (tag === 1)
|
|
11046
|
+
return { kind: "secIndex", timestamp: asNumber2(body), localOffsetMin: 0, seasonOffsetMin: 0 };
|
|
11047
|
+
if (tag === 2)
|
|
11048
|
+
return { kind: "timestamp", timestamp: asNumber2(body), localOffsetMin: 0, seasonOffsetMin: 0 };
|
|
11049
|
+
if (tag === 3 && body?.kind === "list" && body.items.length >= 3)
|
|
11050
|
+
return {
|
|
11051
|
+
kind: "timestampLocal",
|
|
11052
|
+
timestamp: asNumber2(body.items[0]),
|
|
11053
|
+
localOffsetMin: asNumber2(body.items[1]),
|
|
11054
|
+
seasonOffsetMin: asNumber2(body.items[2])
|
|
11055
|
+
};
|
|
11056
|
+
return null;
|
|
11057
|
+
}
|
|
11058
|
+
function resolveSmlTime(t) {
|
|
11059
|
+
const offsetSec = (t.localOffsetMin + t.seasonOffsetMin) * 60;
|
|
11060
|
+
return {
|
|
11061
|
+
localEpoch: t.timestamp + offsetSec,
|
|
11062
|
+
date: new Date(t.timestamp * 1e3)
|
|
11063
|
+
};
|
|
11064
|
+
}
|
|
11065
|
+
function buildEDL40Signature(res) {
|
|
11066
|
+
const listSignature = res.listSignature;
|
|
11067
|
+
const isEmoc = listSignature.length === 66;
|
|
11068
|
+
let signedValueEntry = findEntryByObis(res, OBIS_SIGNED_VALUE);
|
|
11069
|
+
signedValueEntry ??= findEntryByObis(res, OBIS_SIGNED_VALUE_2);
|
|
11070
|
+
if (signedValueEntry == null)
|
|
11071
|
+
throw new EDL40ValidationError("MISSING_FIELD", "EDL40: missing signed value entry");
|
|
11072
|
+
const contractEntry = findEntryByObis(res, OBIS_CONTRACT_ID);
|
|
11073
|
+
const paginationEntry = findEntryByObis(res, OBIS_EDL_PAGINATION);
|
|
11074
|
+
const secondsIndexEntry = findEntryByObis(res, OBIS_EDL_SECONDS_INDEX);
|
|
11075
|
+
const versionEntry = findEntryByObis(res, OBIS_SIGNATURE_VERSION);
|
|
11076
|
+
const unit = signedValueEntry.unit ?? 0;
|
|
11077
|
+
if (unit !== REQUIRED_UNIT)
|
|
11078
|
+
throw new EDL40ValidationError("INVALID_UNIT", "EDL40: unit must be 30 (Wh)");
|
|
11079
|
+
const scaler = signedValueEntry.scaler ?? 0;
|
|
11080
|
+
const meterValue = valueAsLong(signedValueEntry);
|
|
11081
|
+
const obisId = signedValueEntry.objName ?? new Uint8Array(6);
|
|
11082
|
+
let status = 0;
|
|
11083
|
+
if (signedValueEntry.status != null && (signedValueEntry.status.kind === "uint" || signedValueEntry.status.kind === "int"))
|
|
11084
|
+
status = Number(BigInt.asUintN(32, signedValueEntry.status.value)) & 255;
|
|
11085
|
+
if (isEmoc && signedValueEntry.status != null && (signedValueEntry.status.kind === "uint" || signedValueEntry.status.kind === "int"))
|
|
11086
|
+
status = transformEDL40Status(Number(BigInt.asUintN(32, signedValueEntry.status.value)));
|
|
11087
|
+
let pagination = 0;
|
|
11088
|
+
const p = deepFirstInt(paginationEntry?.value);
|
|
11089
|
+
if (p != null)
|
|
11090
|
+
pagination = Number(p);
|
|
11091
|
+
let secondsIndex = 0;
|
|
11092
|
+
const s = deepFirstInt(secondsIndexEntry?.value);
|
|
11093
|
+
if (s != null)
|
|
11094
|
+
secondsIndex = Number(s);
|
|
11095
|
+
let version = 0;
|
|
11096
|
+
const ver = deepFirstInt(versionEntry?.value);
|
|
11097
|
+
if (ver != null)
|
|
11098
|
+
version = Number(ver);
|
|
11099
|
+
const contractRaw = contractEntry?.value?.kind === "octet" ? contractEntry.value.bytes : new Uint8Array(0);
|
|
11100
|
+
const contractId = new Uint8Array(128);
|
|
11101
|
+
contractId.set(contractRaw.subarray(0, 128), 0);
|
|
11102
|
+
const out = new Uint8Array(SIGNATURE_LENGTH);
|
|
11103
|
+
out.set(res.serverId.subarray(0, 10), 0);
|
|
11104
|
+
out.set(timeBytes(signedValueEntry), 10);
|
|
11105
|
+
out[14] = status;
|
|
11106
|
+
out.set(reverseBytes(intToBytesBE(secondsIndex >>> 0)), 15);
|
|
11107
|
+
out.set(reverseBytes(intToBytesBE(pagination >>> 0)), 19);
|
|
11108
|
+
out.set(obisId.subarray(0, 6), 23);
|
|
11109
|
+
out[29] = unit & 255;
|
|
11110
|
+
out[30] = scaler & 255;
|
|
11111
|
+
out.set(reverseBytes(longToBytesBE(meterValue)), 31);
|
|
11112
|
+
out.set(listSignature.subarray(listSignature.length - 2), 39);
|
|
11113
|
+
out.set(contractId, 41);
|
|
11114
|
+
if (contractEntry != null)
|
|
11115
|
+
out.set(timeBytes(contractEntry), 169);
|
|
11116
|
+
return {
|
|
11117
|
+
variant: "EDL_40_P",
|
|
11118
|
+
signedData: out,
|
|
11119
|
+
listSignature,
|
|
11120
|
+
version,
|
|
11121
|
+
isEmoc,
|
|
11122
|
+
unit,
|
|
11123
|
+
scaler,
|
|
11124
|
+
serverId: res.serverId,
|
|
11125
|
+
contractId,
|
|
11126
|
+
pagination,
|
|
11127
|
+
meterValue,
|
|
11128
|
+
obisId,
|
|
11129
|
+
status,
|
|
11130
|
+
meterDate: signedValueEntry.valTime != null ? resolveSmlTime(signedValueEntry.valTime).date : /* @__PURE__ */ new Date(0)
|
|
11131
|
+
};
|
|
11132
|
+
}
|
|
11133
|
+
function buildIsaSignature(res) {
|
|
11134
|
+
const contractEntry = requireEntry(res, OBIS_CONTRACT_ID, "contract-id");
|
|
11135
|
+
const startEntry = requireEntry(res, OBIS_START_EC, "start-ec");
|
|
11136
|
+
const actualEntry = requireEntry(res, OBIS_ACTUAL_EC, "actual-ec");
|
|
11137
|
+
const paginationEntry = requireEntry(res, OBIS_ISA_PAGINATION, "pagination");
|
|
11138
|
+
const esthEntry = requireEntry(res, OBIS_ESTH, "esth");
|
|
11139
|
+
const actualUnit = actualEntry.unit ?? 0;
|
|
11140
|
+
const startUnit = startEntry.unit ?? 0;
|
|
11141
|
+
if (actualUnit !== REQUIRED_UNIT || startUnit !== REQUIRED_UNIT)
|
|
11142
|
+
throw new EDL40ValidationError("INVALID_UNIT", "ISA: unit must be 30 (Wh)");
|
|
11143
|
+
if (paginationEntry.value == null || paginationEntry.value.kind !== "uint" && paginationEntry.value.kind !== "int")
|
|
11144
|
+
throw new EDL40ValidationError("MISSING_FIELD", "ISA: pagination is not an unsigned integer");
|
|
11145
|
+
const contractRaw = contractEntry.value?.kind === "octet" ? contractEntry.value.bytes : new Uint8Array(0);
|
|
11146
|
+
const contractId = new Uint8Array(128);
|
|
11147
|
+
contractId.set(contractRaw.subarray(0, 128), 0);
|
|
11148
|
+
const esth = esthEntry.value?.kind === "octet" ? esthEntry.value.bytes : new Uint8Array(20);
|
|
11149
|
+
const actualStatus = status8(actualEntry);
|
|
11150
|
+
const startStatus = status8(startEntry);
|
|
11151
|
+
const actualValue = valueAsLong(actualEntry);
|
|
11152
|
+
const startValue = valueAsLong(startEntry);
|
|
11153
|
+
const actualSig = actualEntry.valueSignature ?? new Uint8Array(66);
|
|
11154
|
+
const listName = res.listName ?? new Uint8Array(6);
|
|
11155
|
+
const listSignature = res.listSignature;
|
|
11156
|
+
const dataSignature = listSignature.subarray(0, listSignature.length - 2);
|
|
11157
|
+
const pagination = Number(paginationEntry.value.value);
|
|
11158
|
+
const out = new Uint8Array(SIGNATURE_LENGTH);
|
|
11159
|
+
out.set(res.serverId.subarray(0, 10), 0);
|
|
11160
|
+
out.set(timeBytes(actualEntry), 10);
|
|
11161
|
+
out[14] = actualStatus[7] ?? 0;
|
|
11162
|
+
out.set((actualEntry.objName ?? new Uint8Array(6)).subarray(0, 6), 15);
|
|
11163
|
+
out[21] = actualUnit & 255;
|
|
11164
|
+
out[22] = (actualEntry.scaler ?? 0) & 255;
|
|
11165
|
+
out.set(reverseBytes(longToBytesBE(actualValue)), 23);
|
|
11166
|
+
out.set(listSignature.subarray(listSignature.length - 2), 31);
|
|
11167
|
+
out.set(actualSig.subarray(0, 66), 33);
|
|
11168
|
+
out.set(contractId, 99);
|
|
11169
|
+
out.set(timeBytes(startEntry), 227);
|
|
11170
|
+
out.set(esth.subarray(0, 20), 231);
|
|
11171
|
+
out[251] = startStatus[7] ?? 0;
|
|
11172
|
+
out.set((startEntry.objName ?? new Uint8Array(6)).subarray(0, 6), 252);
|
|
11173
|
+
out[258] = startUnit & 255;
|
|
11174
|
+
out[259] = (startEntry.scaler ?? 0) & 255;
|
|
11175
|
+
out.set(reverseBytes(longToBytesBE(startValue)), 260);
|
|
11176
|
+
out.set(listName.subarray(0, 6), 268);
|
|
11177
|
+
out.set(reverseBytes(intToBytesBE(pagination >>> 0)), 274);
|
|
11178
|
+
return {
|
|
11179
|
+
variant: "ISA_EDL_40_P",
|
|
11180
|
+
signedData: out,
|
|
11181
|
+
dataSignature,
|
|
11182
|
+
listSignature,
|
|
11183
|
+
serverId: res.serverId,
|
|
11184
|
+
listName: res.listName,
|
|
11185
|
+
contractId,
|
|
11186
|
+
pagination,
|
|
11187
|
+
unit: actualUnit,
|
|
11188
|
+
actualEcValue: actualValue,
|
|
11189
|
+
actualEcScaler: actualEntry.scaler ?? 0,
|
|
11190
|
+
actualEcObis: actualEntry.objName ?? new Uint8Array(6),
|
|
11191
|
+
actualEcStatus: actualStatus,
|
|
11192
|
+
actualEcDate: actualEntry.valTime != null ? resolveSmlTime(actualEntry.valTime).date : /* @__PURE__ */ new Date(0),
|
|
11193
|
+
startEcValue: startValue,
|
|
11194
|
+
startEcScaler: startEntry.scaler ?? 0,
|
|
11195
|
+
startEcObis: startEntry.objName ?? new Uint8Array(6),
|
|
11196
|
+
startEcStatus: startStatus,
|
|
11197
|
+
startEcDate: startEntry.valTime != null ? resolveSmlTime(startEntry.valTime).date : /* @__PURE__ */ new Date(0)
|
|
11198
|
+
};
|
|
11199
|
+
}
|
|
11200
|
+
function isaListNameContext(listName) {
|
|
11201
|
+
const hex = listName != null ? bytesToHex2(listName) : "";
|
|
11202
|
+
if (hex === "8180816201ff")
|
|
11203
|
+
return "UPDATE";
|
|
11204
|
+
if (hex === "8180816202ff")
|
|
11205
|
+
return "STOP";
|
|
11206
|
+
return "START";
|
|
11207
|
+
}
|
|
11208
|
+
function transformEDL40Status(value) {
|
|
11209
|
+
let b = 0;
|
|
11210
|
+
const set = (targetBit, sourceBit) => {
|
|
11211
|
+
if (value & 1 << sourceBit)
|
|
11212
|
+
b |= 1 << targetBit;
|
|
11213
|
+
};
|
|
11214
|
+
set(0, 17);
|
|
11215
|
+
set(3, 31);
|
|
11216
|
+
set(4, 16);
|
|
11217
|
+
set(5, 11);
|
|
11218
|
+
set(6, 9);
|
|
11219
|
+
set(7, 8);
|
|
11220
|
+
return b & 255;
|
|
11221
|
+
}
|
|
11222
|
+
var EDL40Crypt01 = class extends ACrypt {
|
|
11223
|
+
constructor(chargy) {
|
|
11224
|
+
super(
|
|
11225
|
+
"EDL40/ISA-EDL40",
|
|
11226
|
+
chargy
|
|
11227
|
+
);
|
|
11228
|
+
}
|
|
11229
|
+
async VerifyChargingSession(chargingSession) {
|
|
11230
|
+
let sessionResult = "ValidSignature" /* ValidSignature */;
|
|
11231
|
+
let valueCount = 0;
|
|
11232
|
+
for (const measurement of chargingSession.measurements ?? []) {
|
|
11233
|
+
measurement.chargingSession = chargingSession;
|
|
11234
|
+
for (const measurementValue of measurement.values) {
|
|
11235
|
+
valueCount++;
|
|
11236
|
+
measurementValue.measurement = measurement;
|
|
11237
|
+
const result = await this.VerifyMeasurement(measurementValue);
|
|
11238
|
+
if (result.status !== "ValidSignature" /* ValidSignature */)
|
|
11239
|
+
sessionResult = "InvalidSignature" /* InvalidSignature */;
|
|
11240
|
+
}
|
|
11241
|
+
if (measurement.values.length > 0 && measurement.values.every((value) => value.result?.status === "ValidSignature" /* ValidSignature */)) {
|
|
11242
|
+
measurement.verificationResult = {
|
|
11243
|
+
status: "ValidSignature" /* ValidSignature */
|
|
11244
|
+
};
|
|
11245
|
+
} else {
|
|
11246
|
+
measurement.verificationResult = {
|
|
11247
|
+
status: "InvalidSignature" /* InvalidSignature */
|
|
11248
|
+
};
|
|
11249
|
+
}
|
|
11250
|
+
}
|
|
11251
|
+
if (valueCount === 0)
|
|
11252
|
+
sessionResult = "InvalidSessionFormat" /* InvalidSessionFormat */;
|
|
11253
|
+
return {
|
|
11254
|
+
status: sessionResult,
|
|
11255
|
+
certainty: 0.9
|
|
11256
|
+
};
|
|
11257
|
+
}
|
|
11258
|
+
async VerifyMeasurement(measurementValue) {
|
|
11259
|
+
measurementValue.method = this;
|
|
11260
|
+
const document2 = measurementValue.edl40Document;
|
|
11261
|
+
const result = {
|
|
11262
|
+
status: document2.validationStatus,
|
|
11263
|
+
hashValue: document2.hashValue,
|
|
11264
|
+
signedData: document2.signedData,
|
|
11265
|
+
publicKey: document2.publicKey,
|
|
11266
|
+
publicKeyFormat: document2.publicKeyFormat,
|
|
11267
|
+
signature: document2.signature,
|
|
11268
|
+
serverId: document2.serverId,
|
|
11269
|
+
variant: document2.variant,
|
|
11270
|
+
curve: document2.curve,
|
|
11271
|
+
pagination: document2.pagination.toString(),
|
|
11272
|
+
obis: measurementValue.measurement?.obis,
|
|
11273
|
+
unitEncoded: String(measurementValue.measurement?.unitEncoded ?? ""),
|
|
11274
|
+
scaler: String(measurementValue.measurement?.scale ?? ""),
|
|
11275
|
+
value: measurementValue.value.toString()
|
|
11276
|
+
};
|
|
11277
|
+
measurementValue.result = result;
|
|
11278
|
+
return Promise.resolve(result);
|
|
11279
|
+
}
|
|
11280
|
+
async ViewMeasurement(measurementValue, errorDiv, introDiv, infoDiv, PlainTextDiv, HashedPlainTextDiv, PublicKeyDiv, SignatureExpectedDiv, SignatureCheckDiv) {
|
|
11281
|
+
const result = measurementValue.result;
|
|
11282
|
+
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 ?? "");
|
|
11283
|
+
PlainTextDiv.innerHTML = result?.signedData?.match(/.{1,8}/g)?.join(" ") ?? "";
|
|
11284
|
+
HashedPlainTextDiv.innerHTML = result?.hashValue?.match(/.{1,8}/g)?.join(" ") ?? "";
|
|
11285
|
+
PublicKeyDiv.innerHTML = result?.publicKey?.match(/.{1,8}/g)?.join(" ") ?? "";
|
|
11286
|
+
SignatureExpectedDiv.innerHTML = result?.signature != null ? "r: " + (result.signature.r.match(/.{1,8}/g)?.join(" ") ?? "") + "<br />s: " + (result.signature.s.match(/.{1,8}/g)?.join(" ") ?? "") : "";
|
|
11287
|
+
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>";
|
|
11288
|
+
return Promise.resolve(void 0);
|
|
11289
|
+
}
|
|
11290
|
+
};
|
|
11291
|
+
var EDL40 = class {
|
|
11292
|
+
constructor(chargy) {
|
|
11293
|
+
this.chargy = chargy;
|
|
11294
|
+
}
|
|
11295
|
+
chargy;
|
|
11296
|
+
async TryToParseEDL40Documents(signedDataValues, publicKey, containerInfos) {
|
|
11297
|
+
try {
|
|
11298
|
+
if (signedDataValues.length === 0)
|
|
11299
|
+
return {
|
|
11300
|
+
status: "InvalidSessionFormat" /* InvalidSessionFormat */,
|
|
11301
|
+
message: this.chargy.GetMultilanguageText("The given EDL40 data could not be parsed!"),
|
|
11302
|
+
certainty: 0
|
|
11303
|
+
};
|
|
11304
|
+
const parsed = signedDataValues.map((signedData) => ({
|
|
11305
|
+
raw: signedData,
|
|
11306
|
+
signature: parseEDL40(signedData)
|
|
11307
|
+
}));
|
|
11308
|
+
const variants = new Set(parsed.map((value) => value.signature.variant));
|
|
11309
|
+
if (variants.size > 1)
|
|
11310
|
+
return {
|
|
11311
|
+
status: "InvalidSessionFormat" /* InvalidSessionFormat */,
|
|
11312
|
+
message: this.chargy.GetMultilanguageText("Invalid mixture of different signed data formats within the given XML container!"),
|
|
11313
|
+
certainty: 0
|
|
11314
|
+
};
|
|
11315
|
+
const documents = [];
|
|
11316
|
+
for (const value of parsed) {
|
|
11317
|
+
const verification = await verifyEDL40Document(value.signature, publicKey, this.chargy);
|
|
11318
|
+
const signatureHex = bytesToHex2(verification.signature);
|
|
11319
|
+
const document2 = {
|
|
11320
|
+
"@context": "EDL40",
|
|
11321
|
+
raw: value.raw,
|
|
11322
|
+
variant: value.signature.variant,
|
|
11323
|
+
curve: verification.curve,
|
|
11324
|
+
encoding: "guessed",
|
|
11325
|
+
serverId: bytesToHex2(value.signature.serverId),
|
|
11326
|
+
contractId: bytesToHex2(trimPaddingAtEnd(value.signature.contractId)),
|
|
11327
|
+
publicKey: cleanHex(publicKey),
|
|
11328
|
+
publicKeyFormat: "XY" /* XY */,
|
|
11329
|
+
signedData: bytesToHex2(value.signature.signedData),
|
|
11330
|
+
hashAlgorithm: "SHA256",
|
|
11331
|
+
hashValue: verification.hashValue,
|
|
11332
|
+
signatureHex,
|
|
11333
|
+
signature: rawSignatureToRS(verification.signature),
|
|
11334
|
+
pagination: value.signature.pagination,
|
|
11335
|
+
validationStatus: verification.status
|
|
11336
|
+
};
|
|
11337
|
+
if (value.signature.variant === "ISA_EDL_40_P")
|
|
11338
|
+
document2.listNameContext = isaListNameContext(value.signature.listName);
|
|
11339
|
+
documents.push(document2);
|
|
11340
|
+
}
|
|
11341
|
+
return this.toChargeTransparencyRecord(parsed.map((value) => value.signature), documents, publicKey, containerInfos);
|
|
11342
|
+
} catch (exception) {
|
|
11343
|
+
return {
|
|
11344
|
+
status: "InvalidSessionFormat" /* InvalidSessionFormat */,
|
|
11345
|
+
message: this.chargy.GetMultilanguageText(exception instanceof Error ? exception.message : String(exception)),
|
|
11346
|
+
certainty: 0
|
|
11347
|
+
};
|
|
11348
|
+
}
|
|
11349
|
+
}
|
|
11350
|
+
toChargeTransparencyRecord(signatures, documents, publicKey, containerInfos) {
|
|
11351
|
+
const first = getFirstArrayElement(signatures, "Missing EDL40 signature data");
|
|
11352
|
+
const values = this.toMeasurementValues(signatures, documents);
|
|
11353
|
+
const firstValue2 = getFirstArrayElement(values, "Missing EDL40 measurement value");
|
|
11354
|
+
const lastValue = values[values.length - 1] ?? firstValue2;
|
|
11355
|
+
const serverId = bytesToHex2(first.serverId);
|
|
11356
|
+
const meterId = serverId;
|
|
11357
|
+
const sessionId = serverId + "-" + String(first.pagination) + "-" + String(signatures[signatures.length - 1]?.pagination ?? first.pagination);
|
|
11358
|
+
const curve = documents[0]?.curve ?? "secp192r1";
|
|
11359
|
+
const variant = first.variant;
|
|
11360
|
+
const evseId = containerInfos?.chargingStations?.[0]?.EVSEs?.[0]?.["@id"] ?? "DE*GEF*EVSE*EDL40*1";
|
|
11361
|
+
const chargingStation = containerInfos?.chargingStations?.[0] ?? {
|
|
11362
|
+
"@id": "DE*GEF*STATION*EDL40*1",
|
|
11363
|
+
"description": { "en": "EDL40 charging station" }
|
|
11364
|
+
};
|
|
11365
|
+
chargingStation.EVSEs ??= [
|
|
11366
|
+
{
|
|
11367
|
+
"@id": evseId
|
|
11368
|
+
}
|
|
11369
|
+
];
|
|
11370
|
+
let primaryEVSE = chargingStation.EVSEs[0];
|
|
11371
|
+
if (primaryEVSE == null) {
|
|
11372
|
+
primaryEVSE = {
|
|
11373
|
+
"@id": evseId
|
|
11374
|
+
};
|
|
11375
|
+
chargingStation.EVSEs = [primaryEVSE];
|
|
11376
|
+
}
|
|
11377
|
+
primaryEVSE.energyMeters = [
|
|
11378
|
+
{
|
|
11379
|
+
"@id": meterId,
|
|
11380
|
+
"manufacturer": { "name": variant === "ISA_EDL_40_P" ? "ISA" : "EDL40" },
|
|
11381
|
+
"signatureFormat": EDL40_SIGNATURE_CONTEXT,
|
|
11382
|
+
"publicKeys": [
|
|
11383
|
+
{
|
|
11384
|
+
"value": cleanHex(publicKey),
|
|
11385
|
+
"algorithm": curve,
|
|
11386
|
+
"format": "XY" /* XY */,
|
|
11387
|
+
"encoding": "hex" /* hex */
|
|
11388
|
+
}
|
|
11389
|
+
]
|
|
11390
|
+
}
|
|
11391
|
+
];
|
|
11392
|
+
const measurement = {
|
|
11393
|
+
"energyMeterId": meterId,
|
|
11394
|
+
"@context": EDL40_SIGNATURE_CONTEXT,
|
|
11395
|
+
"name": OBIS2MeasurementName(EDL40_OBIS),
|
|
11396
|
+
"obis": EDL40_OBIS,
|
|
11397
|
+
"unit": "kWh",
|
|
11398
|
+
"unitEncoded": 30,
|
|
11399
|
+
"scale": -3,
|
|
11400
|
+
"serverId": serverId,
|
|
11401
|
+
"publicKey": cleanHex(publicKey),
|
|
11402
|
+
"variant": variant,
|
|
11403
|
+
"curve": curve,
|
|
11404
|
+
"signatureInfos": {
|
|
11405
|
+
"hash": "SHA256" /* SHA256 */,
|
|
11406
|
+
"hashTruncation": curve === "secp192r1" ? 24 : 32,
|
|
11407
|
+
"algorithm": "ECC" /* ECC */,
|
|
11408
|
+
"curve": curve,
|
|
11409
|
+
"format": "RS" /* RS */,
|
|
11410
|
+
"encoding": "hex" /* hex */
|
|
11411
|
+
},
|
|
11412
|
+
"values": values
|
|
11413
|
+
};
|
|
11414
|
+
const firstDocument = documents[0];
|
|
11415
|
+
const authorizationStart = firstDocument?.contractId != null && firstDocument.contractId.length > 0 ? {
|
|
11416
|
+
"@id": firstDocument.contractId
|
|
11417
|
+
} : void 0;
|
|
11418
|
+
const chargingSession = {
|
|
11419
|
+
"@id": sessionId,
|
|
11420
|
+
"@context": EDL40_SESSION_CONTEXT,
|
|
11421
|
+
"begin": firstValue2.timestamp,
|
|
11422
|
+
"end": lastValue.timestamp,
|
|
11423
|
+
"internalSessionId": sessionId,
|
|
11424
|
+
"EVSEId": evseId,
|
|
11425
|
+
"meterId": meterId,
|
|
11426
|
+
"authorizationStart": authorizationStart,
|
|
11427
|
+
"measurements": [
|
|
11428
|
+
measurement
|
|
11429
|
+
]
|
|
11430
|
+
};
|
|
11431
|
+
return {
|
|
11432
|
+
"@id": sessionId,
|
|
11433
|
+
"@context": "https://open.charging.cloud/contexts/CTR+json",
|
|
11434
|
+
"begin": chargingSession.begin,
|
|
11435
|
+
"end": chargingSession.end,
|
|
11436
|
+
"description": {
|
|
11437
|
+
"de": "EDL40/ISA-EDL40 Ladevorgang",
|
|
11438
|
+
"en": "EDL40/ISA-EDL40 charging session"
|
|
11439
|
+
},
|
|
11440
|
+
"chargingStations": [
|
|
11441
|
+
chargingStation
|
|
11442
|
+
],
|
|
11443
|
+
"chargingSessions": [
|
|
11444
|
+
chargingSession
|
|
11445
|
+
],
|
|
11446
|
+
"publicKeys": [
|
|
11447
|
+
{
|
|
11448
|
+
"@context": "https://open.charging.cloud/contexts/publicKey+json",
|
|
11449
|
+
"subject": meterId,
|
|
11450
|
+
"algorithm": curve,
|
|
11451
|
+
"encoding": "hex" /* hex */,
|
|
11452
|
+
"format": "XY" /* XY */,
|
|
11453
|
+
"value": cleanHex(publicKey),
|
|
11454
|
+
"certainty": 1
|
|
11455
|
+
}
|
|
11456
|
+
],
|
|
11457
|
+
"warnings": containerInfos?.warnings,
|
|
11458
|
+
"edl40": {
|
|
11459
|
+
variant,
|
|
11460
|
+
serverId,
|
|
11461
|
+
paginationStart: first.pagination,
|
|
11462
|
+
paginationEnd: signatures[signatures.length - 1]?.pagination ?? first.pagination
|
|
11463
|
+
},
|
|
11464
|
+
"certainty": 1,
|
|
11465
|
+
"status": "Unvalidated" /* Unvalidated */
|
|
11466
|
+
};
|
|
11467
|
+
}
|
|
11468
|
+
toMeasurementValues(signatures, documents) {
|
|
11469
|
+
const values = [];
|
|
11470
|
+
for (let index = 0; index < signatures.length; index++) {
|
|
11471
|
+
const signature = getArrayElement(signatures, index, "Missing EDL40 signature data");
|
|
11472
|
+
const document2 = getArrayElement(documents, index, "Missing EDL40 document");
|
|
11473
|
+
if (signature.variant === "ISA_EDL_40_P") {
|
|
11474
|
+
values.push(this.toValue(
|
|
11475
|
+
signature.startEcDate,
|
|
11476
|
+
signature.startEcValue,
|
|
11477
|
+
signature.startEcScaler,
|
|
11478
|
+
bytesToHex2(signature.startEcStatus),
|
|
11479
|
+
signature.pagination,
|
|
11480
|
+
document2
|
|
11481
|
+
));
|
|
11482
|
+
values.push(this.toValue(
|
|
11483
|
+
signature.actualEcDate,
|
|
11484
|
+
signature.actualEcValue,
|
|
11485
|
+
signature.actualEcScaler,
|
|
11486
|
+
bytesToHex2(signature.actualEcStatus),
|
|
11487
|
+
signature.pagination,
|
|
11488
|
+
document2
|
|
11489
|
+
));
|
|
11490
|
+
} else {
|
|
11491
|
+
values.push(this.toValue(
|
|
11492
|
+
signature.meterDate,
|
|
11493
|
+
signature.meterValue,
|
|
11494
|
+
signature.scaler,
|
|
11495
|
+
signature.status.toString(16).padStart(2, "0"),
|
|
11496
|
+
signature.pagination,
|
|
11497
|
+
document2
|
|
11498
|
+
));
|
|
11499
|
+
}
|
|
11500
|
+
}
|
|
11501
|
+
return values.sort((left, right) => left.timestamp.localeCompare(right.timestamp));
|
|
11502
|
+
}
|
|
11503
|
+
toValue(timestamp, valueWh, scaler, statusMeter, pagination, document2) {
|
|
11504
|
+
return {
|
|
11505
|
+
"timestamp": timestamp.toISOString(),
|
|
11506
|
+
"value": scaledWhToKWh(valueWh, scaler),
|
|
11507
|
+
"statusMeter": statusMeter,
|
|
11508
|
+
"paginationId": pagination,
|
|
11509
|
+
"signatures": [
|
|
11510
|
+
document2.signature
|
|
11511
|
+
],
|
|
11512
|
+
"edl40Document": document2,
|
|
11513
|
+
"result": {
|
|
11514
|
+
"status": document2.validationStatus
|
|
11515
|
+
}
|
|
11516
|
+
};
|
|
11517
|
+
}
|
|
11518
|
+
};
|
|
11519
|
+
async function hashSignedData(signedData, crop) {
|
|
11520
|
+
return bytesToHex2((await sha256____(signedData)).subarray(0, crop));
|
|
11521
|
+
}
|
|
11522
|
+
function verifyRawSignature(chargy, curve, publicKey, signature, hashValue) {
|
|
11523
|
+
try {
|
|
11524
|
+
const ec = curve === "secp192r1" ? new chargy.elliptic.ec("p192") : new chargy.elliptic.ec("p256");
|
|
11525
|
+
const verified = ec.keyFromPublic("04" + publicKey, "hex").verify(hashValue.toUpperCase(), rawSignatureToRS(signature));
|
|
11526
|
+
return verified ? "ValidSignature" /* ValidSignature */ : "InvalidSignature" /* InvalidSignature */;
|
|
11527
|
+
} catch {
|
|
11528
|
+
return "InvalidSignature" /* InvalidSignature */;
|
|
11529
|
+
}
|
|
11530
|
+
}
|
|
11531
|
+
function rawSignatureToRS(signature) {
|
|
11532
|
+
const signatureHex = bytesToHex2(signature);
|
|
11533
|
+
const half = signatureHex.length / 2;
|
|
11534
|
+
return {
|
|
11535
|
+
algorithm: "ECC" /* ECC */,
|
|
11536
|
+
format: "RS" /* RS */,
|
|
11537
|
+
value: signatureHex,
|
|
11538
|
+
r: signatureHex.substring(0, half),
|
|
11539
|
+
s: signatureHex.substring(half)
|
|
11540
|
+
};
|
|
11541
|
+
}
|
|
11542
|
+
function scaledWhToKWh(valueWh, scaler) {
|
|
11543
|
+
return new Decimal(valueWh.toString()).mul(new Decimal(10).pow(scaler)).div(1e3);
|
|
11544
|
+
}
|
|
11545
|
+
function timeBytes(entry) {
|
|
11546
|
+
if (entry.valTime == null)
|
|
11547
|
+
throw new EDL40ValidationError("MISSING_FIELD", "EDL40/ISA: missing valTime");
|
|
11548
|
+
return reverseBytes(intToBytesBE(resolveSmlTime(entry.valTime).localEpoch >>> 0));
|
|
11549
|
+
}
|
|
11550
|
+
function valueAsLong(entry) {
|
|
11551
|
+
if (entry.value?.kind === "int" || entry.value?.kind === "uint")
|
|
11552
|
+
return entry.value.value;
|
|
11553
|
+
if (entry.value?.kind === "octet")
|
|
11554
|
+
return toSignedBigInt(entry.value.bytes);
|
|
11555
|
+
return 0n;
|
|
11556
|
+
}
|
|
11557
|
+
function requireEntry(res, obis, label) {
|
|
11558
|
+
const entry = findEntryByObis(res, obis);
|
|
11559
|
+
if (entry == null)
|
|
11560
|
+
throw new EDL40ValidationError("MISSING_FIELD", "ISA: missing " + label + " entry (OBIS " + obis + ")");
|
|
11561
|
+
return entry;
|
|
11562
|
+
}
|
|
11563
|
+
function status8(entry) {
|
|
11564
|
+
const value = entry.status;
|
|
11565
|
+
if (value != null && (value.kind === "uint" || value.kind === "int"))
|
|
11566
|
+
return longToBytesBE(BigInt.asUintN(64, value.value));
|
|
11567
|
+
return new Uint8Array(8);
|
|
11568
|
+
}
|
|
11569
|
+
function deepFirstInt(value) {
|
|
11570
|
+
if (value == null)
|
|
11571
|
+
return null;
|
|
11572
|
+
if (value.kind === "uint" || value.kind === "int")
|
|
11573
|
+
return value.value;
|
|
11574
|
+
if (value.kind === "list")
|
|
11575
|
+
for (let i = value.items.length - 1; i >= 0; i--) {
|
|
11576
|
+
const result = deepFirstInt(value.items[i]);
|
|
11577
|
+
if (result != null)
|
|
11578
|
+
return result;
|
|
11579
|
+
}
|
|
11580
|
+
return null;
|
|
11581
|
+
}
|
|
11582
|
+
function octet(value) {
|
|
11583
|
+
return value?.kind === "octet" ? value.bytes : null;
|
|
11584
|
+
}
|
|
11585
|
+
function num(value) {
|
|
11586
|
+
if (value?.kind === "uint" || value?.kind === "int")
|
|
11587
|
+
return Number(value.value);
|
|
11588
|
+
return null;
|
|
11589
|
+
}
|
|
11590
|
+
function asNumber2(value) {
|
|
11591
|
+
if (value?.kind === "uint" || value?.kind === "int")
|
|
11592
|
+
return Number(value.value);
|
|
11593
|
+
return 0;
|
|
11594
|
+
}
|
|
11595
|
+
function intToBytesBE(value) {
|
|
11596
|
+
return Uint8Array.from([
|
|
11597
|
+
value >>> 24 & 255,
|
|
11598
|
+
value >>> 16 & 255,
|
|
11599
|
+
value >>> 8 & 255,
|
|
11600
|
+
value & 255
|
|
11601
|
+
]);
|
|
11602
|
+
}
|
|
11603
|
+
function longToBytesBE(value) {
|
|
11604
|
+
const out = new Uint8Array(8);
|
|
11605
|
+
let v = BigInt.asUintN(64, value);
|
|
11606
|
+
for (let i = 7; i >= 0; i--) {
|
|
11607
|
+
out[i] = Number(v & 0xffn);
|
|
11608
|
+
v >>= 8n;
|
|
11609
|
+
}
|
|
11610
|
+
return out;
|
|
11611
|
+
}
|
|
11612
|
+
function reverseBytes(bytes) {
|
|
11613
|
+
const out = new Uint8Array(bytes.length);
|
|
11614
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
11615
|
+
const byte = bytes[i];
|
|
11616
|
+
if (byte !== void 0)
|
|
11617
|
+
out[bytes.length - 1 - i] = byte;
|
|
11618
|
+
}
|
|
11619
|
+
return out;
|
|
11620
|
+
}
|
|
11621
|
+
function toUnsignedBigInt(bytes) {
|
|
11622
|
+
let value = 0n;
|
|
11623
|
+
for (const byte of bytes)
|
|
11624
|
+
value = value << 8n | BigInt(byte);
|
|
11625
|
+
return value;
|
|
11626
|
+
}
|
|
11627
|
+
function toSignedBigInt(bytes) {
|
|
11628
|
+
if (bytes.length === 0)
|
|
11629
|
+
return 0n;
|
|
11630
|
+
let value = toUnsignedBigInt(bytes);
|
|
11631
|
+
const bits = BigInt(bytes.length * 8);
|
|
11632
|
+
const signBit = 1n << bits - 1n;
|
|
11633
|
+
if (value & signBit)
|
|
11634
|
+
value -= 1n << bits;
|
|
11635
|
+
return value;
|
|
11636
|
+
}
|
|
11637
|
+
function trimPaddingAtEnd(bytes) {
|
|
11638
|
+
let end = bytes.length;
|
|
11639
|
+
while (end > 0 && bytes[end - 1] === 0)
|
|
11640
|
+
end--;
|
|
11641
|
+
return bytes.subarray(0, end);
|
|
11642
|
+
}
|
|
11643
|
+
function indexOfSeq(haystack, needle) {
|
|
11644
|
+
outer: for (let i = 0; i + needle.length <= haystack.length; i++) {
|
|
11645
|
+
for (let j = 0; j < needle.length; j++)
|
|
11646
|
+
if (haystack[i + j] !== needle[j])
|
|
11647
|
+
continue outer;
|
|
11648
|
+
return i;
|
|
11649
|
+
}
|
|
11650
|
+
return -1;
|
|
11651
|
+
}
|
|
11652
|
+
function matchSeq(buf, pos, seq) {
|
|
11653
|
+
if (pos + seq.length > buf.length)
|
|
11654
|
+
return false;
|
|
11655
|
+
for (let i = 0; i < seq.length; i++)
|
|
11656
|
+
if (buf[pos + i] !== seq[i])
|
|
11657
|
+
return false;
|
|
11658
|
+
return true;
|
|
11659
|
+
}
|
|
11660
|
+
function bytesToHex2(bytes) {
|
|
11661
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
11662
|
+
}
|
|
11663
|
+
function byteAt(bytes, index) {
|
|
11664
|
+
const byte = bytes[index];
|
|
11665
|
+
if (byte === void 0)
|
|
11666
|
+
throw new EDL40ValidationError("SML_INCOMPLETE", "Unexpected end of SML data at " + index.toString());
|
|
11667
|
+
return byte;
|
|
11668
|
+
}
|
|
11669
|
+
|
|
10626
11670
|
// src/interfaces/CryptoUtils.ts
|
|
10627
11671
|
var import_elliptic = __toESM(require_elliptic());
|
|
10628
11672
|
var JSONSignatureVerificationStatus = /* @__PURE__ */ ((JSONSignatureVerificationStatus2) => {
|
|
@@ -11384,117 +12428,6 @@ var GDFCrypt01 = class extends ACrypt {
|
|
|
11384
12428
|
return void 0;
|
|
11385
12429
|
}
|
|
11386
12430
|
};
|
|
11387
|
-
|
|
11388
|
-
// src/interfaces/IPublicKeyInfo.ts
|
|
11389
|
-
var IPublicKeyInfo_exports = {};
|
|
11390
|
-
__export(IPublicKeyInfo_exports, {
|
|
11391
|
-
IsAPublicKey: () => IsAPublicKey,
|
|
11392
|
-
IsAPublicKeyLookup: () => IsAPublicKeyLookup,
|
|
11393
|
-
IsAPublicKeySignature: () => IsAPublicKeySignature,
|
|
11394
|
-
IsAPublicKeyXY: () => IsAPublicKeyXY,
|
|
11395
|
-
PublicKeyFormats: () => PublicKeyFormats,
|
|
11396
|
-
isPublicKeySubject: () => isPublicKeySubject
|
|
11397
|
-
});
|
|
11398
|
-
var PublicKeyFormats = /* @__PURE__ */ ((PublicKeyFormats2) => {
|
|
11399
|
-
PublicKeyFormats2["DER"] = "DER";
|
|
11400
|
-
PublicKeyFormats2["XY"] = "XY";
|
|
11401
|
-
return PublicKeyFormats2;
|
|
11402
|
-
})(PublicKeyFormats || {});
|
|
11403
|
-
function IsAPublicKeyLookup(data) {
|
|
11404
|
-
if (!isMandatoryJSONObject(data))
|
|
11405
|
-
return false;
|
|
11406
|
-
return Array.isArray(data["publicKeys"]);
|
|
11407
|
-
}
|
|
11408
|
-
function IsAPublicKey(data) {
|
|
11409
|
-
if (!isMandatoryJSONObject(data))
|
|
11410
|
-
return false;
|
|
11411
|
-
if (data["@context"] !== void 0 && !isStringOrStringArray(data["@context"])) {
|
|
11412
|
-
return false;
|
|
11413
|
-
}
|
|
11414
|
-
if (!isPublicKeySubject(data["subject"]))
|
|
11415
|
-
return false;
|
|
11416
|
-
if (data["value"] !== void 0 && !isString(data["value"])) {
|
|
11417
|
-
return false;
|
|
11418
|
-
}
|
|
11419
|
-
if (data["value"] === void 0 && (data["x"] === void 0 || data["y"] === void 0)) {
|
|
11420
|
-
return false;
|
|
11421
|
-
}
|
|
11422
|
-
if (data["value"] !== void 0 && !isStringOrOIDInfo(data["algorithm"])) {
|
|
11423
|
-
return false;
|
|
11424
|
-
}
|
|
11425
|
-
if (data["certainty"] !== void 0 && (typeof data["certainty"] !== "number" || !Number.isFinite(data["certainty"]))) {
|
|
11426
|
-
return false;
|
|
11427
|
-
}
|
|
11428
|
-
if (data["type"] !== void 0 && !isStringOrOIDInfo(data["type"])) {
|
|
11429
|
-
return false;
|
|
11430
|
-
}
|
|
11431
|
-
if (data["encoding"] !== void 0 && typeof data["encoding"] !== "string") {
|
|
11432
|
-
return false;
|
|
11433
|
-
}
|
|
11434
|
-
if (data["signatures"] !== void 0 && (!Array.isArray(data["signatures"]) || !data["signatures"].every(IsAPublicKeySignature))) {
|
|
11435
|
-
return false;
|
|
11436
|
-
}
|
|
11437
|
-
return true;
|
|
11438
|
-
}
|
|
11439
|
-
function isPublicKeySubject(data) {
|
|
11440
|
-
if (data === void 0)
|
|
11441
|
-
return true;
|
|
11442
|
-
if (isStringOrStringArray(data))
|
|
11443
|
-
return true;
|
|
11444
|
-
if (!isMandatoryJSONObject(data))
|
|
11445
|
-
return false;
|
|
11446
|
-
return Object.values(data).every(
|
|
11447
|
-
(value) => typeof value === "string" || isStringOrStringArray(value)
|
|
11448
|
-
);
|
|
11449
|
-
}
|
|
11450
|
-
function IsAPublicKeySignature(data) {
|
|
11451
|
-
if (!isMandatoryJSONObject(data))
|
|
11452
|
-
return false;
|
|
11453
|
-
if (!isOptionalString(data["@id"]))
|
|
11454
|
-
return false;
|
|
11455
|
-
if (data["@context"] !== void 0 && !isStringOrStringArray(data["@context"]))
|
|
11456
|
-
return false;
|
|
11457
|
-
if (!isOptionalStringOrOIDInfo(data["algorithm"]))
|
|
11458
|
-
return false;
|
|
11459
|
-
if (!isOptionalString(data["format"]))
|
|
11460
|
-
return false;
|
|
11461
|
-
if (!isOptionalString(data["encoding"]))
|
|
11462
|
-
return false;
|
|
11463
|
-
if (data["value"] !== void 0 && !isString(data["value"]))
|
|
11464
|
-
return false;
|
|
11465
|
-
if (data["publicKey"] !== void 0 && !isEncodedValue(data["publicKey"]))
|
|
11466
|
-
return false;
|
|
11467
|
-
if (data["signature"] !== void 0 && !isEncodedValue(data["signature"]))
|
|
11468
|
-
return false;
|
|
11469
|
-
if (!isOptionalString(data["timestamp"]))
|
|
11470
|
-
return false;
|
|
11471
|
-
if (!isOptionalString(data["issuer"]))
|
|
11472
|
-
return false;
|
|
11473
|
-
if (!isOptionalString(data["signer"]))
|
|
11474
|
-
return false;
|
|
11475
|
-
if (!isOptionalString(data["notBefore"]))
|
|
11476
|
-
return false;
|
|
11477
|
-
if (!isOptionalString(data["notAfter"]))
|
|
11478
|
-
return false;
|
|
11479
|
-
if (!isOptionalStringArray(data["keyUsage"]))
|
|
11480
|
-
return false;
|
|
11481
|
-
if (data["operations"] !== void 0 && !isMandatoryJSONObject(data["operations"]))
|
|
11482
|
-
return false;
|
|
11483
|
-
if (data["comment"] !== void 0 && !isMandatoryJSONObject(data["comment"]))
|
|
11484
|
-
return false;
|
|
11485
|
-
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;
|
|
11486
|
-
}
|
|
11487
|
-
function IsAPublicKeyXY(data) {
|
|
11488
|
-
if (!IsAPublicKey(data))
|
|
11489
|
-
return false;
|
|
11490
|
-
if (!isString(data["x"])) {
|
|
11491
|
-
return false;
|
|
11492
|
-
}
|
|
11493
|
-
if (!isString(data["y"])) {
|
|
11494
|
-
return false;
|
|
11495
|
-
}
|
|
11496
|
-
return true;
|
|
11497
|
-
}
|
|
11498
12431
|
var MENNEKES_EDL40_XMLNS = "http://www.mennekes.de/Mennekes.EdlVerification.xsd";
|
|
11499
12432
|
var MENNEKES_EDL40_OBIS = "1-0:1.17.0*255";
|
|
11500
12433
|
var Mennekes = class {
|
|
@@ -11956,6 +12889,132 @@ function numberToBytesBE(value, length) {
|
|
|
11956
12889
|
}
|
|
11957
12890
|
return bytes;
|
|
11958
12891
|
}
|
|
12892
|
+
var OCMFBonnTariffParseError = class extends Error {
|
|
12893
|
+
tariffText;
|
|
12894
|
+
constructor(tariffText, message) {
|
|
12895
|
+
super(message);
|
|
12896
|
+
this.name = "OCMFBonnTariffParseError";
|
|
12897
|
+
this.tariffText = tariffText;
|
|
12898
|
+
}
|
|
12899
|
+
};
|
|
12900
|
+
function parseCents(value, tariffText, fieldName) {
|
|
12901
|
+
if (!/^(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/.test(value))
|
|
12902
|
+
throw new OCMFBonnTariffParseError(tariffText, `${fieldName} must be a non-negative decimal number`);
|
|
12903
|
+
const parsedValue = Number(value);
|
|
12904
|
+
if (!Number.isFinite(parsedValue))
|
|
12905
|
+
throw new OCMFBonnTariffParseError(tariffText, `${fieldName} is outside the supported numeric range`);
|
|
12906
|
+
return parsedValue;
|
|
12907
|
+
}
|
|
12908
|
+
function parseOCMFBonnTariffText(tariffText) {
|
|
12909
|
+
const fields = tariffText.split(";");
|
|
12910
|
+
const code = fields[0];
|
|
12911
|
+
if (fields[1] !== "EUR")
|
|
12912
|
+
throw new OCMFBonnTariffParseError(tariffText, "currency must be EUR");
|
|
12913
|
+
switch (code) {
|
|
12914
|
+
case "001":
|
|
12915
|
+
if (fields.length !== 6)
|
|
12916
|
+
throw new OCMFBonnTariffParseError(tariffText, "profile 001 must contain six fields");
|
|
12917
|
+
return {
|
|
12918
|
+
raw: tariffText,
|
|
12919
|
+
code,
|
|
12920
|
+
currency: "EUR",
|
|
12921
|
+
startFeeCents: parseCents(fields[2] ?? "", tariffText, "W"),
|
|
12922
|
+
energyFeeCentsPerKWh: parseCents(fields[3] ?? "", tariffText, "X"),
|
|
12923
|
+
blockingFeeCentsPerMinute: parseCents(fields[4] ?? "", tariffText, "Y"),
|
|
12924
|
+
blockingFeeStartMinute: parseCents(fields[5] ?? "", tariffText, "Z")
|
|
12925
|
+
};
|
|
12926
|
+
case "002":
|
|
12927
|
+
if (fields.length !== 5)
|
|
12928
|
+
throw new OCMFBonnTariffParseError(tariffText, "profile 002 must contain five fields");
|
|
12929
|
+
return {
|
|
12930
|
+
raw: tariffText,
|
|
12931
|
+
code,
|
|
12932
|
+
currency: "EUR",
|
|
12933
|
+
startFeeCents: parseCents(fields[2] ?? "", tariffText, "W"),
|
|
12934
|
+
energyFeeCentsPerKWh: parseCents(fields[3] ?? "", tariffText, "X"),
|
|
12935
|
+
blockingFeeCentsPerMinute: parseCents(fields[4] ?? "", tariffText, "Y"),
|
|
12936
|
+
blockingFeeStartsAfterCharging: true
|
|
12937
|
+
};
|
|
12938
|
+
case "003":
|
|
12939
|
+
if (fields.length !== 4)
|
|
12940
|
+
throw new OCMFBonnTariffParseError(tariffText, "profile 003 must contain four fields");
|
|
12941
|
+
return {
|
|
12942
|
+
raw: tariffText,
|
|
12943
|
+
code,
|
|
12944
|
+
currency: "EUR",
|
|
12945
|
+
startFeeCents: parseCents(fields[2] ?? "", tariffText, "W"),
|
|
12946
|
+
timeFeeCentsPerMinute: parseCents(fields[3] ?? "", tariffText, "X")
|
|
12947
|
+
};
|
|
12948
|
+
default:
|
|
12949
|
+
throw new OCMFBonnTariffParseError(tariffText, "unknown Bonn tariff profile");
|
|
12950
|
+
}
|
|
12951
|
+
}
|
|
12952
|
+
function tryParseOCMFBonnTariffText(tariffText) {
|
|
12953
|
+
try {
|
|
12954
|
+
return parseOCMFBonnTariffText(tariffText);
|
|
12955
|
+
} catch (error) {
|
|
12956
|
+
if (error instanceof OCMFBonnTariffParseError)
|
|
12957
|
+
return void 0;
|
|
12958
|
+
throw error;
|
|
12959
|
+
}
|
|
12960
|
+
}
|
|
12961
|
+
function priceComponent(type, price, stepSize) {
|
|
12962
|
+
return {
|
|
12963
|
+
type,
|
|
12964
|
+
price,
|
|
12965
|
+
step_size: stepSize
|
|
12966
|
+
};
|
|
12967
|
+
}
|
|
12968
|
+
function eurosFromCents(cents) {
|
|
12969
|
+
return new Decimal(cents).dividedBy(100);
|
|
12970
|
+
}
|
|
12971
|
+
function eurosPerHourFromCentsPerMinute(cents) {
|
|
12972
|
+
return eurosFromCents(cents).times(60);
|
|
12973
|
+
}
|
|
12974
|
+
function ocmfBonnTariffToChargingTariff(tariff) {
|
|
12975
|
+
const baseComponents = new Array(
|
|
12976
|
+
priceComponent("FLAT", eurosFromCents(tariff.startFeeCents), 1)
|
|
12977
|
+
);
|
|
12978
|
+
const elements = new Array();
|
|
12979
|
+
switch (tariff.code) {
|
|
12980
|
+
case "001":
|
|
12981
|
+
baseComponents.push(priceComponent("ENERGY", eurosFromCents(tariff.energyFeeCentsPerKWh), 1));
|
|
12982
|
+
elements.push(
|
|
12983
|
+
{ price_components: baseComponents },
|
|
12984
|
+
{
|
|
12985
|
+
price_components: [
|
|
12986
|
+
priceComponent("PARKING_TIME", eurosPerHourFromCentsPerMinute(tariff.blockingFeeCentsPerMinute), 60)
|
|
12987
|
+
],
|
|
12988
|
+
restrictions: {
|
|
12989
|
+
min_duration: tariff.blockingFeeStartMinute * 60
|
|
12990
|
+
}
|
|
12991
|
+
}
|
|
12992
|
+
);
|
|
12993
|
+
break;
|
|
12994
|
+
case "002":
|
|
12995
|
+
baseComponents.push(priceComponent("ENERGY", eurosFromCents(tariff.energyFeeCentsPerKWh), 1));
|
|
12996
|
+
elements.push(
|
|
12997
|
+
{ price_components: baseComponents },
|
|
12998
|
+
{
|
|
12999
|
+
price_components: [
|
|
13000
|
+
priceComponent("PARKING_TIME", eurosPerHourFromCentsPerMinute(tariff.blockingFeeCentsPerMinute), 60)
|
|
13001
|
+
]
|
|
13002
|
+
}
|
|
13003
|
+
);
|
|
13004
|
+
break;
|
|
13005
|
+
case "003":
|
|
13006
|
+
baseComponents.push(priceComponent("TIME", eurosPerHourFromCentsPerMinute(tariff.timeFeeCentsPerMinute), 60));
|
|
13007
|
+
elements.push({ price_components: baseComponents });
|
|
13008
|
+
break;
|
|
13009
|
+
}
|
|
13010
|
+
return {
|
|
13011
|
+
"@id": tariff.raw,
|
|
13012
|
+
currency: tariff.currency,
|
|
13013
|
+
elements
|
|
13014
|
+
};
|
|
13015
|
+
}
|
|
13016
|
+
|
|
13017
|
+
// src/OCMF.ts
|
|
11959
13018
|
var OCMFv1_x = class extends ACrypt {
|
|
11960
13019
|
curve = new this.chargy.elliptic.ec("p256");
|
|
11961
13020
|
constructor(chargy) {
|
|
@@ -12045,6 +13104,8 @@ var OCMFv1_x = class extends ACrypt {
|
|
|
12045
13104
|
return "Reading Current Type";
|
|
12046
13105
|
case "CL":
|
|
12047
13106
|
return "Cumulated Loss";
|
|
13107
|
+
case "EI":
|
|
13108
|
+
return "Error Index";
|
|
12048
13109
|
case "EF":
|
|
12049
13110
|
return "Error Flags";
|
|
12050
13111
|
case "ST":
|
|
@@ -12232,6 +13293,9 @@ var OCMF = class {
|
|
|
12232
13293
|
//#region (private) tryToParseOCMFv1_0(OCMFDataList, ContainerInfos?)
|
|
12233
13294
|
tryToParseOCMFv1_0(OCMFJSONDocuments, ContainerInfos) {
|
|
12234
13295
|
try {
|
|
13296
|
+
const containerChargingStation = ContainerInfos?.chargingStations?.[0];
|
|
13297
|
+
const containerEVSE = containerChargingStation?.EVSEs?.[0] ?? ContainerInfos?.EVSEs?.[0];
|
|
13298
|
+
const containerConnector = containerEVSE?.connectors?.[0] ?? ContainerInfos?.connectors?.[0];
|
|
12235
13299
|
const firstOCMDJSONDocument = getFirstArrayElement(OCMFJSONDocuments, "Missing first OCMF JSON document");
|
|
12236
13300
|
const formatVersion = firstOCMDJSONDocument.payload.FV;
|
|
12237
13301
|
const gatewayInformation = firstOCMDJSONDocument.payload.GI ?? firstOCMDJSONDocument.payload.VI;
|
|
@@ -12249,10 +13313,39 @@ var OCMF = class {
|
|
|
12249
13313
|
const identificationType = firstOCMDJSONDocument.payload.IT;
|
|
12250
13314
|
const identificationData = firstOCMDJSONDocument.payload.ID;
|
|
12251
13315
|
const tariffText = firstOCMDJSONDocument.payload.TT;
|
|
12252
|
-
const
|
|
13316
|
+
const tariffTextInterpretation = typeof tariffText === "string" ? tryParseOCMFBonnTariffText(tariffText) : void 0;
|
|
13317
|
+
const chargingTariff = typeof tariffText === "string" && tariffText.length > 0 ? tariffTextInterpretation !== void 0 ? ocmfBonnTariffToChargingTariff(tariffTextInterpretation) : { "@id": tariffText } : void 0;
|
|
13318
|
+
const controllerFirmwareVersion = firstOCMDJSONDocument.payload.CF;
|
|
12253
13319
|
const lossCompensation = firstOCMDJSONDocument.payload.LC;
|
|
13320
|
+
const signedCable = lossCompensation !== void 0 && typeof lossCompensation.LR === "number" && Number.isFinite(lossCompensation.LR) && typeof lossCompensation.LU === "string" && lossCompensation.LU.length > 0 ? {
|
|
13321
|
+
...typeof lossCompensation.LN === "string" ? { lossCompensation: lossCompensation.LN } : {},
|
|
13322
|
+
...typeof lossCompensation.LI === "number" ? { lossCompensationId: lossCompensation.LI.toString() } : {},
|
|
13323
|
+
resistance: lossCompensation.LR,
|
|
13324
|
+
resistanceUnit: lossCompensation.LU
|
|
13325
|
+
} : void 0;
|
|
12254
13326
|
const chargePointIdType = firstOCMDJSONDocument.payload.CT;
|
|
12255
13327
|
const chargePointId = firstOCMDJSONDocument.payload.CI;
|
|
13328
|
+
let signedChargingStationId;
|
|
13329
|
+
let signedEVSEId;
|
|
13330
|
+
let signedConnectorId;
|
|
13331
|
+
if (typeof chargePointId === "string" && chargePointId.trim().length > 0) {
|
|
13332
|
+
const normalizedChargePointId = chargePointId.trim();
|
|
13333
|
+
switch (chargePointIdType?.toUpperCase()) {
|
|
13334
|
+
case void 0:
|
|
13335
|
+
break;
|
|
13336
|
+
case "EVSEID":
|
|
13337
|
+
signedEVSEId = normalizedChargePointId;
|
|
13338
|
+
break;
|
|
13339
|
+
case "CBIDC": {
|
|
13340
|
+
const cbidcMatch = /^(\S+)\s+(\S+)$/.exec(normalizedChargePointId);
|
|
13341
|
+
if (cbidcMatch?.[1] !== void 0 && cbidcMatch[2] !== void 0) {
|
|
13342
|
+
signedChargingStationId = cbidcMatch[1];
|
|
13343
|
+
signedConnectorId = cbidcMatch[2];
|
|
13344
|
+
}
|
|
13345
|
+
break;
|
|
13346
|
+
}
|
|
13347
|
+
}
|
|
13348
|
+
}
|
|
12256
13349
|
if (isOptionalString(formatVersion) && isOptionalString(gatewayInformation) && isOptionalString(gatewaySerial) && isOptionalString(gatewayVersion) && isMandatoryString(paging) && isOptionalString(meterVendor) && isOptionalString(meterModel) && // OCMF 1.0 table 3 lists MS as 1..1, but the later "Relation of Serial Numbers,
|
|
12257
13350
|
// Charge Point and Public Key" section makes the serial-number fields conditionally
|
|
12258
13351
|
// mandatory. KEBA KCP30 records identify the signing gateway via GS and omit MS.
|
|
@@ -12265,7 +13358,7 @@ var OCMF = class {
|
|
|
12265
13358
|
// IT is 1..1 in the user-assignment table for transaction records. Some OCMF 1.0
|
|
12266
13359
|
// implementations omit it when no user is assigned (IS=false, ID empty). We tolerate
|
|
12267
13360
|
// this vendor compatibility case instead of rejecting otherwise valid signatures.
|
|
12268
|
-
isOptionalString(identificationType) && isOptionalString(identificationData) && isOptionalString(tariffText) && isOptionalString(
|
|
13361
|
+
isOptionalString(identificationType) && isOptionalString(identificationData) && isOptionalString(tariffText) && isOptionalString(controllerFirmwareVersion) && isOptionalJSONObject(lossCompensation) && isOptionalString(chargePointIdType) && isOptionalString(chargePointId)) {
|
|
12269
13362
|
const paginationPrefix = paging.length > 0 ? paging.charAt(0).toLowerCase() : null;
|
|
12270
13363
|
const transactionType = paginationPrefix === "t" ? "transaction" /* transaction */ : paginationPrefix === "f" ? "fiscal" /* fiscal */ : "undefined" /* undefined */;
|
|
12271
13364
|
const pagination = paging.length > 1 ? parseNumber(paging.substring(1)) : null;
|
|
@@ -12297,11 +13390,22 @@ var OCMF = class {
|
|
|
12297
13390
|
"@id": identificationData ?? "?",
|
|
12298
13391
|
"type": identificationType ?? "?"
|
|
12299
13392
|
},
|
|
13393
|
+
"chargingTariffs": chargingTariff !== void 0 ? [chargingTariff] : void 0,
|
|
12300
13394
|
"ocmf": {
|
|
12301
13395
|
"formatVersion": formatVersion,
|
|
12302
13396
|
"gatewayInformation": gatewayInformation,
|
|
12303
13397
|
"gatewaySerial": gatewaySerial,
|
|
12304
|
-
"gatewayVersion": gatewayVersion
|
|
13398
|
+
"gatewayVersion": gatewayVersion,
|
|
13399
|
+
"meterVendor": meterVendor,
|
|
13400
|
+
"meterModel": meterModel,
|
|
13401
|
+
"meterSerial": meterSerial,
|
|
13402
|
+
"meterFirmware": meterFirmware,
|
|
13403
|
+
"tariffText": tariffText,
|
|
13404
|
+
"tariffTextInterpretation": tariffTextInterpretation,
|
|
13405
|
+
"controllerFirmwareVersion": controllerFirmwareVersion,
|
|
13406
|
+
"lossCompensation": lossCompensation,
|
|
13407
|
+
"chargePointIdentificationType": chargePointIdType,
|
|
13408
|
+
"chargePointIdentification": chargePointId
|
|
12305
13409
|
},
|
|
12306
13410
|
// "chargingStationOperators": [{
|
|
12307
13411
|
// "chargingPools": [{
|
|
@@ -12368,7 +13472,11 @@ var OCMF = class {
|
|
|
12368
13472
|
"@context": "https://open.charging.cloud/contexts/SessionSignatureFormats/OCMFv1.0+json",
|
|
12369
13473
|
"begin": "?",
|
|
12370
13474
|
"end": "?",
|
|
12371
|
-
|
|
13475
|
+
"chargingStationId": signedChargingStationId,
|
|
13476
|
+
"EVSEId": signedEVSEId,
|
|
13477
|
+
"ConnectorId": signedConnectorId,
|
|
13478
|
+
"tariffId": chargingTariff?.["@id"],
|
|
13479
|
+
"chargingTariffs": chargingTariff !== void 0 ? [chargingTariff] : void 0,
|
|
12372
13480
|
"authorizationStart": {
|
|
12373
13481
|
"@id": identificationData ?? "?",
|
|
12374
13482
|
"type": identificationType ?? "?",
|
|
@@ -12381,8 +13489,51 @@ var OCMF = class {
|
|
|
12381
13489
|
}],
|
|
12382
13490
|
"certainty": 1
|
|
12383
13491
|
};
|
|
12384
|
-
|
|
13492
|
+
const resolvedChargingStationId = signedChargingStationId ?? containerChargingStation?.["@id"];
|
|
13493
|
+
if (resolvedChargingStationId !== void 0) {
|
|
13494
|
+
const matchingContainerStation = containerChargingStation?.["@id"] === resolvedChargingStationId ? containerChargingStation : void 0;
|
|
13495
|
+
const resolvedChargingStation = {
|
|
13496
|
+
...matchingContainerStation ?? { "@id": resolvedChargingStationId },
|
|
13497
|
+
...controllerFirmwareVersion !== void 0 ? {
|
|
13498
|
+
firmware: {
|
|
13499
|
+
...matchingContainerStation?.firmware,
|
|
13500
|
+
version: controllerFirmwareVersion
|
|
13501
|
+
}
|
|
13502
|
+
} : {}
|
|
13503
|
+
};
|
|
13504
|
+
CTR.chargingStations = [
|
|
13505
|
+
resolvedChargingStation,
|
|
13506
|
+
...ContainerInfos?.chargingStations?.filter((station) => station["@id"] !== resolvedChargingStationId) ?? []
|
|
13507
|
+
];
|
|
13508
|
+
if (CTR.chargingSessions?.[0] !== void 0) {
|
|
13509
|
+
CTR.chargingSessions[0].chargingStationId ??= resolvedChargingStationId;
|
|
13510
|
+
CTR.chargingSessions[0].chargingStation = resolvedChargingStation;
|
|
13511
|
+
}
|
|
13512
|
+
} else if (ContainerInfos?.chargingStations !== void 0)
|
|
12385
13513
|
CTR.chargingStations = ContainerInfos.chargingStations;
|
|
13514
|
+
if (containerEVSE !== void 0 && CTR.chargingSessions?.[0] !== void 0) {
|
|
13515
|
+
const chargingSession = CTR.chargingSessions[0];
|
|
13516
|
+
chargingSession.EVSEId ??= containerEVSE["@id"];
|
|
13517
|
+
if (chargingSession.EVSEId === containerEVSE["@id"])
|
|
13518
|
+
chargingSession.EVSE = containerEVSE;
|
|
13519
|
+
}
|
|
13520
|
+
const resolvedConnectorId = signedConnectorId ?? containerConnector?.["@id"];
|
|
13521
|
+
if ((resolvedConnectorId !== void 0 || signedCable !== void 0) && CTR.chargingSessions?.[0] !== void 0) {
|
|
13522
|
+
const matchingContainerConnector = containerConnector?.["@id"] === resolvedConnectorId ? containerConnector : void 0;
|
|
13523
|
+
const resolvedConnector = {
|
|
13524
|
+
...matchingContainerConnector,
|
|
13525
|
+
...resolvedConnectorId !== void 0 ? { "@id": resolvedConnectorId } : {},
|
|
13526
|
+
...signedCable !== void 0 ? {
|
|
13527
|
+
cable: {
|
|
13528
|
+
...matchingContainerConnector?.cable,
|
|
13529
|
+
...signedCable
|
|
13530
|
+
}
|
|
13531
|
+
} : {}
|
|
13532
|
+
};
|
|
13533
|
+
const chargingSession = CTR.chargingSessions[0];
|
|
13534
|
+
chargingSession.ConnectorId ??= resolvedConnectorId;
|
|
13535
|
+
chargingSession.Connector = resolvedConnector;
|
|
13536
|
+
}
|
|
12386
13537
|
const measurementsByKey = /* @__PURE__ */ new Map();
|
|
12387
13538
|
for (const ocmfJSONDocument of OCMFJSONDocuments) {
|
|
12388
13539
|
let inheritedReading = {};
|
|
@@ -12395,12 +13546,13 @@ var OCMF = class {
|
|
|
12395
13546
|
const readingUnit = effectiveReading.RU;
|
|
12396
13547
|
const readingCurrentType = effectiveReading.RT;
|
|
12397
13548
|
const cumulatedLoss = effectiveReading.CL;
|
|
13549
|
+
const errorIndex = effectiveReading.EI;
|
|
12398
13550
|
const errorFlags = effectiveReading.EF;
|
|
12399
13551
|
const status = effectiveReading.ST;
|
|
12400
13552
|
inheritedReading = effectiveReading;
|
|
12401
13553
|
if (isMandatoryString(time) && isOptionalString(transaction) && isMandatoryDecimal(readingValue) && // Note: Some vendors use a JSON string here!
|
|
12402
13554
|
isOptionalString(readingIdentification) && isMandatoryString(readingUnit) && isOptionalString(readingCurrentType) && // chargyLib.isOptionalDecimal (cumulatedLoss) &&
|
|
12403
|
-
isOptionalString(errorFlags) && isMandatoryString(status)) {
|
|
13555
|
+
isOptionalNumber(errorIndex) && isOptionalString(errorFlags) && isMandatoryString(status)) {
|
|
12404
13556
|
const timeSplit = time.split(" ");
|
|
12405
13557
|
if (timeSplit.length != 2) return {
|
|
12406
13558
|
status: "InvalidSessionFormat" /* InvalidSessionFormat */,
|
|
@@ -12499,6 +13651,7 @@ var OCMF = class {
|
|
|
12499
13651
|
// "T" ToDo: Serialize this to a string!
|
|
12500
13652
|
"pagination": pagination,
|
|
12501
13653
|
// "9289"
|
|
13654
|
+
"errorIndex": errorIndex,
|
|
12502
13655
|
"errorFlags": errorFlags,
|
|
12503
13656
|
// ""
|
|
12504
13657
|
"cumulatedLoss": cumulatedLoss != null && cumulatedLoss !== 0 ? new Decimal(cumulatedLoss) : void 0,
|
|
@@ -12515,10 +13668,8 @@ var OCMF = class {
|
|
|
12515
13668
|
}
|
|
12516
13669
|
}
|
|
12517
13670
|
}
|
|
12518
|
-
if (ContainerInfos?.chargingStations !== void 0)
|
|
12519
|
-
CTR.chargingStations = ContainerInfos.chargingStations;
|
|
12520
13671
|
if (ContainerInfos?.warnings !== void 0)
|
|
12521
|
-
CTR.warnings =
|
|
13672
|
+
CTR.warnings = (CTR.warnings ?? []).concat(ContainerInfos.warnings);
|
|
12522
13673
|
CTR.status = OCMFJSONDocuments.every((ocmfJSONDocument) => ocmfJSONDocument.validationStatus === "ValidSignature" /* ValidSignature */) ? "ValidSignature" /* ValidSignature */ : "InvalidSignature" /* InvalidSignature */;
|
|
12523
13674
|
if (CTR.chargingSessions != null && CTR.chargingSessions.length > 0 && CTR.chargingSessions[0]) {
|
|
12524
13675
|
CTR.begin = CTR.chargingSessions[0].begin;
|
|
@@ -13013,6 +14164,11 @@ var OCMF = class {
|
|
|
13013
14164
|
}
|
|
13014
14165
|
if (ocmfJSONDocumentGroup[0]) {
|
|
13015
14166
|
switch (ocmfJSONDocumentGroup[0].payload.FV) {
|
|
14167
|
+
// FV has cardinality 0..1 in OCMF. All supported 1.x
|
|
14168
|
+
// versions use the same parser, so an omitted version
|
|
14169
|
+
// is parsed as generic OCMF without changing the
|
|
14170
|
+
// signed payload or inventing a concrete version.
|
|
14171
|
+
case void 0:
|
|
13016
14172
|
case "0.1":
|
|
13017
14173
|
// OCMF 0.1 SAFE reference data uses a few legacy field names/forms (VI/VV,
|
|
13018
14174
|
// string based IS values), but the compact signed document structure is close
|
|
@@ -14034,6 +15190,184 @@ function readDERInteger(bytes, getOffset, setOffset) {
|
|
|
14034
15190
|
return hex;
|
|
14035
15191
|
}
|
|
14036
15192
|
|
|
15193
|
+
// src/PTBContainer.ts
|
|
15194
|
+
var base64RegExp = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
15195
|
+
var formatVersionRegExp = /^1(?:\.[0-9]+)?$/;
|
|
15196
|
+
var PTB = class {
|
|
15197
|
+
chargy;
|
|
15198
|
+
constructor(chargy) {
|
|
15199
|
+
this.chargy = chargy;
|
|
15200
|
+
}
|
|
15201
|
+
async TryToParsePTBContainer(container) {
|
|
15202
|
+
const validation = this.validateContainer(container);
|
|
15203
|
+
if (!validation.valid)
|
|
15204
|
+
return this.validationError(validation.issues);
|
|
15205
|
+
const ptbContainer = validation.container;
|
|
15206
|
+
const containerInfos = {
|
|
15207
|
+
chargingStations: [{
|
|
15208
|
+
"@id": ptbContainer.chargeboxIdentifier,
|
|
15209
|
+
address: this.normalizeAddress(ptbContainer.address),
|
|
15210
|
+
geoLocation: {
|
|
15211
|
+
lat: ptbContainer.geoLocation.lat,
|
|
15212
|
+
lng: ptbContainer.geoLocation.lng
|
|
15213
|
+
},
|
|
15214
|
+
EVSEs: [{
|
|
15215
|
+
"@id": ptbContainer.chargeboxIdentifier
|
|
15216
|
+
}]
|
|
15217
|
+
}]
|
|
15218
|
+
};
|
|
15219
|
+
return new OCMF(this.chargy).TryToParseOCMFDocuments(
|
|
15220
|
+
[ptbContainer.ocmfBegin, ptbContainer.ocmfEnd],
|
|
15221
|
+
ptbContainer.publicKey,
|
|
15222
|
+
"base64",
|
|
15223
|
+
containerInfos
|
|
15224
|
+
);
|
|
15225
|
+
}
|
|
15226
|
+
validateContainer(container) {
|
|
15227
|
+
const issues = [];
|
|
15228
|
+
if (!isMandatoryJSONObject(container))
|
|
15229
|
+
return {
|
|
15230
|
+
valid: false,
|
|
15231
|
+
issues: [{
|
|
15232
|
+
path: "$",
|
|
15233
|
+
message: "must be an object"
|
|
15234
|
+
}]
|
|
15235
|
+
};
|
|
15236
|
+
this.requireConstantString(container, "format", "ptb", issues);
|
|
15237
|
+
this.requireString(container, "publicKey", issues);
|
|
15238
|
+
this.requireString(container, "chargeboxIdentifier", issues);
|
|
15239
|
+
this.requireString(container, "ocmfBegin", issues);
|
|
15240
|
+
this.requireString(container, "ocmfEnd", issues);
|
|
15241
|
+
const formatVersion = container["formatVersion"];
|
|
15242
|
+
if (formatVersion !== void 0 && (typeof formatVersion !== "string" || !formatVersionRegExp.test(formatVersion))) {
|
|
15243
|
+
issues.push({
|
|
15244
|
+
path: "$.formatVersion",
|
|
15245
|
+
message: "must match ^1(?:\\.[0-9]+)?$"
|
|
15246
|
+
});
|
|
15247
|
+
}
|
|
15248
|
+
const publicKey = container["publicKey"];
|
|
15249
|
+
if (typeof publicKey === "string" && publicKey.length > 0 && !base64RegExp.test(publicKey))
|
|
15250
|
+
issues.push({
|
|
15251
|
+
path: "$.publicKey",
|
|
15252
|
+
message: "must be a base64 encoded string"
|
|
15253
|
+
});
|
|
15254
|
+
for (const propertyName of ["ocmfBegin", "ocmfEnd"]) {
|
|
15255
|
+
const ocmfDocument = container[propertyName];
|
|
15256
|
+
if (typeof ocmfDocument === "string" && (ocmfDocument.length < 10 || !ocmfDocument.startsWith("OCMF|"))) {
|
|
15257
|
+
issues.push({
|
|
15258
|
+
path: "$." + propertyName,
|
|
15259
|
+
message: "must be an unmodified OCMF record beginning with OCMF|"
|
|
15260
|
+
});
|
|
15261
|
+
}
|
|
15262
|
+
}
|
|
15263
|
+
const address = container["address"];
|
|
15264
|
+
if (!isMandatoryJSONObject(address))
|
|
15265
|
+
issues.push({
|
|
15266
|
+
path: "$.address",
|
|
15267
|
+
message: "must be an object"
|
|
15268
|
+
});
|
|
15269
|
+
else
|
|
15270
|
+
this.validateAddress(address, issues);
|
|
15271
|
+
const geoLocation = container["geoLocation"];
|
|
15272
|
+
if (!isMandatoryJSONObject(geoLocation))
|
|
15273
|
+
issues.push({
|
|
15274
|
+
path: "$.geoLocation",
|
|
15275
|
+
message: "must be an object"
|
|
15276
|
+
});
|
|
15277
|
+
else
|
|
15278
|
+
this.validateGeoLocation(geoLocation, issues);
|
|
15279
|
+
if (issues.length > 0)
|
|
15280
|
+
return {
|
|
15281
|
+
valid: false,
|
|
15282
|
+
issues
|
|
15283
|
+
};
|
|
15284
|
+
return {
|
|
15285
|
+
valid: true,
|
|
15286
|
+
container
|
|
15287
|
+
};
|
|
15288
|
+
}
|
|
15289
|
+
validateAddress(address, issues) {
|
|
15290
|
+
this.requireString(address, "street", issues, "$.address");
|
|
15291
|
+
for (const propertyName of ["houseNumber", "zipCode", "postalCode", "town", "city", "country"]) {
|
|
15292
|
+
const propertyValue = address[propertyName];
|
|
15293
|
+
if (propertyValue !== void 0 && typeof propertyValue !== "string")
|
|
15294
|
+
issues.push({
|
|
15295
|
+
path: "$.address." + propertyName,
|
|
15296
|
+
message: "must be a string"
|
|
15297
|
+
});
|
|
15298
|
+
else if ((propertyName === "town" || propertyName === "city") && propertyValue === "")
|
|
15299
|
+
issues.push({
|
|
15300
|
+
path: "$.address." + propertyName,
|
|
15301
|
+
message: "must be a non-empty string"
|
|
15302
|
+
});
|
|
15303
|
+
}
|
|
15304
|
+
const town = address["town"];
|
|
15305
|
+
const city = address["city"];
|
|
15306
|
+
if ((typeof town !== "string" || town.length === 0) && (typeof city !== "string" || city.length === 0)) {
|
|
15307
|
+
issues.push({
|
|
15308
|
+
path: "$.address",
|
|
15309
|
+
message: "must contain a non-empty town or city"
|
|
15310
|
+
});
|
|
15311
|
+
}
|
|
15312
|
+
}
|
|
15313
|
+
validateGeoLocation(geoLocation, issues) {
|
|
15314
|
+
const latitude = geoLocation["lat"];
|
|
15315
|
+
const longitude = geoLocation["lng"];
|
|
15316
|
+
if (typeof latitude !== "number" || !Number.isFinite(latitude) || latitude < -90 || latitude > 90)
|
|
15317
|
+
issues.push({
|
|
15318
|
+
path: "$.geoLocation.lat",
|
|
15319
|
+
message: "must be a number between -90 and 90"
|
|
15320
|
+
});
|
|
15321
|
+
if (typeof longitude !== "number" || !Number.isFinite(longitude) || longitude < -180 || longitude > 180)
|
|
15322
|
+
issues.push({
|
|
15323
|
+
path: "$.geoLocation.lng",
|
|
15324
|
+
message: "must be a number between -180 and 180"
|
|
15325
|
+
});
|
|
15326
|
+
for (const propertyName of Object.keys(geoLocation))
|
|
15327
|
+
if (propertyName !== "lat" && propertyName !== "lng")
|
|
15328
|
+
issues.push({
|
|
15329
|
+
path: "$.geoLocation." + propertyName,
|
|
15330
|
+
message: "is not allowed"
|
|
15331
|
+
});
|
|
15332
|
+
}
|
|
15333
|
+
requireString(json, propertyName, issues, parentPath = "$") {
|
|
15334
|
+
const value = json[propertyName];
|
|
15335
|
+
if (typeof value !== "string" || value.length === 0)
|
|
15336
|
+
issues.push({
|
|
15337
|
+
path: parentPath + "." + propertyName,
|
|
15338
|
+
message: "must be a non-empty string"
|
|
15339
|
+
});
|
|
15340
|
+
}
|
|
15341
|
+
requireConstantString(json, propertyName, expectedValue, issues) {
|
|
15342
|
+
if (json[propertyName] !== expectedValue)
|
|
15343
|
+
issues.push({
|
|
15344
|
+
path: "$." + propertyName,
|
|
15345
|
+
message: "must equal " + expectedValue
|
|
15346
|
+
});
|
|
15347
|
+
}
|
|
15348
|
+
normalizeAddress(address) {
|
|
15349
|
+
return {
|
|
15350
|
+
city: address.city ?? address.town,
|
|
15351
|
+
street: address.street,
|
|
15352
|
+
houseNumber: address.houseNumber,
|
|
15353
|
+
postalCode: address.postalCode ?? address.zipCode,
|
|
15354
|
+
country: address.country
|
|
15355
|
+
};
|
|
15356
|
+
}
|
|
15357
|
+
validationError(issues) {
|
|
15358
|
+
return {
|
|
15359
|
+
format: "ptb",
|
|
15360
|
+
status: "InvalidSessionFormat" /* InvalidSessionFormat */,
|
|
15361
|
+
message: this.chargy.GetMultilanguageText("Invalid PTB OCMF container!"),
|
|
15362
|
+
certainty: 1,
|
|
15363
|
+
issues,
|
|
15364
|
+
errors: issues.map((issue) => CreateError(
|
|
15365
|
+
this.chargy.GetMultilanguageText(issue.path + " " + issue.message)
|
|
15366
|
+
))
|
|
15367
|
+
};
|
|
15368
|
+
}
|
|
15369
|
+
};
|
|
15370
|
+
|
|
14037
15371
|
// src/SAFE_XML.ts
|
|
14038
15372
|
var SAFEXML = class _SAFEXML {
|
|
14039
15373
|
chargy;
|
|
@@ -14228,6 +15562,14 @@ var SAFEXML = class _SAFEXML {
|
|
|
14228
15562
|
commonPublicKeyEncoding,
|
|
14229
15563
|
safeXMLContext
|
|
14230
15564
|
);
|
|
15565
|
+
case "edl_40_p":
|
|
15566
|
+
case "isa_edl_40_p":
|
|
15567
|
+
case "sml_edl40_p":
|
|
15568
|
+
return await new EDL40(this.chargy).TryToParseEDL40Documents(
|
|
15569
|
+
signedDataValues,
|
|
15570
|
+
commonPublicKey,
|
|
15571
|
+
safeXMLContext
|
|
15572
|
+
);
|
|
14231
15573
|
default:
|
|
14232
15574
|
return {
|
|
14233
15575
|
status: "InvalidSessionFormat" /* InvalidSessionFormat */,
|
|
@@ -17252,7 +18594,9 @@ var Chargy = class {
|
|
|
17252
18594
|
if (IsAChargeTransparencyLiveLink(JSONContent)) {
|
|
17253
18595
|
JSONContent.timestamp ??= (/* @__PURE__ */ new Date()).toISOString();
|
|
17254
18596
|
processedFile.result = JSONContent;
|
|
17255
|
-
} else if (
|
|
18597
|
+
} else if (JSONContent["format"] === "ptb")
|
|
18598
|
+
processedFile.result = await new PTB(this).TryToParsePTBContainer(JSONContent);
|
|
18599
|
+
else if (isMandatoryString(JSONContext)) {
|
|
17256
18600
|
if (JSONContext.startsWith("https://open.charging.cloud/contexts/CTR+json"))
|
|
17257
18601
|
processedFile.result = JSONContent;
|
|
17258
18602
|
else if (JSONContext.startsWith("https://open.charging.cloud/contexts/publicKey+json"))
|
|
@@ -17628,6 +18972,10 @@ var Chargy = class {
|
|
|
17628
18972
|
chargingSession.method = new PCDFCrypt01(this);
|
|
17629
18973
|
verificationResult2 = await chargingSession.method.VerifyChargingSession(chargingSession);
|
|
17630
18974
|
break;
|
|
18975
|
+
case "https://open.charging.cloud/contexts/SessionSignatureFormats/EDL40+json":
|
|
18976
|
+
chargingSession.method = new EDL40Crypt01(this);
|
|
18977
|
+
verificationResult2 = await chargingSession.method.VerifyChargingSession(chargingSession);
|
|
18978
|
+
break;
|
|
17631
18979
|
case "https://open.charging.cloud/contexts/SessionSignatureFormats/bsm-ws36a-v0+json":
|
|
17632
18980
|
chargingSession.method = new BSMCrypt01(this);
|
|
17633
18981
|
verificationResult2 = await chargingSession.method.VerifyChargingSession(chargingSession);
|
|
@@ -17708,6 +19056,6 @@ var Chargy = class {
|
|
|
17708
19056
|
}
|
|
17709
19057
|
};
|
|
17710
19058
|
|
|
17711
|
-
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, 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 };
|
|
19059
|
+
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, OCMFBonnTariffParseError, OCMFTransactionTypes, OCMFv1_x, OCPI, OIDInfo, PCDF, PCDFCrypt01, PCDFParseError, PCDFValidationError, PCDF_FIELD_ORDER, PCDF_PREFIX, PTB, 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, ocmfBonnTariffToChargingTariff, openFullscreen, pad, parseAndVerifyJSONSignatures, parseDescription, parseEDL40, parseHexString, parseMennekesXMLDocument, parseNumber, parseOBIS, parseOCMFBonnTariffText, 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, tryParseOCMFBonnTariffText, unquotePCDFText, validatePCDFFields, verifyEDL40Document, verifyJSONMessageSignatureResults, verifyJSONMessageSignatures, verifyJSONSignature, verifyJSONSignatureResult, verifyPCDFDocument };
|
|
17712
19060
|
//# sourceMappingURL=index.js.map
|
|
17713
19061
|
//# sourceMappingURL=index.js.map
|