@it-enterprise/digital-signature 1.4.6 → 1.5.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/dist/euscp.worker.js +8 -0
- package/dist/it-digital-signature.mjs +368 -205
- package/dist/it-digital-signature.mjs.map +1 -1
- package/dist/it-digital-signature.umd.js +1 -1
- package/dist/it-digital-signature.umd.js.map +1 -1
- package/package.json +2 -3
- package/readme.md +1 -1
- package/src/DigitalSignature.js +84 -29
- package/src/GlSign.js +1 -1
- package/src/Utils.js +334 -57
- package/src/umcaservice.js +8 -5
package/src/Utils.js
CHANGED
|
@@ -87,11 +87,13 @@ export function makeUrl(url) {
|
|
|
87
87
|
return origin + url;
|
|
88
88
|
}
|
|
89
89
|
if (origin && pathname) {
|
|
90
|
-
return origin + pathname.
|
|
90
|
+
return origin + pathname.substring(0, pathname.lastIndexOf("/")) + "/" + url;
|
|
91
91
|
}
|
|
92
92
|
return url;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
//--------------------------------------------------------------------------------
|
|
96
|
+
|
|
95
97
|
export function format(format) {
|
|
96
98
|
const args = Array.prototype.slice.call(arguments, 1);
|
|
97
99
|
return format.replace(/{(\d+)}/g, function (match, number) {
|
|
@@ -99,6 +101,8 @@ export function format(format) {
|
|
|
99
101
|
});
|
|
100
102
|
}
|
|
101
103
|
|
|
104
|
+
//--------------------------------------------------------------------------------
|
|
105
|
+
|
|
102
106
|
export function readFile(file) {
|
|
103
107
|
return new Promise((resolve, reject) => {
|
|
104
108
|
const reader = new FileReader();
|
|
@@ -113,83 +117,70 @@ export function readFile(file) {
|
|
|
113
117
|
});
|
|
114
118
|
}
|
|
115
119
|
|
|
116
|
-
|
|
117
|
-
let base64Str = "";
|
|
118
|
-
const m_map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
119
|
-
|
|
120
|
-
const bytes = new Uint8Array(array);
|
|
121
|
-
const bytesLength = bytes.length;
|
|
120
|
+
//--------------------------------------------------------------------------------
|
|
122
121
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (bytesLength % 3 === 2) {
|
|
132
|
-
base64Str = base64Str.substring(0, base64Str.length - 1) + "=";
|
|
133
|
-
} else if (bytesLength % 3 === 1) {
|
|
134
|
-
base64Str = base64Str.substring(0, base64Str.length - 2) + "==";
|
|
122
|
+
/**
|
|
123
|
+
* Convert Uint8Array to Base64 string
|
|
124
|
+
* @param {Uint8Array} buffer
|
|
125
|
+
* @returns {string}
|
|
126
|
+
*/
|
|
127
|
+
export function arrayToBase64(buffer) {
|
|
128
|
+
if (typeof buffer.toBase64 === "function") {
|
|
129
|
+
return buffer.toBase64();
|
|
135
130
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return base64Str;
|
|
131
|
+
return new EndUserBase64Coder().encode(buffer);
|
|
139
132
|
}
|
|
140
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Convert Base64 string to Uint8Array
|
|
136
|
+
* @param {string} str
|
|
137
|
+
* @returns {Uint8Array}
|
|
138
|
+
*/
|
|
141
139
|
export function base64ToArray(str) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const array = new Uint8Array(new ArrayBuffer(rawLength));
|
|
145
|
-
|
|
146
|
-
for (let i = 0; i < rawLength; i++) {
|
|
147
|
-
array[i] = raw.charCodeAt(i);
|
|
140
|
+
if (typeof Uint8Array.fromBase64 === "function") {
|
|
141
|
+
return Uint8Array.fromBase64(str);
|
|
148
142
|
}
|
|
149
|
-
return
|
|
143
|
+
return new EndUserBase64Coder().decode(str);
|
|
150
144
|
}
|
|
151
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Converts string to Uint8Array using UTF-16 encoding
|
|
148
|
+
* @param {string} s
|
|
149
|
+
* @returns {Uint8Array}
|
|
150
|
+
*/
|
|
152
151
|
export function stringToArray(s) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const arr = [];
|
|
156
|
-
for (let i = 0; i < utf8.length; i++) {
|
|
157
|
-
arr.push(utf8.charCodeAt(i));
|
|
158
|
-
}
|
|
159
|
-
return arr;
|
|
152
|
+
return new Uint8Array(new EndUserUTF16LECoder().encode(s));
|
|
160
153
|
}
|
|
161
154
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/* eslint-disable no-magic-numbers */
|
|
172
|
-
for (let i = 0; i < length; i++) {
|
|
173
|
-
let chr = arr[i];
|
|
174
|
-
if (chr > 0xFF) {
|
|
175
|
-
chr &= 0xFF;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
ret.push(String.fromCharCode(chr));
|
|
179
|
-
}
|
|
180
|
-
/* eslint-enable no-magic-numbers */
|
|
181
|
-
|
|
182
|
-
return decodeURIComponent(escape(ret.join("")));
|
|
155
|
+
/**
|
|
156
|
+
* Converts Uint8Array to string using UTF-16 encoding
|
|
157
|
+
* @param {Uint8Array} buffer
|
|
158
|
+
* @returns {string}
|
|
159
|
+
*/
|
|
160
|
+
export function arrayToString(buffer) {
|
|
161
|
+
return new EndUserUTF16LECoder().decode(buffer);
|
|
183
162
|
}
|
|
184
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Converts regular string to Base64 string using UTF-16 encoding
|
|
166
|
+
* @param {string} str
|
|
167
|
+
* @returns {string}
|
|
168
|
+
*/
|
|
185
169
|
export function convertToBase64(str) {
|
|
186
170
|
return arrayToBase64(stringToArray(str));
|
|
187
171
|
}
|
|
188
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Converts Base64 string to regular string using UTF-16 encoding
|
|
175
|
+
* @param {string} str
|
|
176
|
+
* @returns {string}
|
|
177
|
+
*/
|
|
189
178
|
export function convertFromBase64(str) {
|
|
190
179
|
return arrayToString(base64ToArray(str));
|
|
191
180
|
}
|
|
192
181
|
|
|
182
|
+
//--------------------------------------------------------------------------------
|
|
183
|
+
|
|
193
184
|
/**
|
|
194
185
|
* Получить алгоритм хеширования для алгоритма подписи
|
|
195
186
|
* @param {EndUserConstants.EndUserSignAlgo} signAlgo - Алгоритм подписи
|
|
@@ -240,6 +231,8 @@ export function getSupportedSignAlgos(certificates, glsign = null) {
|
|
|
240
231
|
return signAlgos;
|
|
241
232
|
}
|
|
242
233
|
|
|
234
|
+
//--------------------------------------------------------------------------------
|
|
235
|
+
|
|
243
236
|
export function isUrlValid(url) {
|
|
244
237
|
try {
|
|
245
238
|
return !!new URL(url);
|
|
@@ -294,11 +287,15 @@ export function isDefaultValue(value) {
|
|
|
294
287
|
return value === false || value === null || typeof value === "undefined";
|
|
295
288
|
}
|
|
296
289
|
|
|
290
|
+
//--------------------------------------------------------------------------------
|
|
291
|
+
|
|
297
292
|
// отсчёт месяцев в JS начинается с нуля -_-
|
|
298
293
|
// реальная дата - 01.07.2026
|
|
299
294
|
/* eslint-disable no-magic-numbers */
|
|
300
295
|
export const IS_DSTU_7564_DAY = () => Date.now() >= new Date(2026, 6, 1);
|
|
301
296
|
|
|
297
|
+
//--------------------------------------------------------------------------------
|
|
298
|
+
|
|
302
299
|
export function dateWithoutTimezone(date) {
|
|
303
300
|
const tzoffset = date.getTimezoneOffset() * 60000; //offset in milliseconds
|
|
304
301
|
const withoutTimezone = new Date(date.valueOf() - tzoffset)
|
|
@@ -306,3 +303,283 @@ export function dateWithoutTimezone(date) {
|
|
|
306
303
|
.slice(0, -1);
|
|
307
304
|
return withoutTimezone;
|
|
308
305
|
};
|
|
306
|
+
|
|
307
|
+
//--------------------------------------------------------------------------------
|
|
308
|
+
|
|
309
|
+
export class EndUserBase64Coder {
|
|
310
|
+
constructor() {
|
|
311
|
+
this.m_map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
312
|
+
this.m_codes = [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
|
|
313
|
+
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103,
|
|
314
|
+
104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118,
|
|
315
|
+
119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47];
|
|
316
|
+
}
|
|
317
|
+
_getTextDecoder() {
|
|
318
|
+
try {
|
|
319
|
+
if (typeof TextDecoder == 'undefined')
|
|
320
|
+
return null;
|
|
321
|
+
|
|
322
|
+
const decoder = new TextDecoder("utf-8");
|
|
323
|
+
if (decoder.encoding != "utf-8")
|
|
324
|
+
return null;
|
|
325
|
+
|
|
326
|
+
return decoder;
|
|
327
|
+
} catch (e) {
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
_encodePart(bytes, begin, end) {
|
|
332
|
+
const result = [];
|
|
333
|
+
let tmp, str;
|
|
334
|
+
|
|
335
|
+
for (let i = begin; i < end; i += 3) {
|
|
336
|
+
tmp = (bytes[i] << 16) |
|
|
337
|
+
(bytes[i + 1] << 8) |
|
|
338
|
+
(bytes[i + 2]);
|
|
339
|
+
str = this.m_map[(tmp >> 18) & 0x3F] +
|
|
340
|
+
this.m_map[(tmp >> 12) & 0x3F] +
|
|
341
|
+
this.m_map[(tmp >> 6) & 0x3F] +
|
|
342
|
+
this.m_map[tmp & 0x3F];
|
|
343
|
+
|
|
344
|
+
result.push(str);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return result.join('');
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
encode(array) {
|
|
351
|
+
let bytes;
|
|
352
|
+
let i, j;
|
|
353
|
+
let tmp;
|
|
354
|
+
let length;
|
|
355
|
+
let str = '';
|
|
356
|
+
let result;
|
|
357
|
+
|
|
358
|
+
bytes = (typeof Uint8Array == 'undefined') ?
|
|
359
|
+
((typeof EndUserUint8Array == 'undefined') ?
|
|
360
|
+
array.slice(0) : new EndUserUint8Array(array)) :
|
|
361
|
+
new Uint8Array(array);
|
|
362
|
+
length = bytes.length;
|
|
363
|
+
|
|
364
|
+
if (length == 0)
|
|
365
|
+
return "";
|
|
366
|
+
|
|
367
|
+
const decoder = this._getTextDecoder();
|
|
368
|
+
if (decoder != null) {
|
|
369
|
+
result = new Uint8Array(parseInt(((length + 2) / 3)) * 4);
|
|
370
|
+
|
|
371
|
+
for (i = 0, j = 0; i < length - (length % 3); i += 3, j += 4) {
|
|
372
|
+
tmp = (bytes[i] << 16) |
|
|
373
|
+
(bytes[i + 1] << 8) |
|
|
374
|
+
(bytes[i + 2]);
|
|
375
|
+
result[j] = this.m_codes[(tmp >> 18) & 0x3F];
|
|
376
|
+
result[j + 1] = this.m_codes[(tmp >> 12) & 0x3F];
|
|
377
|
+
result[j + 2] = this.m_codes[(tmp >> 6) & 0x3F];
|
|
378
|
+
result[j + 3] = this.m_codes[tmp & 0x3F];
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
switch (length % 3) {
|
|
382
|
+
case 1:
|
|
383
|
+
tmp = (bytes[i] << 16);
|
|
384
|
+
result[j] = this.m_codes[(tmp >> 18) & 0x3F];
|
|
385
|
+
result[j + 1] = this.m_codes[(tmp >> 12) & 0x3F];
|
|
386
|
+
result[j + 2] = 61;
|
|
387
|
+
result[j + 3] = 61;
|
|
388
|
+
break;
|
|
389
|
+
case 2:
|
|
390
|
+
tmp = (bytes[i] << 16) |
|
|
391
|
+
(bytes[i + 1] << 8);
|
|
392
|
+
result[j] = this.m_codes[(tmp >> 18) & 0x3F];
|
|
393
|
+
result[j + 1] = this.m_codes[(tmp >> 12) & 0x3F];
|
|
394
|
+
result[j + 2] = this.m_codes[(tmp >> 6) & 0x3F];
|
|
395
|
+
result[j + 3] = 61;
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
str = decoder.decode(result);
|
|
399
|
+
} else {
|
|
400
|
+
let part = null;
|
|
401
|
+
const partLength = 5 * 1024 * 3;
|
|
402
|
+
const baseLength = length - (length % 3);
|
|
403
|
+
const partsCount = parseInt(baseLength / partLength);
|
|
404
|
+
let lastPart;
|
|
405
|
+
|
|
406
|
+
result = [];
|
|
407
|
+
|
|
408
|
+
for (i = 0; i < partsCount; i++) {
|
|
409
|
+
part = this._encodePart(bytes, i * partLength,
|
|
410
|
+
i * partLength + partLength);
|
|
411
|
+
result.push(part);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if ((partsCount * partLength) < baseLength) {
|
|
415
|
+
part = this._encodePart(bytes, i * partLength, baseLength);
|
|
416
|
+
result.push(part);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
switch (length % 3) {
|
|
420
|
+
case 1:
|
|
421
|
+
tmp = (bytes[length - 1] << 16);
|
|
422
|
+
lastPart = this.m_map[(tmp >> 18) & 0x3F];
|
|
423
|
+
lastPart += this.m_map[(tmp >> 12) & 0x3F];
|
|
424
|
+
lastPart += '=';
|
|
425
|
+
lastPart += '=';
|
|
426
|
+
result.push(lastPart);
|
|
427
|
+
break;
|
|
428
|
+
case 2:
|
|
429
|
+
tmp = (bytes[length - 2] << 16) |
|
|
430
|
+
(bytes[length - 1] << 8);
|
|
431
|
+
lastPart = this.m_map[(tmp >> 18) & 0x3F];
|
|
432
|
+
lastPart += this.m_map[(tmp >> 12) & 0x3F];
|
|
433
|
+
lastPart += this.m_map[(tmp >> 6) & 0x3F];
|
|
434
|
+
lastPart += '=';
|
|
435
|
+
result.push(lastPart);
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
str = result.join('');
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
return str;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
decode(base64Str) {
|
|
446
|
+
let bytes;
|
|
447
|
+
let bytesLength;
|
|
448
|
+
let i, j, p;
|
|
449
|
+
let base64StrLength;
|
|
450
|
+
let equals;
|
|
451
|
+
let encoded1, encoded2, encoded3, encoded4;
|
|
452
|
+
|
|
453
|
+
if ((base64Str == '') || ((base64Str.length & 0x03) > 0)) {
|
|
454
|
+
return (typeof Uint8Array == 'undefined') ?
|
|
455
|
+
((typeof EndUserUint8Array == 'undefined') ?
|
|
456
|
+
[] : new EndUserUint8Array(0)) :
|
|
457
|
+
(new Uint8Array(0));
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
base64StrLength = base64Str.length;
|
|
461
|
+
equals = (base64Str[base64StrLength - 1] == '=') ?
|
|
462
|
+
((base64Str[base64StrLength - 2] == '=') ? 2 : 1) : 0;
|
|
463
|
+
bytesLength = (base64StrLength / 4) * 3 - equals;
|
|
464
|
+
|
|
465
|
+
bytes = (typeof Uint8Array == 'undefined') ?
|
|
466
|
+
((typeof EndUserUint8Array == 'undefined') ?
|
|
467
|
+
[] : new EndUserUint8Array(bytesLength)) :
|
|
468
|
+
new Uint8Array(bytesLength);
|
|
469
|
+
|
|
470
|
+
for (i = 0, j = 0, p = 0; i <
|
|
471
|
+
Math.floor((base64StrLength - equals) / 4); i++) {
|
|
472
|
+
encoded1 = this.m_map.indexOf(base64Str[j++]);
|
|
473
|
+
encoded2 = this.m_map.indexOf(base64Str[j++]);
|
|
474
|
+
encoded3 = this.m_map.indexOf(base64Str[j++]);
|
|
475
|
+
encoded4 = this.m_map.indexOf(base64Str[j++]);
|
|
476
|
+
|
|
477
|
+
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
|
|
478
|
+
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
|
|
479
|
+
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
switch (equals) {
|
|
483
|
+
case 2:
|
|
484
|
+
encoded1 = this.m_map.indexOf(base64Str[j]);
|
|
485
|
+
encoded2 = this.m_map.indexOf(base64Str[j + 1]);
|
|
486
|
+
|
|
487
|
+
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
|
|
488
|
+
break;
|
|
489
|
+
|
|
490
|
+
case 1:
|
|
491
|
+
encoded1 = this.m_map.indexOf(base64Str[j]);
|
|
492
|
+
encoded2 = this.m_map.indexOf(base64Str[j + 1]);
|
|
493
|
+
encoded3 = this.m_map.indexOf(base64Str[j + 2]);
|
|
494
|
+
|
|
495
|
+
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
|
|
496
|
+
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
return bytes;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
//--------------------------------------------------------------------------------
|
|
505
|
+
|
|
506
|
+
export class EndUserUTF8Coder {
|
|
507
|
+
encode(str) {
|
|
508
|
+
var out = [], p = 0;
|
|
509
|
+
for (var i = 0; i < str.length; i++) {
|
|
510
|
+
var c = str.charCodeAt(i);
|
|
511
|
+
if (c < 128) {
|
|
512
|
+
out[p++] = c;
|
|
513
|
+
} else if (c < 2048) {
|
|
514
|
+
out[p++] = (c >> 6) | 192;
|
|
515
|
+
out[p++] = (c & 63) | 128;
|
|
516
|
+
} else {
|
|
517
|
+
out[p++] = (c >> 12) | 224;
|
|
518
|
+
out[p++] = ((c >> 6) & 63) | 128;
|
|
519
|
+
out[p++] = (c & 63) | 128;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return out;
|
|
523
|
+
}
|
|
524
|
+
decode(bytes) {
|
|
525
|
+
var out = [], pos = 0, c = 0;
|
|
526
|
+
var c1, c2, c3;
|
|
527
|
+
while (pos < bytes.length) {
|
|
528
|
+
c1 = bytes[pos++];
|
|
529
|
+
if (c1 < 128) {
|
|
530
|
+
out[c++] = String.fromCharCode(c1);
|
|
531
|
+
} else if (c1 > 191 && c1 < 224) {
|
|
532
|
+
c2 = bytes[pos++];
|
|
533
|
+
out[c++] = String.fromCharCode((c1 & 31) << 6 | c2 & 63);
|
|
534
|
+
} else {
|
|
535
|
+
c2 = bytes[pos++];
|
|
536
|
+
c3 = bytes[pos++];
|
|
537
|
+
out[c++] = String.fromCharCode(
|
|
538
|
+
(c1 & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return out.join('');
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
//--------------------------------------------------------------------------------
|
|
546
|
+
|
|
547
|
+
export class EndUserUTF16LECoder {
|
|
548
|
+
encode(str) {
|
|
549
|
+
var out = [];
|
|
550
|
+
var c;
|
|
551
|
+
|
|
552
|
+
for (var i = 0; i < str.length; i++) {
|
|
553
|
+
c = str.charCodeAt(i);
|
|
554
|
+
out.push(c & 0xFF);
|
|
555
|
+
out.push((c & 0xFF00) >> 8);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
return out;
|
|
559
|
+
}
|
|
560
|
+
decode(bytes) {
|
|
561
|
+
var i = 0;
|
|
562
|
+
var ret = '';
|
|
563
|
+
var length;
|
|
564
|
+
|
|
565
|
+
if ((bytes.length % 2) != 0)
|
|
566
|
+
return null;
|
|
567
|
+
|
|
568
|
+
length = bytes.length;
|
|
569
|
+
if (length > 0 &&
|
|
570
|
+
bytes[length - 2] == 0 &&
|
|
571
|
+
bytes[length - 1] == 0) {
|
|
572
|
+
length -= 2;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
while (i < length) {
|
|
576
|
+
ret += String.fromCharCode(bytes[i] | (bytes[i + 1] << 8));
|
|
577
|
+
i += 2;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
return ret;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
//--------------------------------------------------------------------------------
|
|
585
|
+
|
package/src/umcaservice.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EndUserConstants, EndUserError } from "../euscp/euscp";
|
|
2
|
-
import { arrayToBase64, base64ToArray } from "./Utils";
|
|
2
|
+
import { arrayToBase64, base64ToArray, convertToBase64 } from "./Utils";
|
|
3
3
|
|
|
4
4
|
export default class UmCAService {
|
|
5
5
|
constructor(port) {
|
|
@@ -72,11 +72,14 @@ export default class UmCAService {
|
|
|
72
72
|
toSign = [...toSign];
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
// при подписани данных, строковые данные передаются в "сыром" виде а не в base64
|
|
75
76
|
for (let i = 0; i < toSign.length; i++) {
|
|
76
|
-
|
|
77
|
+
let d = toSign[i];
|
|
77
78
|
if (d.val) {
|
|
79
|
+
if (typeof d.val === "string") d.val = convertToBase64(d.val);
|
|
78
80
|
toSign[i] = { name: d.name, val: formatData(d.val, true) };
|
|
79
81
|
} else {
|
|
82
|
+
if (typeof d === "string") d = convertToBase64(d);
|
|
80
83
|
toSign[i] = formatData(d, true);
|
|
81
84
|
}
|
|
82
85
|
}
|
|
@@ -124,7 +127,7 @@ export default class UmCAService {
|
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
const formatData = (data, toBase64) => {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
if (toBase64 && typeof data !== "string") return arrayToBase64(data);
|
|
131
|
+
if (!toBase64 && typeof data === "string") return base64ToArray(data);
|
|
132
|
+
return data;
|
|
130
133
|
};
|