@it-enterprise/digital-signature 1.1.0 → 1.1.6

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/src/Models.js CHANGED
@@ -2,7 +2,7 @@ import { EndUserCertificate, EndUserError, EndUserOwnerInfo, EndUserConstants }
2
2
  import GlSign from "./GlSign";
3
3
  import { downloadData, byteArrayToBase64, base64ToByteArray, signAlgoToHashAlgo, getSupportedSignAlgos } from "./Utils";
4
4
 
5
- const LIBRARY_VERSION = "1.3.45";
5
+ const LIBRARY_VERSION = "1.3.49";
6
6
 
7
7
  /**
8
8
  * Параметры библиотеки электронной подписи
@@ -10,11 +10,13 @@ const LIBRARY_VERSION = "1.3.45";
10
10
  export class DigitalSignatureSettings {
11
11
  /**
12
12
  * @param {string} language - Язык. Поддержываемые значения: en, ru, uk
13
+ * @param {string} userId - id пользователя (для сохранения ключей и предпочитаемого типа ключа)
13
14
  * @param {string} httpProxyServiceURL - Ссылка на ProxyHandler
14
15
  * @param {UriCertificatesProvider | WebCalcCertificatesProvider} certificatesProvider - Список центров сертификации, или ссылка на их скачивание
15
16
  */
16
- constructor(language, httpProxyServiceURL, certificatesProvider, mssServiceURL, libraryUrl) {
17
+ constructor(language, userId, httpProxyServiceURL, certificatesProvider, mssServiceURL, libraryUrl) {
17
18
  this.language = language || "ru";
19
+ this.userId = userId;
18
20
  this.httpProxyServiceURL = httpProxyServiceURL;
19
21
  this.certificatesProvider = certificatesProvider;
20
22
  this.mssServiceURL = mssServiceURL;
@@ -28,12 +30,13 @@ export class DigitalSignatureSettings {
28
30
  export class DefaultSettingProvider {
29
31
  /**
30
32
  * @param {string} language - Язык ошибок
33
+ * @param {string | function} userId - id пользователя (для сохранения ключей и предпочитаемого типа ключа)
31
34
  * @param {string} glSign - ПГУ GlSign
32
35
  * @param {string} basePath - путь к ProxyHandler
33
36
  * @param {string} certificatesPath - путь к папке с сертификатами
34
37
  *
35
38
  */
36
- constructor(language, basePath) {
39
+ constructor(language, userId, basePath) {
37
40
  if (typeof basePath !== "string") {
38
41
  throw {
39
42
  code: EndUserError.EU_ERROR_BAD_PARAMETER,
@@ -44,6 +47,7 @@ export class DefaultSettingProvider {
44
47
  }
45
48
 
46
49
  this.language = language;
50
+ this.userId = userId;
47
51
  this.basePath = basePath;
48
52
  }
49
53
 
@@ -56,6 +60,7 @@ export class DefaultSettingProvider {
56
60
  if (!this._settings) {
57
61
  this._settings = new DigitalSignatureSettings(
58
62
  this.language,
63
+ this.userId,
59
64
  this.basePath + "/ProxyHandler",
60
65
  new UriCertificatesProvider(
61
66
  this.basePath + "/files?name=CAs.json",
@@ -76,11 +81,12 @@ export class DefaultSettingProvider {
76
81
  export class GraphQlSettingProvider {
77
82
  /**
78
83
  * @param {string} language - Язык ошибок
84
+ * @param {string | function} userId - id пользователя (для сохранения ключей и предпочитаемого типа ключа)
79
85
  * @param {string} graphQlUri - Ссылка на GraphQl сервер
80
86
  * @param {string} wsUri - Ссылка на веб-сервисы
81
87
  * @param {Object} auth - Функция для получения токена авторизации
82
88
  */
83
- constructor(language, graphQlUri, wsUri, auth) {
89
+ constructor(language, userId, graphQlUri, wsUri, auth) {
84
90
  if (typeof graphQlUri !== "string") {
85
91
  throw {
86
92
  code: EndUserError.EU_ERROR_BAD_PARAMETER,
@@ -92,6 +98,7 @@ export class GraphQlSettingProvider {
92
98
  }
93
99
 
94
100
  this.language = language;
101
+ this.userId = userId;
95
102
  this.graphQlUri = graphQlUri;
96
103
  this.wsUri = wsUri;
97
104
  this.auth = auth;
@@ -104,6 +111,7 @@ export class GraphQlSettingProvider {
104
111
  getSettings(testMode) {
105
112
  return new DigitalSignatureSettings(
106
113
  this.language,
114
+ this.userId,
107
115
  this.graphQlUri + "/api/digitalSignature/ProxyHandler",
108
116
  new GraphQlCertificatesProvider(testMode, this.graphQlUri, this.wsUri)
109
117
  );
@@ -164,7 +172,7 @@ export class UriCertificatesProvider extends CertificatesProvider {
164
172
 
165
173
  async loadCertificates() {
166
174
  try {
167
- let [CAs, CACertificates] = await Promise.all([downloadData(this.CAsUri, "json"), downloadData(this.CACertificatesUri, "binary")]);
175
+ const [CAs, CACertificates] = await Promise.all([downloadData(this.CAsUri, "json"), downloadData(this.CACertificatesUri, "binary")]);
168
176
 
169
177
  return { CAs, CACertificates };
170
178
  } catch (error) {
@@ -204,8 +212,8 @@ export class GraphQlCertificatesProvider extends CertificatesProvider {
204
212
 
205
213
  async loadCertificates() {
206
214
  let CAs = this._getItem("CAs"),
207
- CACertificates = this._getItem("CACertificates"),
208
- CACertificatesVersion = this._getItem("CACertificatesVersion"),
215
+ CACertificates = this._getItem("CACertificates");
216
+ const CACertificatesVersion = this._getItem("CACertificatesVersion"),
209
217
  CAsVersion = this._getItem("CAsVersion");
210
218
 
211
219
  const version = { VERSIONCAS: CAsVersion, VERSIONCERT: CACertificatesVersion, INCLUDETEST: this.testMode };
@@ -231,7 +239,7 @@ export class GraphQlCertificatesProvider extends CertificatesProvider {
231
239
  }
232
240
 
233
241
  try {
234
- let res = await downloadData(this.graphQlUri + "/api/digitalSignature/CAsAndCertificates?version=" + JSON.stringify(version), "json");
242
+ const res = await downloadData(this.graphQlUri + "/api/digitalSignature/CAsAndCertificates?version=" + JSON.stringify(version), "json");
235
243
  if (!res) {
236
244
  return { CAs, CACertificates };
237
245
  }
@@ -263,7 +271,7 @@ export class GraphQlCertificatesProvider extends CertificatesProvider {
263
271
  }
264
272
  }
265
273
 
266
- /** Подпись файловыми ключами, через MobileId, облачные сервисы */
274
+ /** Подпись файловыми ключами, через облачные сервисы */
267
275
  export const DigitalSignatureLibraryTypeJS = 0;
268
276
  /** Подпись аппартными ключами */
269
277
  export const DigitalSignatureLibraryTypeSW = 1;
@@ -282,10 +290,12 @@ export const DigitalSignatureLibraryType = {
282
290
  export const DigitalSignatureKeyTypeFile = 0;
283
291
  /** Аппаратный ключ */
284
292
  export const DigitalSignatureKeyTypeToken = 1;
285
- /** MobileID */
286
- export const DigitalSignatureKeyTypeMobileID = 2;
293
+ /** DepositSign */
294
+ export const DigitalSignatureKeyTypeDepositsign = 2;
295
+ /** Дiя */
296
+ export const DigitalSignatureKeyTypeDiia = 3;
287
297
  /** Облачный сервис */
288
- export const DigitalSignatureKeyTypeKSP = 3;
298
+ export const DigitalSignatureKeyTypeKSP = 4;
289
299
 
290
300
  /**
291
301
  * Типы ключей
@@ -293,7 +303,8 @@ export const DigitalSignatureKeyTypeKSP = 3;
293
303
  export const DigitalSignatureKeyType = {
294
304
  File: DigitalSignatureKeyTypeFile,
295
305
  Token: DigitalSignatureKeyTypeToken,
296
- MobileID: DigitalSignatureKeyTypeMobileID,
306
+ Depositsign: DigitalSignatureKeyTypeDepositsign,
307
+ Diia: DigitalSignatureKeyTypeDiia,
297
308
  KSP: DigitalSignatureKeyTypeKSP
298
309
  };
299
310
 
@@ -303,12 +314,14 @@ export class PrivateKeyInfo {
303
314
  * @param {EndUserOwnerInfo} ownerInfo - Информация о владельце ключа
304
315
  * @param {EndUserCertificate[]} certificates - Сертификаты ключа
305
316
  * @param {string} visibleName - Имя ключа
317
+ * @param {string} id - Идентификатор ключа
306
318
  */
307
- constructor(keyType, ownerInfo, certificates, visibleName) {
319
+ constructor(keyType, ownerInfo, certificates, visibleName, id) {
308
320
  this.keyType = keyType;
309
321
  this.ownerInfo = ownerInfo;
310
322
  this.certificates = certificates;
311
323
  this.visibleName = visibleName;
324
+ this.id = id;
312
325
  }
313
326
 
314
327
  /**
@@ -330,7 +343,7 @@ export class PrivateKeyInfo {
330
343
  * Ключ поддерживает электронную подпись
331
344
  */
332
345
  supportSigning() {
333
- if(this instanceof KspPrivateKeyInfo || this instanceof MobileIdPrivateKeyInfo){
346
+ if(this instanceof KspPrivateKeyInfo) {
334
347
  return true;
335
348
  }
336
349
 
@@ -363,7 +376,15 @@ export class PrivateKeyInfo {
363
376
  */
364
377
  getSignAlgo() {
365
378
  const certificates = this.certificates;
366
- return getSupportedSignAlgos(certificates)[0];
379
+ if(this instanceof KspPrivateKeyInfo) {
380
+ return EndUserConstants.EndUserSignAlgo.DSTU4145WithGOST34311;
381
+ }
382
+ else if(certificates.length > 0) {
383
+ return getSupportedSignAlgos(certificates)[0];
384
+ }
385
+ else{
386
+ return EndUserConstants.EndUserSignAlgo.Unknown;
387
+ }
367
388
  }
368
389
 
369
390
  /**
@@ -380,10 +401,12 @@ export class FilePrivateKeyInfo extends PrivateKeyInfo {
380
401
  * @param {EndUserOwnerInfo} ownerInfo - Информация о владельце ключа
381
402
  * @param {EndUserCertificate[]} certificates - Сертификаты ключа
382
403
  * @param {Uint8Array} privateKey - Файловый ключ
404
+ * @param {string?} password - Пароль от ключа
383
405
  */
384
- constructor(keyType, ownerInfo, certificates, privateKey){
385
- super(keyType, ownerInfo, certificates, certificates[0].infoEx.issuerCN);
406
+ constructor(keyType, ownerInfo, certificates, privateKey, password) {
407
+ super(keyType, ownerInfo, certificates, certificates[0].infoEx.subjCN, certificates[0].infoEx.serial);
386
408
  this.privateKey = privateKey;
409
+ this.password = password;
387
410
  }
388
411
  }
389
412
 
@@ -393,29 +416,14 @@ export class HardwarePrivateKeyInfo extends PrivateKeyInfo {
393
416
  * @param {EndUserOwnerInfo} ownerInfo - Информация о владельце ключа
394
417
  * @param {EndUserCertificate[]} certificates - Сертификаты ключа
395
418
  * @param {EndUserKeyMedia} keyMedia - Параметры аппаратного ключа
419
+ * @param {boolean} needSavePassword - Нужно ли сохранять пароль
396
420
  */
397
- constructor(keyType, ownerInfo, certificates, keyMedia){
398
- super(keyType, ownerInfo, certificates, certificates[0].infoEx.issuerCN);
399
- keyMedia.password = "";
421
+ constructor(keyType, ownerInfo, certificates, keyMedia) {
422
+ super(keyType, ownerInfo, certificates, certificates[0].infoEx.subjCN, certificates[0].infoEx.serial);
400
423
  this.keyMedia = keyMedia;
401
424
  }
402
425
  }
403
426
 
404
- export class MobileIdPrivateKeyInfo extends PrivateKeyInfo {
405
- /**
406
- * @param {number} keyType - Тип ключа
407
- * @param {EndUserOwnerInfo} ownerInfo - Информация о владельце ключа
408
- * @param {EndUserCertificate[]} certificates - Сертификаты ключа
409
- * @param {string} phone - Номер телефона
410
- * @param {EndUserConstants.EndUserMobileOperatorID} operatorId - Оператор
411
- */
412
- constructor(keyType, ownerInfo, certificates, phone, operatorId){
413
- super(keyType, ownerInfo, certificates, phone);
414
- this.phone = phone;
415
- this.operatorId = operatorId;
416
- }
417
- }
418
-
419
427
  export class KspPrivateKeyInfo extends PrivateKeyInfo {
420
428
  /**
421
429
  * @param {number} keyType - Тип ключа
@@ -424,8 +432,8 @@ export class KspPrivateKeyInfo extends PrivateKeyInfo {
424
432
  * @param {string} userId - Идентификатор пользователя
425
433
  * @param {EndUserKSP} ksp - Объект KSP
426
434
  */
427
- constructor(keyType, ownerInfo, certificates, userId, ksp){
428
- super(keyType, ownerInfo, certificates, userId);
435
+ constructor(keyType, ownerInfo, certificates, userId, ksp) {
436
+ super(keyType, ownerInfo, certificates, userId, userId);
429
437
  this.userId = userId;
430
438
  this.ksp = ksp;
431
439
  }
@@ -8,7 +8,8 @@
8
8
  "WebExtensionInstall": "Інсталяційний пакет бібліотеки підпису (web-розширення)",
9
9
  "LibraryInstall": "Інсталяційний пакет web-бібліотеки підпису",
10
10
  "LibraryUpdate": "Оновлення web-бібліотеки підпису",
11
- "PrivateKeyNotReaded": "Особистий ключ не считано."
11
+ "PrivateKeyNotReaded": "Особистий ключ не считано.",
12
+ "DiiaError": "Дія.Підпис – сервіс для накладання кваліфікованого електронного підпису за допомогою смартфону і додатку «Дія».<br/>Для можливості використання «Дія.Підпис» у даній інсталяції системи вам необхідно звернутися до свого постачальника.<br/>У зверненні вкажіть наступну інформацію:<br/><ul><li>Посилання: "
12
13
  },
13
14
  "ru": {
14
15
  "LibraryNotSupported": "Библиотека web-подписи не поддерживается в вашем браузере или ОС.",
@@ -19,7 +20,8 @@
19
20
  "WebExtensionInstall": "Установочный пакет библиотеки подписи (web-розширення)",
20
21
  "LibraryInstall": "Установочный пакет web-библиотеки подписи",
21
22
  "LibraryUpdate": "Обновление web-библиотеки подписи",
22
- "PrivateKeyNotReaded": "Приватный ключ не считан."
23
+ "PrivateKeyNotReaded": "Приватный ключ не считан.",
24
+ "DiiaError": "Дія.Підпис – сервис для наложения квалифицированной электронной подписи с помощью смартфона и приложения «Дія».<br/>Для возможности использования «Дія.Підпис» в данной инсталляции системы вам необходимо обратиться к своему поставщику.<br/>В обращении укажите следующую информацию:<br/><ul><li>Ссылка: "
23
25
  },
24
26
  "en": {
25
27
  "LibraryNotSupported": "Web-signature library is not supported in your browser or OS.",
@@ -30,6 +32,7 @@
30
32
  "WebExtensionInstall": "Signature library installation package (web-extension)",
31
33
  "LibraryInstall": "Web-signature library installation package",
32
34
  "LibraryUpdate": "Web-signature library update package",
33
- "PrivateKeyNotReaded": "Private key not readed."
35
+ "PrivateKeyNotReaded": "Private key not readed.",
36
+ "DiiaError": "Дія.Підпис - a service for applying a qualified electronic signature using a smartphone and the application \"Дія\". <br/> To be able to use \"Дія.Підпис\" in this system, you need to contact your provider. <br/> Please include the following information in your request: <br/> <ul> <li> Link: "
34
37
  }
35
38
  }
package/.gitlab-ci.yml DELETED
@@ -1,12 +0,0 @@
1
- stages:
2
- - publish
3
-
4
- Publish_npm_package:
5
- stage: publish
6
- script:
7
- - npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
8
- - npm publish --verbose
9
- only:
10
- - master
11
- tags:
12
- - tfs2017