@it-enterprise/digital-signature 1.2.0 → 1.2.1

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.
@@ -1,5 +1,5 @@
1
1
  import { EndUser, EndUserConstants, EndUserProxySettings, EndUserError, KSPSettings, EndUserCertificate, EndUserKeyMedia, EndUserSignContainerInfo } from "../euscp/euscp";
2
- import { DigitalSignatureKeyType, PrivateKeyInfo, FilePrivateKeyInfo, HardwarePrivateKeyInfo, KspPrivateKeyInfo, SignFormat, DigitalSignatureFormat } from "./Models";
2
+ import { DigitalSignatureKeyType, PrivateKeyInfo, FilePrivateKeyInfo, HardwarePrivateKeyInfo, KspPrivateKeyInfo } from "./Models";
3
3
  import { downloadAndSignFiles, downloadData, format, readFile, signAlgoToHashAlgo } from "./Utils";
4
4
  import Resourses from "./Resourses.json";
5
5
  import GlSign from "./GlSign";
@@ -36,7 +36,7 @@ export default class DigitalSignature {
36
36
  depositsign.ksp = EndUserConstants.EU_KSP_IIT;
37
37
  depositsign.address = "https://depositsign.com/api/v1/it-enterprise/sign-server";
38
38
  depositsign.directAccess = true;
39
- depositsign.needQrcode = false;
39
+ depositsign.needQRCode = false;
40
40
 
41
41
  const diia = new KSPSettings();
42
42
  diia.name = "Дія.Підпис";
@@ -45,7 +45,7 @@ export default class DigitalSignature {
45
45
  diia.mobileAppName = "Дія";
46
46
  diia.address = "https://diia-sign.it.ua/KSPSign";
47
47
  diia.systemId = "diia-sign-it-ent";
48
- diia.needQrcode = true;
48
+ diia.needQRCode = true;
49
49
 
50
50
  const smartId = new KSPSettings();
51
51
  smartId.name = "Приватбанк - хмарний підпис \"SmartID\"";
@@ -55,14 +55,14 @@ export default class DigitalSignature {
55
55
  smartId.address = "https://acsk.privatbank.ua/cloud/api/back/";
56
56
  smartId.clientIdPrefix = "IEIS_";
57
57
  smartId.confirmationURL = "https://www.privat24.ua/rd/kep";
58
- smartId.needQrcode = true;
58
+ smartId.needQRCode = true;
59
59
 
60
60
  const vchasno = new KSPSettings();
61
61
  vchasno.name = "Вчасно - хмарний підпис";
62
62
  vchasno.ksp = EndUserConstants.EU_KSP_IIT;
63
63
  vchasno.address = "https://cs.vchasno.ua/ss/";
64
64
  vchasno.directAccess = true;
65
- vchasno.needQrcode = false;
65
+ vchasno.needQRCode = false;
66
66
 
67
67
  const cloudKey = new KSPSettings();
68
68
  cloudKey.name = "ТОВ «ЦСК «Україна» - хмарний підпис CloudKey";
@@ -72,14 +72,23 @@ export default class DigitalSignature {
72
72
  cloudKey.address = "https://sid.uakey.com.ua/smartid/iit/";
73
73
  cloudKey.clientIdPrefix = "DIIA_2";
74
74
  cloudKey.confirmationURL = "https://sid.uakey.com.ua/kep?hash=rd/kep";
75
- cloudKey.needQrcode = true;
75
+ cloudKey.needQRCode = true;
76
76
 
77
77
  const esign = new KSPSettings();
78
78
  esign.name = "ESign - хмарний підпис";
79
79
  esign.ksp = EndUserConstants.EU_KSP_IIT;
80
80
  esign.address = "https://cabinet.e-life.com.ua/api/EDG/Sign";
81
81
  esign.directAccess = true;
82
- esign.needQrcode = false;
82
+ esign.needQRCode = false;
83
+
84
+ const idd = new KSPSettings();
85
+ idd.name = "ІДД ДПС - хмарний підпис";
86
+ idd.ksp = EndUserConstants.EU_KSP_IIT;
87
+ idd.address = "https://smart-sign.tax.gov.ua/";
88
+ idd.port = "443";
89
+ idd.directAccess = true;
90
+ idd.clientIdType = 1;
91
+ idd.needQRCode = false;
83
92
 
84
93
  this._KSPs = {
85
94
  depositsign,
@@ -88,6 +97,7 @@ export default class DigitalSignature {
88
97
  vchasno,
89
98
  cloudKey,
90
99
  esign,
100
+ idd,
91
101
  asArray: function() {
92
102
  return [
93
103
  depositsign,
@@ -95,7 +105,8 @@ export default class DigitalSignature {
95
105
  smartId,
96
106
  vchasno,
97
107
  cloudKey,
98
- esign
108
+ esign,
109
+ idd
99
110
  ];
100
111
  }
101
112
  };
@@ -250,7 +261,7 @@ export default class DigitalSignature {
250
261
  }
251
262
 
252
263
  this._euSettings = {
253
- language: this._settings.language,
264
+ language: this._language,
254
265
  encoding: "UTF-16LE",
255
266
  httpProxyServiceURL: this._settings.httpProxyServiceURL,
256
267
  directAccess: true,
@@ -320,9 +331,7 @@ export default class DigitalSignature {
320
331
  * @returns {Promise<Array<EndUserKeyMedia>>} Список подключённых устройств
321
332
  */
322
333
  async getKeyMedias() {
323
- if (!this._euSignKeyMedia) {
324
- await this.setLibraryType(DigitalSignatureKeyType.Token);
325
- }
334
+ await this.setLibraryType(DigitalSignatureKeyType.Token);
326
335
  return this._euSignKeyMedia.GetKeyMedias();
327
336
  }
328
337
 
@@ -610,7 +619,7 @@ export default class DigitalSignature {
610
619
  asByteArray = false;
611
620
  }
612
621
 
613
- if (this.readedKey.keyType === DigitalSignatureKeyType.KSP && signType !== EndUserConstants.EndUserSignContainerType.CAdES) {
622
+ if (this.readedKey.keyType === DigitalSignatureKeyType.KSP && signType.type !== EndUserConstants.EndUserSignContainerType.CAdES) {
614
623
  throw {
615
624
  code: EndUserError.EU_ERROR_NOT_SUPPORTED,
616
625
  message: this._resourses.KSPSignFormatError
@@ -621,7 +630,18 @@ export default class DigitalSignature {
621
630
  const signLevel = signType.asicSignType === EndUserConstants.EndUserASiCSignType.CAdES ? EndUserConstants.EndUserSignType.CAdES_X_Long : EndUserConstants.EndUserXAdESSignLevel.B_LT;
622
631
  return await this._euSign.ASiCSignData(this._readedKey.getSignAlgo(), signType.subType, signType.asicSignType, signLevel, data, !asByteArray);
623
632
  } else if (signType.type === EndUserConstants.EndUserSignContainerType.XAdES) {
624
- return (await this._euSign.XAdESSignData(this._readedKey.getSignAlgo(), signType.subType, EndUserConstants.EndUserXAdESSignLevel.B_LT, data, !asByteArray));
633
+ let returnArray = true;
634
+ if (!Array.isArray(data)) {
635
+ data = [data];
636
+ returnArray = false;
637
+ }
638
+ data = data.map((e, i) => !e.name && !e.val ? { name: "data" + i, val: e } : e);
639
+ const signs = [];
640
+ for (let i = 0; i < data.length; i++) {
641
+ const result = await this._euSign.XAdESSignData(this._readedKey.getSignAlgo(), signType.subType, EndUserConstants.EndUserXAdESSignLevel.B_LT, data[i], !asByteArray);
642
+ signs[i] = result;
643
+ }
644
+ return returnArray ? signs : signs[0];
625
645
  } else if (signType.type === EndUserConstants.EndUserSignContainerType.PAdES) {
626
646
  return await this._euSign.PDFSignData(this._readedKey.getSignAlgo(), data, EndUserConstants.EndUserPAdESSignLevel.B_T, !asByteArray);
627
647
  } else if (signType.type === EndUserConstants.EndUserSignContainerType.CAdES) {
@@ -695,7 +715,7 @@ export default class DigitalSignature {
695
715
  } else if (signContainerInfo.type === EndUserConstants.EndUserSignContainerType.PAdES) {
696
716
  return await this._euSign.PDFVerifyData(sign, signIndex);
697
717
  } else if (signContainerInfo.type === EndUserConstants.EndUserSignContainerType.XAdES) {
698
- return await this._euSign.XAdESVerifyData(data, sign, signIndex);
718
+ return await this._euSign.XAdESVerifyData(data, sign.val || sign, signIndex);
699
719
  } else if (signContainerInfo.type === EndUserConstants.EndUserSignContainerType.CAdES) {
700
720
  if (signContainerInfo.subType === EndUserConstants.EndUserCAdESType.Detached) {
701
721
  if (!data) {
@@ -830,10 +850,10 @@ export default class DigitalSignature {
830
850
  async signFileEx(fileUrl, hash) {
831
851
  const isNamedData = typeof fileUrl === "object";
832
852
  let data = await downloadData(isNamedData ? fileUrl.val : fileUrl, "binary");
833
- if(isNamedData) {
853
+ if (isNamedData) {
834
854
  data = {name: fileUrl.name, val: data};
835
855
  }
836
- if(hash) {
856
+ if (hash) {
837
857
  return await this.signHashEx(data);
838
858
  } else {
839
859
  return await this.signDataEx(data, false);
@@ -918,14 +938,14 @@ export default class DigitalSignature {
918
938
  * @param {boolean} toLocalStorage - Будет ли ключ сохранён после закрытия вкладки
919
939
  */
920
940
  async storePrivateKeyInfo(privateKeyInfo, toLocalStorage) {
921
- if(this._KSPs.needQrcode(privateKeyInfo.ksp)) {
941
+ if (privateKeyInfo.ksp && privateKeyInfo.ksp.needQrcode) {
922
942
  return;
923
943
  }
924
944
 
925
945
  const storage = toLocalStorage ? localStorage : sessionStorage;
926
946
  const keys = await this.getStoredPrivateKeyInfo();
927
947
 
928
- if(keys.length == 0 || keys.filter(key => key.id == privateKeyInfo.id).length < 1) {
948
+ if (keys.length == 0 || keys.filter(key => key.id == privateKeyInfo.id).length < 1) {
929
949
  const keys = await this.getPrivateKeyInfoFromStorage(toLocalStorage);
930
950
  keys.push(privateKeyInfo);
931
951
  const data = await this._euSignFile.ProtectDataByPassword(JSON.stringify(keys), "", true);
@@ -950,23 +970,23 @@ export default class DigitalSignature {
950
970
 
951
971
  let ls;
952
972
  const result = [];
953
- if(!storedKeys) {
973
+ if (!storedKeys) {
954
974
  return result;
955
975
  }
956
976
  const data = await this._euSignFile.UnprotectDataByPassword(storedKeys, "", true);
957
- try{
977
+ try {
958
978
  ls = JSON.parse(data);
959
- if(keyType >= 0) {
979
+ if (keyType >= 0) {
960
980
  ls = ls.filter(key => key.keyType == keyType);
961
981
  }
962
982
  }
963
- catch{
983
+ catch {
964
984
  ls = [];
965
985
  }
966
986
 
967
987
  ls.forEach(key => {
968
988
  const password = key.password;
969
- if(key.keyType == DigitalSignatureKeyType.File) {
989
+ if (key.keyType == DigitalSignatureKeyType.File) {
970
990
  key.privateKey = new Uint8Array(Object.assign(new Array(), key.privateKey));
971
991
  key = new FilePrivateKeyInfo(key.keyType, key.ownerInfo, key.certificates, key.privateKey, key.password);
972
992
  }
@@ -998,14 +1018,14 @@ export default class DigitalSignature {
998
1018
  localStorage.removeItem(this._userId + this.PRIVATE_KEY_INFO);
999
1019
  sessionStorage.removeItem(this._userId + this.PRIVATE_KEY_INFO);
1000
1020
  }
1001
- else{
1021
+ else {
1002
1022
  const localStoredKeys = await this.getPrivateKeyInfoFromStorage(true);
1003
1023
  const sessionStoredKeys = await this.getPrivateKeyInfoFromStorage(false);
1004
1024
  const storage = localStoredKeys.filter(item => item.id == keyId).length > 0 ? localStorage : sessionStorage;
1005
1025
  const keys = storage == localStorage ? localStoredKeys : sessionStoredKeys;
1006
1026
  const keyIndex = keys.findIndex((element) => element.id == keyId);
1007
1027
 
1008
- if(keyIndex > -1) {
1028
+ if (keyIndex > -1) {
1009
1029
  keys.splice(keyIndex, 1);
1010
1030
  const data = await this._euSignFile.ProtectDataByPassword(JSON.stringify(keys), "", true);
1011
1031
  storage[this._userId + this.PRIVATE_KEY_INFO] = data;
@@ -1037,11 +1057,15 @@ export default class DigitalSignature {
1037
1057
  }
1038
1058
 
1039
1059
  get _resourses() {
1040
- return Resourses[this._settings.language];
1060
+ return Resourses[this._language];
1041
1061
  }
1042
1062
 
1043
1063
  get _userId () {
1044
- return typeof this._settings.userId === "function" ? this._settings.userId() : this._settings.userId;
1064
+ return typeof this._settingsProvider.userId === "function" ? this._settingsProvider.userId() : this._settingsProvider.userId;
1065
+ }
1066
+
1067
+ get _language () {
1068
+ return typeof this._settingsProvider.language === "function" ? this._settingsProvider.language() : this._settingsProvider.language;
1045
1069
  }
1046
1070
 
1047
1071
  /**
package/src/Models.js CHANGED
@@ -102,14 +102,14 @@ export class LegacySettingsProvider {
102
102
  getSettings(testMode) {
103
103
  return new DigitalSignatureSettings(this.language,
104
104
  this.userId,
105
- this.basePath + "/ProxyHandler",
105
+ this.basePath + "/ProxyHandler.ashx",
106
106
  new LegacyCertificatesProvider(
107
107
  testMode,
108
108
  this.basePath + "/Data/version.txt",
109
- this.basePath + testMode ? "/Data/CAs.test.json" : "/Data/CAs.json",
110
- this.basePath + testMode ? "/Data/CACertificates.p7b" : "/Data/CACertificates.p7b"
109
+ this.basePath + (testMode ? "/Data/CAs.test.json" : "/Data/CAs.json"),
110
+ this.basePath + (testMode ? "/Data/CACertificates.test.p7b" : "/Data/CACertificates.p7b")
111
111
  ),
112
- this.basePath + `/Scripts/euscp.worker.ex-${LIBRARY_VERSION}.js`
112
+ this.basePath + `/Scripts/DigitalSignature/euscp.worker.ex-${LIBRARY_VERSION}.js`
113
113
  );
114
114
  }
115
115
  }