eimzo-sign-core 0.1.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 +62 -0
- package/dist/index.cjs +1340 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +247 -0
- package/dist/index.d.ts +247 -0
- package/dist/index.js +1330 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
- package/src/cert-utils.ts +53 -0
- package/src/client.ts +456 -0
- package/src/errors.ts +73 -0
- package/src/index.ts +45 -0
- package/src/raw-types.ts +65 -0
- package/src/types.ts +112 -0
- package/src/util.ts +69 -0
- package/src/vendor/VENDOR.md +59 -0
- package/src/vendor/e-imzo-client.js +477 -0
- package/src/vendor/e-imzo.js +483 -0
- package/src/vendor/index.ts +46 -0
- package/src/vendor/vendor.d.ts +15 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1340 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// src/errors.ts
|
|
11
|
+
var EimzoError = class _EimzoError extends Error {
|
|
12
|
+
constructor(code, message, options) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "EimzoError";
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.cause = options?.cause;
|
|
17
|
+
Object.setPrototypeOf(this, _EimzoError.prototype);
|
|
18
|
+
}
|
|
19
|
+
/** `EimzoError.is(e)` yoki `EimzoError.is(e, 'E_TIMEOUT')`. */
|
|
20
|
+
static is(error, code) {
|
|
21
|
+
return error instanceof _EimzoError && (code === void 0 || error.code === code);
|
|
22
|
+
}
|
|
23
|
+
/** Bekor qilingan (foydalanuvchi voz kechgan) — odatda jimgina o'tiladi. */
|
|
24
|
+
static isCancelled(error) {
|
|
25
|
+
return _EimzoError.is(error, "E_CANCELLED") || _EimzoError.is(error, "E_KEY_LOAD_CANCELLED");
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
function toEimzoError(error, fallbackCode, fallbackMessage) {
|
|
29
|
+
if (EimzoError.is(error)) return error;
|
|
30
|
+
return new EimzoError(fallbackCode, fallbackMessage, { cause: error });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/util.ts
|
|
34
|
+
function nowIso() {
|
|
35
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
36
|
+
}
|
|
37
|
+
function normalizeSerial(value) {
|
|
38
|
+
return String(value ?? "").toUpperCase().replace(/\s+/g, "");
|
|
39
|
+
}
|
|
40
|
+
function throwIfAborted(signal) {
|
|
41
|
+
if (signal?.aborted) {
|
|
42
|
+
throw new EimzoError("E_CANCELLED", "Amal bekor qilindi");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function withTimeout(timeoutMs, timeoutError, executor, signal) {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
let settled = false;
|
|
48
|
+
const cleanup = () => {
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
signal?.removeEventListener("abort", onAbort);
|
|
51
|
+
};
|
|
52
|
+
const settleResolve = (value) => {
|
|
53
|
+
if (settled) return;
|
|
54
|
+
settled = true;
|
|
55
|
+
cleanup();
|
|
56
|
+
resolve(value);
|
|
57
|
+
};
|
|
58
|
+
const settleReject = (error) => {
|
|
59
|
+
if (settled) return;
|
|
60
|
+
settled = true;
|
|
61
|
+
cleanup();
|
|
62
|
+
reject(error);
|
|
63
|
+
};
|
|
64
|
+
const onAbort = () => settleReject(new EimzoError("E_CANCELLED", "Amal bekor qilindi"));
|
|
65
|
+
const timer = setTimeout(() => settleReject(timeoutError()), timeoutMs);
|
|
66
|
+
if (signal?.aborted) {
|
|
67
|
+
settleReject(new EimzoError("E_CANCELLED", "Amal bekor qilindi"));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
signal?.addEventListener("abort", onAbort);
|
|
71
|
+
try {
|
|
72
|
+
executor(settleResolve, settleReject);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
settleReject(error);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/vendor/e-imzo.js
|
|
80
|
+
(function(global) {
|
|
81
|
+
var _Base64 = global.Base64;
|
|
82
|
+
var version = "2.1.4";
|
|
83
|
+
var buffer;
|
|
84
|
+
if (typeof module !== "undefined" && module.exports) {
|
|
85
|
+
buffer = __require("buffer").Buffer;
|
|
86
|
+
}
|
|
87
|
+
var b64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
88
|
+
var b64tab = (function(bin) {
|
|
89
|
+
var t = {};
|
|
90
|
+
for (var i = 0, l = bin.length; i < l; i++) t[bin.charAt(i)] = i;
|
|
91
|
+
return t;
|
|
92
|
+
})(b64chars);
|
|
93
|
+
var fromCharCode = String.fromCharCode;
|
|
94
|
+
var cb_utob = function(c) {
|
|
95
|
+
if (c.length < 2) {
|
|
96
|
+
var cc = c.charCodeAt(0);
|
|
97
|
+
return cc < 128 ? c : cc < 2048 ? fromCharCode(192 | cc >>> 6) + fromCharCode(128 | cc & 63) : fromCharCode(224 | cc >>> 12 & 15) + fromCharCode(128 | cc >>> 6 & 63) + fromCharCode(128 | cc & 63);
|
|
98
|
+
} else {
|
|
99
|
+
var cc = 65536 + (c.charCodeAt(0) - 55296) * 1024 + (c.charCodeAt(1) - 56320);
|
|
100
|
+
return fromCharCode(240 | cc >>> 18 & 7) + fromCharCode(128 | cc >>> 12 & 63) + fromCharCode(128 | cc >>> 6 & 63) + fromCharCode(128 | cc & 63);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
|
104
|
+
var utob = function(u) {
|
|
105
|
+
return u.replace(re_utob, cb_utob);
|
|
106
|
+
};
|
|
107
|
+
var cb_encode = function(ccc) {
|
|
108
|
+
var padlen = [0, 2, 1][ccc.length % 3], ord = ccc.charCodeAt(0) << 16 | (ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8 | (ccc.length > 2 ? ccc.charCodeAt(2) : 0), chars = [
|
|
109
|
+
b64chars.charAt(ord >>> 18),
|
|
110
|
+
b64chars.charAt(ord >>> 12 & 63),
|
|
111
|
+
padlen >= 2 ? "=" : b64chars.charAt(ord >>> 6 & 63),
|
|
112
|
+
padlen >= 1 ? "=" : b64chars.charAt(ord & 63)
|
|
113
|
+
];
|
|
114
|
+
return chars.join("");
|
|
115
|
+
};
|
|
116
|
+
var btoa = global.btoa ? function(b) {
|
|
117
|
+
return global.btoa(b);
|
|
118
|
+
} : function(b) {
|
|
119
|
+
return b.replace(/[\s\S]{1,3}/g, cb_encode);
|
|
120
|
+
};
|
|
121
|
+
var _encode = buffer ? function(u) {
|
|
122
|
+
return new buffer(u).toString("base64");
|
|
123
|
+
} : function(u) {
|
|
124
|
+
return btoa(utob(u));
|
|
125
|
+
};
|
|
126
|
+
var encode = function(u, urisafe) {
|
|
127
|
+
return !urisafe ? _encode(u) : _encode(u).replace(/[+\/]/g, function(m0) {
|
|
128
|
+
return m0 == "+" ? "-" : "_";
|
|
129
|
+
}).replace(/=/g, "");
|
|
130
|
+
};
|
|
131
|
+
var encodeURI = function(u) {
|
|
132
|
+
return encode(u, true);
|
|
133
|
+
};
|
|
134
|
+
var re_btou = new RegExp([
|
|
135
|
+
"[\xC0-\xDF][\x80-\xBF]",
|
|
136
|
+
"[\xE0-\xEF][\x80-\xBF]{2}",
|
|
137
|
+
"[\xF0-\xF7][\x80-\xBF]{3}"
|
|
138
|
+
].join("|"), "g");
|
|
139
|
+
var cb_btou = function(cccc) {
|
|
140
|
+
switch (cccc.length) {
|
|
141
|
+
case 4:
|
|
142
|
+
var cp = (7 & cccc.charCodeAt(0)) << 18 | (63 & cccc.charCodeAt(1)) << 12 | (63 & cccc.charCodeAt(2)) << 6 | 63 & cccc.charCodeAt(3), offset = cp - 65536;
|
|
143
|
+
return fromCharCode((offset >>> 10) + 55296) + fromCharCode((offset & 1023) + 56320);
|
|
144
|
+
case 3:
|
|
145
|
+
return fromCharCode(
|
|
146
|
+
(15 & cccc.charCodeAt(0)) << 12 | (63 & cccc.charCodeAt(1)) << 6 | 63 & cccc.charCodeAt(2)
|
|
147
|
+
);
|
|
148
|
+
default:
|
|
149
|
+
return fromCharCode(
|
|
150
|
+
(31 & cccc.charCodeAt(0)) << 6 | 63 & cccc.charCodeAt(1)
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
var btou = function(b) {
|
|
155
|
+
return b.replace(re_btou, cb_btou);
|
|
156
|
+
};
|
|
157
|
+
var cb_decode = function(cccc) {
|
|
158
|
+
var len = cccc.length, padlen = len % 4, n = (len > 0 ? b64tab[cccc.charAt(0)] << 18 : 0) | (len > 1 ? b64tab[cccc.charAt(1)] << 12 : 0) | (len > 2 ? b64tab[cccc.charAt(2)] << 6 : 0) | (len > 3 ? b64tab[cccc.charAt(3)] : 0), chars = [
|
|
159
|
+
fromCharCode(n >>> 16),
|
|
160
|
+
fromCharCode(n >>> 8 & 255),
|
|
161
|
+
fromCharCode(n & 255)
|
|
162
|
+
];
|
|
163
|
+
chars.length -= [0, 0, 2, 1][padlen];
|
|
164
|
+
return chars.join("");
|
|
165
|
+
};
|
|
166
|
+
var atob = global.atob ? function(a) {
|
|
167
|
+
return global.atob(a);
|
|
168
|
+
} : function(a) {
|
|
169
|
+
return a.replace(/[\s\S]{1,4}/g, cb_decode);
|
|
170
|
+
};
|
|
171
|
+
var _decode = buffer ? function(a) {
|
|
172
|
+
return new buffer(a, "base64").toString();
|
|
173
|
+
} : function(a) {
|
|
174
|
+
return btou(atob(a));
|
|
175
|
+
};
|
|
176
|
+
var decode = function(a) {
|
|
177
|
+
return _decode(
|
|
178
|
+
a.replace(/[-_]/g, function(m0) {
|
|
179
|
+
return m0 == "-" ? "+" : "/";
|
|
180
|
+
}).replace(/[^A-Za-z0-9\+\/]/g, "")
|
|
181
|
+
);
|
|
182
|
+
};
|
|
183
|
+
var noConflict = function() {
|
|
184
|
+
var Base642 = global.Base64;
|
|
185
|
+
global.Base64 = _Base64;
|
|
186
|
+
return Base642;
|
|
187
|
+
};
|
|
188
|
+
global.Base64 = {
|
|
189
|
+
VERSION: version,
|
|
190
|
+
atob,
|
|
191
|
+
btoa,
|
|
192
|
+
fromBase64: decode,
|
|
193
|
+
toBase64: encode,
|
|
194
|
+
utob,
|
|
195
|
+
encode,
|
|
196
|
+
encodeURI,
|
|
197
|
+
btou,
|
|
198
|
+
decode,
|
|
199
|
+
noConflict
|
|
200
|
+
};
|
|
201
|
+
if (typeof Object.defineProperty === "function") {
|
|
202
|
+
var noEnum = function(v) {
|
|
203
|
+
return { value: v, enumerable: false, writable: true, configurable: true };
|
|
204
|
+
};
|
|
205
|
+
global.Base64.extendString = function() {
|
|
206
|
+
Object.defineProperty(
|
|
207
|
+
String.prototype,
|
|
208
|
+
"fromBase64",
|
|
209
|
+
noEnum(function() {
|
|
210
|
+
return decode(this);
|
|
211
|
+
})
|
|
212
|
+
);
|
|
213
|
+
Object.defineProperty(
|
|
214
|
+
String.prototype,
|
|
215
|
+
"toBase64",
|
|
216
|
+
noEnum(function(urisafe) {
|
|
217
|
+
return encode(this, urisafe);
|
|
218
|
+
})
|
|
219
|
+
);
|
|
220
|
+
Object.defineProperty(
|
|
221
|
+
String.prototype,
|
|
222
|
+
"toBase64URI",
|
|
223
|
+
noEnum(function() {
|
|
224
|
+
return encode(this, true);
|
|
225
|
+
})
|
|
226
|
+
);
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
var _Base64 = global.Base64;
|
|
230
|
+
var version = "2.1.4";
|
|
231
|
+
var buffer;
|
|
232
|
+
if (typeof module !== "undefined" && module.exports) {
|
|
233
|
+
buffer = __require("buffer").Buffer;
|
|
234
|
+
}
|
|
235
|
+
var b64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
236
|
+
var b64tab = (function(bin) {
|
|
237
|
+
var t = {};
|
|
238
|
+
for (var i = 0, l = bin.length; i < l; i++) t[bin.charAt(i)] = i;
|
|
239
|
+
return t;
|
|
240
|
+
})(b64chars);
|
|
241
|
+
var fromCharCode = String.fromCharCode;
|
|
242
|
+
var cb_utob = function(c) {
|
|
243
|
+
if (c.length < 2) {
|
|
244
|
+
let cc = c.charCodeAt(0);
|
|
245
|
+
return cc < 128 ? c : cc < 2048 ? fromCharCode(192 | cc >>> 6) + fromCharCode(128 | cc & 63) : fromCharCode(224 | cc >>> 12 & 15) + fromCharCode(128 | cc >>> 6 & 63) + fromCharCode(128 | cc & 63);
|
|
246
|
+
} else {
|
|
247
|
+
let cc = 65536 + (c.charCodeAt(0) - 55296) * 1024 + (c.charCodeAt(1) - 56320);
|
|
248
|
+
return fromCharCode(240 | cc >>> 18 & 7) + fromCharCode(128 | cc >>> 12 & 63) + fromCharCode(128 | cc >>> 6 & 63) + fromCharCode(128 | cc & 63);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
|
252
|
+
var utob = function(u) {
|
|
253
|
+
return u.replace(re_utob, cb_utob);
|
|
254
|
+
};
|
|
255
|
+
var cb_encode = function(ccc) {
|
|
256
|
+
var padlen = [0, 2, 1][ccc.length % 3], ord = ccc.charCodeAt(0) << 16 | (ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8 | (ccc.length > 2 ? ccc.charCodeAt(2) : 0), chars = [
|
|
257
|
+
b64chars.charAt(ord >>> 18),
|
|
258
|
+
b64chars.charAt(ord >>> 12 & 63),
|
|
259
|
+
padlen >= 2 ? "=" : b64chars.charAt(ord >>> 6 & 63),
|
|
260
|
+
padlen >= 1 ? "=" : b64chars.charAt(ord & 63)
|
|
261
|
+
];
|
|
262
|
+
return chars.join("");
|
|
263
|
+
};
|
|
264
|
+
var btoa = global.btoa ? function(b) {
|
|
265
|
+
return global.btoa(b);
|
|
266
|
+
} : function(b) {
|
|
267
|
+
return b.replace(/[\s\S]{1,3}/g, cb_encode);
|
|
268
|
+
};
|
|
269
|
+
var _encode = buffer ? function(u) {
|
|
270
|
+
return new buffer(u).toString("base64");
|
|
271
|
+
} : function(u) {
|
|
272
|
+
return btoa(utob(u));
|
|
273
|
+
};
|
|
274
|
+
var encode = function(u, urisafe) {
|
|
275
|
+
return !urisafe ? _encode(u) : _encode(u).replace(/[+\/]/g, function(m0) {
|
|
276
|
+
return m0 == "+" ? "-" : "_";
|
|
277
|
+
}).replace(/=/g, "");
|
|
278
|
+
};
|
|
279
|
+
var encodeURI = function(u) {
|
|
280
|
+
return encode(u, true);
|
|
281
|
+
};
|
|
282
|
+
var re_btou = new RegExp([
|
|
283
|
+
"[\xC0-\xDF][\x80-\xBF]",
|
|
284
|
+
"[\xE0-\xEF][\x80-\xBF]{2}",
|
|
285
|
+
"[\xF0-\xF7][\x80-\xBF]{3}"
|
|
286
|
+
].join("|"), "g");
|
|
287
|
+
var cb_btou = function(cccc) {
|
|
288
|
+
switch (cccc.length) {
|
|
289
|
+
case 4:
|
|
290
|
+
var cp = (7 & cccc.charCodeAt(0)) << 18 | (63 & cccc.charCodeAt(1)) << 12 | (63 & cccc.charCodeAt(2)) << 6 | 63 & cccc.charCodeAt(3), offset = cp - 65536;
|
|
291
|
+
return fromCharCode((offset >>> 10) + 55296) + fromCharCode((offset & 1023) + 56320);
|
|
292
|
+
case 3:
|
|
293
|
+
return fromCharCode(
|
|
294
|
+
(15 & cccc.charCodeAt(0)) << 12 | (63 & cccc.charCodeAt(1)) << 6 | 63 & cccc.charCodeAt(2)
|
|
295
|
+
);
|
|
296
|
+
default:
|
|
297
|
+
return fromCharCode(
|
|
298
|
+
(31 & cccc.charCodeAt(0)) << 6 | 63 & cccc.charCodeAt(1)
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
var btou = function(b) {
|
|
303
|
+
return b.replace(re_btou, cb_btou);
|
|
304
|
+
};
|
|
305
|
+
var cb_decode = function(cccc) {
|
|
306
|
+
var len = cccc.length, padlen = len % 4, n = (len > 0 ? b64tab[cccc.charAt(0)] << 18 : 0) | (len > 1 ? b64tab[cccc.charAt(1)] << 12 : 0) | (len > 2 ? b64tab[cccc.charAt(2)] << 6 : 0) | (len > 3 ? b64tab[cccc.charAt(3)] : 0), chars = [
|
|
307
|
+
fromCharCode(n >>> 16),
|
|
308
|
+
fromCharCode(n >>> 8 & 255),
|
|
309
|
+
fromCharCode(n & 255)
|
|
310
|
+
];
|
|
311
|
+
chars.length -= [0, 0, 2, 1][padlen];
|
|
312
|
+
return chars.join("");
|
|
313
|
+
};
|
|
314
|
+
var atob = global.atob ? function(a) {
|
|
315
|
+
return global.atob(a);
|
|
316
|
+
} : function(a) {
|
|
317
|
+
return a.replace(/[\s\S]{1,4}/g, cb_decode);
|
|
318
|
+
};
|
|
319
|
+
var _decode = buffer ? function(a) {
|
|
320
|
+
return new buffer(a, "base64").toString();
|
|
321
|
+
} : function(a) {
|
|
322
|
+
return btou(atob(a));
|
|
323
|
+
};
|
|
324
|
+
var decode = function(a) {
|
|
325
|
+
return _decode(
|
|
326
|
+
a.replace(/[-_]/g, function(m0) {
|
|
327
|
+
return m0 == "-" ? "+" : "/";
|
|
328
|
+
}).replace(/[^A-Za-z0-9\+\/]/g, "")
|
|
329
|
+
);
|
|
330
|
+
};
|
|
331
|
+
var noConflict = function() {
|
|
332
|
+
var Base642 = global.Base64;
|
|
333
|
+
global.Base64 = _Base64;
|
|
334
|
+
return Base642;
|
|
335
|
+
};
|
|
336
|
+
global.Base64 = {
|
|
337
|
+
VERSION: version,
|
|
338
|
+
atob,
|
|
339
|
+
btoa,
|
|
340
|
+
fromBase64: decode,
|
|
341
|
+
toBase64: encode,
|
|
342
|
+
utob,
|
|
343
|
+
encode,
|
|
344
|
+
encodeURI,
|
|
345
|
+
btou,
|
|
346
|
+
decode,
|
|
347
|
+
noConflict
|
|
348
|
+
};
|
|
349
|
+
if (typeof Object.defineProperty === "function") {
|
|
350
|
+
var noEnum = function(v) {
|
|
351
|
+
return { value: v, enumerable: false, writable: true, configurable: true };
|
|
352
|
+
};
|
|
353
|
+
global.Base64.extendString = function() {
|
|
354
|
+
Object.defineProperty(
|
|
355
|
+
String.prototype,
|
|
356
|
+
"fromBase64",
|
|
357
|
+
noEnum(function() {
|
|
358
|
+
return decode(this);
|
|
359
|
+
})
|
|
360
|
+
);
|
|
361
|
+
Object.defineProperty(
|
|
362
|
+
String.prototype,
|
|
363
|
+
"toBase64",
|
|
364
|
+
noEnum(function(urisafe) {
|
|
365
|
+
return encode(this, urisafe);
|
|
366
|
+
})
|
|
367
|
+
);
|
|
368
|
+
Object.defineProperty(
|
|
369
|
+
String.prototype,
|
|
370
|
+
"toBase64URI",
|
|
371
|
+
noEnum(function() {
|
|
372
|
+
return encode(this, true);
|
|
373
|
+
})
|
|
374
|
+
);
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
if (typeof window !== "undefined") window.Base64 = global.Base64;
|
|
378
|
+
})(typeof globalThis !== "undefined" ? globalThis : void 0);
|
|
379
|
+
globalThis.CAPIWS = typeof EIMZOEXT !== "undefined" ? EIMZOEXT : {
|
|
380
|
+
URL: ((typeof window !== "undefined" ? window.location.protocol : "").toLowerCase() === "https:" ? "wss://127.0.0.1:64443" : "ws://127.0.0.1:64646") + "/service/cryptapi",
|
|
381
|
+
callFunction: function(funcDef, callback, error) {
|
|
382
|
+
if (!window.WebSocket) {
|
|
383
|
+
if (error)
|
|
384
|
+
error();
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
var socket;
|
|
388
|
+
try {
|
|
389
|
+
socket = new WebSocket(this.URL);
|
|
390
|
+
} catch (e) {
|
|
391
|
+
error(e);
|
|
392
|
+
}
|
|
393
|
+
socket.onerror = function(e) {
|
|
394
|
+
if (error)
|
|
395
|
+
error(e);
|
|
396
|
+
};
|
|
397
|
+
socket.onmessage = function(event) {
|
|
398
|
+
var data = JSON.parse(event.data);
|
|
399
|
+
socket.close();
|
|
400
|
+
callback(event, data);
|
|
401
|
+
};
|
|
402
|
+
socket.onopen = function() {
|
|
403
|
+
socket.send(JSON.stringify(funcDef));
|
|
404
|
+
};
|
|
405
|
+
},
|
|
406
|
+
version: function(callback, error) {
|
|
407
|
+
if (!window.WebSocket) {
|
|
408
|
+
if (error)
|
|
409
|
+
error();
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
var socket;
|
|
413
|
+
try {
|
|
414
|
+
socket = new WebSocket(this.URL);
|
|
415
|
+
} catch (e) {
|
|
416
|
+
error(e);
|
|
417
|
+
}
|
|
418
|
+
socket.onerror = function(e) {
|
|
419
|
+
if (error)
|
|
420
|
+
error(e);
|
|
421
|
+
};
|
|
422
|
+
socket.onmessage = function(event) {
|
|
423
|
+
var data = JSON.parse(event.data);
|
|
424
|
+
socket.close();
|
|
425
|
+
callback(event, data);
|
|
426
|
+
};
|
|
427
|
+
socket.onopen = function() {
|
|
428
|
+
var o = { name: "version" };
|
|
429
|
+
socket.send(JSON.stringify(o));
|
|
430
|
+
};
|
|
431
|
+
},
|
|
432
|
+
apidoc: function(callback, error) {
|
|
433
|
+
if (!window.WebSocket) {
|
|
434
|
+
if (error)
|
|
435
|
+
error();
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
var socket;
|
|
439
|
+
try {
|
|
440
|
+
socket = new WebSocket(this.URL);
|
|
441
|
+
} catch (e) {
|
|
442
|
+
error(e);
|
|
443
|
+
}
|
|
444
|
+
socket.onerror = function(e) {
|
|
445
|
+
if (error)
|
|
446
|
+
error(e);
|
|
447
|
+
};
|
|
448
|
+
socket.onmessage = function(event) {
|
|
449
|
+
var data = JSON.parse(event.data);
|
|
450
|
+
socket.close();
|
|
451
|
+
callback(event, data);
|
|
452
|
+
};
|
|
453
|
+
socket.onopen = function() {
|
|
454
|
+
var o = { name: "apidoc" };
|
|
455
|
+
socket.send(JSON.stringify(o));
|
|
456
|
+
};
|
|
457
|
+
},
|
|
458
|
+
apikey: function(domainAndKey, callback, error) {
|
|
459
|
+
if (!window.WebSocket) {
|
|
460
|
+
if (error)
|
|
461
|
+
error();
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
var socket;
|
|
465
|
+
try {
|
|
466
|
+
socket = new WebSocket(this.URL);
|
|
467
|
+
} catch (e) {
|
|
468
|
+
error(e);
|
|
469
|
+
}
|
|
470
|
+
socket.onerror = function(e) {
|
|
471
|
+
if (error)
|
|
472
|
+
error(e);
|
|
473
|
+
};
|
|
474
|
+
socket.onmessage = function(event) {
|
|
475
|
+
var data = JSON.parse(event.data);
|
|
476
|
+
socket.close();
|
|
477
|
+
callback(event, data);
|
|
478
|
+
};
|
|
479
|
+
socket.onopen = function() {
|
|
480
|
+
var o = { name: "apikey", arguments: domainAndKey };
|
|
481
|
+
socket.send(JSON.stringify(o));
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
// src/vendor/e-imzo-client.js
|
|
487
|
+
Date.prototype.yyyymmdd = function() {
|
|
488
|
+
var yyyy = this.getFullYear().toString();
|
|
489
|
+
var mm = (this.getMonth() + 1).toString();
|
|
490
|
+
var dd = this.getDate().toString();
|
|
491
|
+
return yyyy + (mm[1] ? mm : "0" + mm[0]) + (dd[1] ? dd : "0" + dd[0]);
|
|
492
|
+
};
|
|
493
|
+
Date.prototype.ddmmyyyy = function() {
|
|
494
|
+
var yyyy = this.getFullYear().toString();
|
|
495
|
+
var mm = (this.getMonth() + 1).toString();
|
|
496
|
+
var dd = this.getDate().toString();
|
|
497
|
+
return (dd[1] ? dd : "0" + dd[0]) + "." + (mm[1] ? mm : "0" + mm[0]) + "." + yyyy;
|
|
498
|
+
};
|
|
499
|
+
String.prototype.splitKeep = function(splitter, ahead) {
|
|
500
|
+
var self = this;
|
|
501
|
+
var result = [];
|
|
502
|
+
if (splitter != "") {
|
|
503
|
+
let getSubst2 = function(value) {
|
|
504
|
+
var substChar = value[0] == "0" ? "1" : "0";
|
|
505
|
+
var subst = "";
|
|
506
|
+
for (var i2 = 0; i2 < value.length; i2++) {
|
|
507
|
+
subst += substChar;
|
|
508
|
+
}
|
|
509
|
+
return subst;
|
|
510
|
+
};
|
|
511
|
+
var matches = [];
|
|
512
|
+
var replaceName = splitter instanceof RegExp ? "replace" : "replaceAll";
|
|
513
|
+
self[replaceName](splitter, function(m2, i2, e) {
|
|
514
|
+
matches.push({ value: m2, index: i2 });
|
|
515
|
+
return getSubst2(m2);
|
|
516
|
+
});
|
|
517
|
+
var lastIndex = 0;
|
|
518
|
+
for (var i = 0; i < matches.length; i++) {
|
|
519
|
+
var m = matches[i];
|
|
520
|
+
var nextIndex = ahead == true ? m.index : m.index + m.value.length;
|
|
521
|
+
if (nextIndex != lastIndex) {
|
|
522
|
+
var part = self.substring(lastIndex, nextIndex);
|
|
523
|
+
result.push(part);
|
|
524
|
+
lastIndex = nextIndex;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
if (lastIndex < self.length) {
|
|
528
|
+
var part = self.substring(lastIndex, self.length);
|
|
529
|
+
result.push(part);
|
|
530
|
+
}
|
|
531
|
+
} else {
|
|
532
|
+
result.add(self);
|
|
533
|
+
}
|
|
534
|
+
return result;
|
|
535
|
+
};
|
|
536
|
+
var EIMZOClient = {
|
|
537
|
+
NEW_API: false,
|
|
538
|
+
NEW_API2: false,
|
|
539
|
+
API_KEYS: [
|
|
540
|
+
"localhost",
|
|
541
|
+
"96D0C1491615C82B9A54D9989779DF825B690748224C2B04F500F370D51827CE2644D8D4A82C18184D73AB8530BB8ED537269603F61DB0D03D2104ABF789970B",
|
|
542
|
+
"127.0.0.1",
|
|
543
|
+
"A7BCFA5D490B351BE0754130DF03A068F855DB4333D43921125B9CF2670EF6A40370C646B90401955E1F7BC9CDBF59CE0B2C5467D820BE189C845D0B79CFC96F"
|
|
544
|
+
],
|
|
545
|
+
checkVersion: function(success, fail) {
|
|
546
|
+
CAPIWS.version(function(event, data) {
|
|
547
|
+
if (data.success === true) {
|
|
548
|
+
if (data.major && data.minor) {
|
|
549
|
+
var installedVersion = parseInt(data.major) * 100 + parseInt(data.minor);
|
|
550
|
+
EIMZOClient.NEW_API = installedVersion >= 336;
|
|
551
|
+
EIMZOClient.NEW_API2 = installedVersion >= 412;
|
|
552
|
+
success(data.major, data.minor);
|
|
553
|
+
} else {
|
|
554
|
+
fail(null, "E-IMZO Version is undefined");
|
|
555
|
+
}
|
|
556
|
+
} else {
|
|
557
|
+
fail(null, data.reason);
|
|
558
|
+
}
|
|
559
|
+
}, function(e) {
|
|
560
|
+
fail(e, null);
|
|
561
|
+
});
|
|
562
|
+
},
|
|
563
|
+
installApiKeys: function(success, fail) {
|
|
564
|
+
CAPIWS.apikey(EIMZOClient.API_KEYS, function(event, data) {
|
|
565
|
+
if (data.success) {
|
|
566
|
+
success();
|
|
567
|
+
} else {
|
|
568
|
+
fail(null, data.reason);
|
|
569
|
+
}
|
|
570
|
+
}, function(e) {
|
|
571
|
+
fail(e, null);
|
|
572
|
+
});
|
|
573
|
+
},
|
|
574
|
+
listAllUserKeys: function(itemIdGen, itemUiGen, success, fail) {
|
|
575
|
+
var items = [];
|
|
576
|
+
var errors = [];
|
|
577
|
+
if (!EIMZOClient.NEW_API) {
|
|
578
|
+
fail(null, "Please install new version of E-IMZO");
|
|
579
|
+
} else {
|
|
580
|
+
if (EIMZOClient.NEW_API2) {
|
|
581
|
+
EIMZOClient._findPfxs2(itemIdGen, itemUiGen, items, errors, function(firstItmId2) {
|
|
582
|
+
if (items.length === 0 && errors.length > 0) {
|
|
583
|
+
fail(errors[0].e, errors[0].r);
|
|
584
|
+
} else {
|
|
585
|
+
var firstId = null;
|
|
586
|
+
if (items.length === 1) {
|
|
587
|
+
if (firstItmId2) {
|
|
588
|
+
firstId = firstItmId2;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
success(items, firstId);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
} else {
|
|
595
|
+
EIMZOClient._findPfxs2(itemIdGen, itemUiGen, items, errors, function(firstItmId2) {
|
|
596
|
+
EIMZOClient._findTokens2(itemIdGen, itemUiGen, items, errors, function(firstItmId3) {
|
|
597
|
+
if (items.length === 0 && errors.length > 0) {
|
|
598
|
+
fail(errors[0].e, errors[0].r);
|
|
599
|
+
} else {
|
|
600
|
+
var firstId = null;
|
|
601
|
+
if (items.length === 1) {
|
|
602
|
+
if (firstItmId2) {
|
|
603
|
+
firstId = firstItmId2;
|
|
604
|
+
} else if (firstItmId3) {
|
|
605
|
+
firstId = firstItmId3;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
success(items, firstId);
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
},
|
|
615
|
+
idCardIsPLuggedIn: function(success, fail) {
|
|
616
|
+
if (!EIMZOClient.NEW_API2) {
|
|
617
|
+
success(false);
|
|
618
|
+
} else {
|
|
619
|
+
CAPIWS.callFunction({ plugin: "idcard", name: "list_readers" }, function(event, data) {
|
|
620
|
+
if (data.success) {
|
|
621
|
+
success(data.readers.length > 0);
|
|
622
|
+
} else {
|
|
623
|
+
fail(null, data.reason);
|
|
624
|
+
}
|
|
625
|
+
}, function(e) {
|
|
626
|
+
fail(e, null);
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
},
|
|
630
|
+
loadKey: function(itemObject, success, fail, verifyPassword) {
|
|
631
|
+
if (itemObject) {
|
|
632
|
+
var vo = itemObject;
|
|
633
|
+
if (vo.type === "pfx") {
|
|
634
|
+
CAPIWS.callFunction({
|
|
635
|
+
plugin: "pfx",
|
|
636
|
+
name: "load_key",
|
|
637
|
+
arguments: [vo.disk, vo.path, vo.name, vo.alias]
|
|
638
|
+
}, function(event, data) {
|
|
639
|
+
if (data.success) {
|
|
640
|
+
var id = data.keyId;
|
|
641
|
+
if (verifyPassword) {
|
|
642
|
+
CAPIWS.callFunction({
|
|
643
|
+
name: "verify_password",
|
|
644
|
+
plugin: "pfx",
|
|
645
|
+
arguments: [id]
|
|
646
|
+
}, function(event2, data2) {
|
|
647
|
+
if (data2.success) {
|
|
648
|
+
success(id);
|
|
649
|
+
} else {
|
|
650
|
+
fail(null, data2.reason);
|
|
651
|
+
}
|
|
652
|
+
}, function(e) {
|
|
653
|
+
fail(e, null);
|
|
654
|
+
});
|
|
655
|
+
} else {
|
|
656
|
+
success(id);
|
|
657
|
+
}
|
|
658
|
+
} else {
|
|
659
|
+
fail(null, data.reason);
|
|
660
|
+
}
|
|
661
|
+
}, function(e) {
|
|
662
|
+
fail(e, null);
|
|
663
|
+
});
|
|
664
|
+
} else if (vo.type === "ftjc") {
|
|
665
|
+
CAPIWS.callFunction({
|
|
666
|
+
plugin: "ftjc",
|
|
667
|
+
name: "load_key",
|
|
668
|
+
arguments: [vo.cardUID]
|
|
669
|
+
}, function(event, data) {
|
|
670
|
+
if (data.success) {
|
|
671
|
+
var id = data.keyId;
|
|
672
|
+
if (verifyPassword) {
|
|
673
|
+
CAPIWS.callFunction({
|
|
674
|
+
plugin: "ftjc",
|
|
675
|
+
name: "verify_pin",
|
|
676
|
+
arguments: [id, "1"]
|
|
677
|
+
}, function(event2, data2) {
|
|
678
|
+
if (data2.success) {
|
|
679
|
+
success(id);
|
|
680
|
+
} else {
|
|
681
|
+
fail(null, data2.reason);
|
|
682
|
+
}
|
|
683
|
+
}, function(e) {
|
|
684
|
+
fail(e, null);
|
|
685
|
+
});
|
|
686
|
+
} else {
|
|
687
|
+
success(id);
|
|
688
|
+
}
|
|
689
|
+
} else {
|
|
690
|
+
fail(null, data.reason);
|
|
691
|
+
}
|
|
692
|
+
}, function(e) {
|
|
693
|
+
fail(e, null);
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
},
|
|
698
|
+
changeKeyPassword: function(itemObject, success, fail) {
|
|
699
|
+
if (itemObject) {
|
|
700
|
+
var vo = itemObject;
|
|
701
|
+
if (vo.type === "pfx") {
|
|
702
|
+
CAPIWS.callFunction({
|
|
703
|
+
plugin: "pfx",
|
|
704
|
+
name: "load_key",
|
|
705
|
+
arguments: [vo.disk, vo.path, vo.name, vo.alias]
|
|
706
|
+
}, function(event, data) {
|
|
707
|
+
if (data.success) {
|
|
708
|
+
var id = data.keyId;
|
|
709
|
+
CAPIWS.callFunction({
|
|
710
|
+
name: "change_password",
|
|
711
|
+
plugin: "pfx",
|
|
712
|
+
arguments: [id]
|
|
713
|
+
}, function(event2, data2) {
|
|
714
|
+
if (data2.success) {
|
|
715
|
+
success();
|
|
716
|
+
} else {
|
|
717
|
+
fail(null, data2.reason);
|
|
718
|
+
}
|
|
719
|
+
}, function(e) {
|
|
720
|
+
fail(e, null);
|
|
721
|
+
});
|
|
722
|
+
} else {
|
|
723
|
+
fail(null, data.reason);
|
|
724
|
+
}
|
|
725
|
+
}, function(e) {
|
|
726
|
+
fail(e, null);
|
|
727
|
+
});
|
|
728
|
+
} else if (vo.type === "ftjc") {
|
|
729
|
+
CAPIWS.callFunction({
|
|
730
|
+
plugin: "ftjc",
|
|
731
|
+
name: "load_key",
|
|
732
|
+
arguments: [vo.cardUID]
|
|
733
|
+
}, function(event, data) {
|
|
734
|
+
if (data.success) {
|
|
735
|
+
var id = data.keyId;
|
|
736
|
+
CAPIWS.callFunction({
|
|
737
|
+
name: "change_pin",
|
|
738
|
+
plugin: "ftjc",
|
|
739
|
+
arguments: [id, "1"]
|
|
740
|
+
}, function(event2, data2) {
|
|
741
|
+
if (data2.success) {
|
|
742
|
+
success();
|
|
743
|
+
} else {
|
|
744
|
+
fail(null, data2.reason);
|
|
745
|
+
}
|
|
746
|
+
}, function(e) {
|
|
747
|
+
fail(e, null);
|
|
748
|
+
});
|
|
749
|
+
} else {
|
|
750
|
+
fail(null, data.reason);
|
|
751
|
+
}
|
|
752
|
+
}, function(e) {
|
|
753
|
+
fail(e, null);
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
},
|
|
758
|
+
createPkcs7: function(id, data, timestamper, success, fail, detached, isDataBase64Encoded, enableAttachTimestamp = true) {
|
|
759
|
+
var data64;
|
|
760
|
+
if (isDataBase64Encoded === true) {
|
|
761
|
+
data64 = data;
|
|
762
|
+
} else {
|
|
763
|
+
data64 = Base64.encode(data);
|
|
764
|
+
}
|
|
765
|
+
if (detached === true) {
|
|
766
|
+
detached = "yes";
|
|
767
|
+
} else {
|
|
768
|
+
detached = "no";
|
|
769
|
+
}
|
|
770
|
+
CAPIWS.callFunction({
|
|
771
|
+
plugin: "pkcs7",
|
|
772
|
+
name: "create_pkcs7",
|
|
773
|
+
arguments: [data64, id, detached]
|
|
774
|
+
}, function(event, data2) {
|
|
775
|
+
if (data2.success) {
|
|
776
|
+
var pkcs7 = data2.pkcs7_64;
|
|
777
|
+
if (timestamper) {
|
|
778
|
+
var sn = data2.signer_serial_number;
|
|
779
|
+
timestamper(data2.signature_hex, function(tst) {
|
|
780
|
+
if (enableAttachTimestamp) {
|
|
781
|
+
CAPIWS.callFunction({
|
|
782
|
+
plugin: "pkcs7",
|
|
783
|
+
name: "attach_timestamp_token_pkcs7",
|
|
784
|
+
arguments: [pkcs7, sn, tst]
|
|
785
|
+
}, function(event2, data3) {
|
|
786
|
+
if (data3.success) {
|
|
787
|
+
var pkcs7tst = data3.pkcs7_64;
|
|
788
|
+
success(pkcs7tst);
|
|
789
|
+
} else {
|
|
790
|
+
fail(null, data3.reason);
|
|
791
|
+
}
|
|
792
|
+
}, function(e) {
|
|
793
|
+
fail(e, null);
|
|
794
|
+
});
|
|
795
|
+
} else {
|
|
796
|
+
success(tst);
|
|
797
|
+
}
|
|
798
|
+
}, fail, data2.pkcs7_64);
|
|
799
|
+
} else {
|
|
800
|
+
success(pkcs7);
|
|
801
|
+
}
|
|
802
|
+
} else {
|
|
803
|
+
fail(null, data2.reason);
|
|
804
|
+
}
|
|
805
|
+
}, function(e) {
|
|
806
|
+
fail(e, null);
|
|
807
|
+
});
|
|
808
|
+
},
|
|
809
|
+
_getX500Val: function(s, f) {
|
|
810
|
+
var res = s.splitKeep(/,[A-Z]+=/g, true);
|
|
811
|
+
for (var i in res) {
|
|
812
|
+
var n = res[i].search((i > 0 ? "," : "") + f + "=");
|
|
813
|
+
if (n !== -1) {
|
|
814
|
+
return res[i].slice(n + f.length + 1 + (i > 0 ? 1 : 0));
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
return "";
|
|
818
|
+
},
|
|
819
|
+
_findPfxs2: function(itemIdGen, itemUiGen, items, errors, callback) {
|
|
820
|
+
var itmkey0;
|
|
821
|
+
CAPIWS.callFunction({ plugin: "pfx", name: "list_all_certificates" }, function(event, data) {
|
|
822
|
+
if (data.success) {
|
|
823
|
+
for (var rec in data.certificates) {
|
|
824
|
+
var el = data.certificates[rec];
|
|
825
|
+
var x500name_ex = el.alias.toUpperCase();
|
|
826
|
+
x500name_ex = x500name_ex.replace("1.2.860.3.16.1.1=", "INN=");
|
|
827
|
+
x500name_ex = x500name_ex.replace("1.2.860.3.16.1.2=", "PINFL=");
|
|
828
|
+
var vo = {
|
|
829
|
+
disk: el.disk,
|
|
830
|
+
path: el.path,
|
|
831
|
+
name: el.name,
|
|
832
|
+
alias: el.alias,
|
|
833
|
+
serialNumber: EIMZOClient._getX500Val(x500name_ex, "SERIALNUMBER"),
|
|
834
|
+
validFrom: new Date(EIMZOClient._getX500Val(x500name_ex, "VALIDFROM").replace(/\./g, "-").replace(" ", "T")),
|
|
835
|
+
validTo: new Date(EIMZOClient._getX500Val(x500name_ex, "VALIDTO").replace(/\./g, "-").replace(" ", "T")),
|
|
836
|
+
CN: EIMZOClient._getX500Val(x500name_ex, "CN"),
|
|
837
|
+
TIN: EIMZOClient._getX500Val(x500name_ex, "INN") ? EIMZOClient._getX500Val(x500name_ex, "INN") : EIMZOClient._getX500Val(x500name_ex, "UID"),
|
|
838
|
+
UID: EIMZOClient._getX500Val(x500name_ex, "UID"),
|
|
839
|
+
PINFL: EIMZOClient._getX500Val(x500name_ex, "PINFL"),
|
|
840
|
+
O: EIMZOClient._getX500Val(x500name_ex, "O"),
|
|
841
|
+
T: EIMZOClient._getX500Val(x500name_ex, "T"),
|
|
842
|
+
type: "pfx"
|
|
843
|
+
};
|
|
844
|
+
if (!vo.TIN && !vo.PINFL)
|
|
845
|
+
continue;
|
|
846
|
+
var itmkey = itemIdGen(vo, rec);
|
|
847
|
+
if (!itmkey0) {
|
|
848
|
+
itmkey0 = itmkey;
|
|
849
|
+
}
|
|
850
|
+
var itm = itemUiGen(itmkey, vo);
|
|
851
|
+
items.push(itm);
|
|
852
|
+
}
|
|
853
|
+
} else {
|
|
854
|
+
errors.push({ r: data.reason });
|
|
855
|
+
}
|
|
856
|
+
callback(itmkey0);
|
|
857
|
+
}, function(e) {
|
|
858
|
+
errors.push({ e });
|
|
859
|
+
callback(itmkey0);
|
|
860
|
+
});
|
|
861
|
+
},
|
|
862
|
+
_findTokens2: function(itemIdGen, itemUiGen, items, errors, callback) {
|
|
863
|
+
var itmkey0;
|
|
864
|
+
CAPIWS.callFunction({ plugin: "ftjc", name: "list_all_keys", arguments: [""] }, function(event, data) {
|
|
865
|
+
if (data.success) {
|
|
866
|
+
for (var rec in data.tokens) {
|
|
867
|
+
var el = data.tokens[rec];
|
|
868
|
+
var x500name_ex = el.info.toUpperCase();
|
|
869
|
+
x500name_ex = x500name_ex.replace("1.2.860.3.16.1.1=", "INN=");
|
|
870
|
+
x500name_ex = x500name_ex.replace("1.2.860.3.16.1.2=", "PINFL=");
|
|
871
|
+
var vo = {
|
|
872
|
+
cardUID: el.cardUID,
|
|
873
|
+
statusInfo: el.statusInfo,
|
|
874
|
+
ownerName: el.ownerName,
|
|
875
|
+
info: el.info,
|
|
876
|
+
serialNumber: EIMZOClient._getX500Val(x500name_ex, "SERIALNUMBER"),
|
|
877
|
+
validFrom: new Date(EIMZOClient._getX500Val(x500name_ex, "VALIDFROM")),
|
|
878
|
+
validTo: new Date(EIMZOClient._getX500Val(x500name_ex, "VALIDTO")),
|
|
879
|
+
CN: EIMZOClient._getX500Val(x500name_ex, "CN"),
|
|
880
|
+
TIN: EIMZOClient._getX500Val(x500name_ex, "INN") ? EIMZOClient._getX500Val(x500name_ex, "INN") : EIMZOClient._getX500Val(x500name_ex, "UID"),
|
|
881
|
+
UID: EIMZOClient._getX500Val(x500name_ex, "UID"),
|
|
882
|
+
PINFL: EIMZOClient._getX500Val(x500name_ex, "PINFL"),
|
|
883
|
+
O: EIMZOClient._getX500Val(x500name_ex, "O"),
|
|
884
|
+
T: EIMZOClient._getX500Val(x500name_ex, "T"),
|
|
885
|
+
type: "ftjc"
|
|
886
|
+
};
|
|
887
|
+
if (!vo.TIN && !vo.PINFL)
|
|
888
|
+
continue;
|
|
889
|
+
var itmkey = itemIdGen(vo, rec);
|
|
890
|
+
if (!itmkey0) {
|
|
891
|
+
itmkey0 = itmkey;
|
|
892
|
+
}
|
|
893
|
+
var itm = itemUiGen(itmkey, vo);
|
|
894
|
+
items.push(itm);
|
|
895
|
+
}
|
|
896
|
+
} else {
|
|
897
|
+
errors.push({ r: data.reason });
|
|
898
|
+
}
|
|
899
|
+
callback(itmkey0);
|
|
900
|
+
}, function(e) {
|
|
901
|
+
errors.push({ e });
|
|
902
|
+
callback(itmkey0);
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
};
|
|
906
|
+
|
|
907
|
+
// src/vendor/index.ts
|
|
908
|
+
var rawClient = EIMZOClient;
|
|
909
|
+
function pickGlobal(name) {
|
|
910
|
+
const g = globalThis;
|
|
911
|
+
if (g[name] != null) return g[name];
|
|
912
|
+
const w = g["window"];
|
|
913
|
+
return w?.[name];
|
|
914
|
+
}
|
|
915
|
+
function getCapiws() {
|
|
916
|
+
const capiws = pickGlobal("CAPIWS");
|
|
917
|
+
if (!capiws || typeof capiws.callFunction !== "function") {
|
|
918
|
+
throw new EimzoError(
|
|
919
|
+
"E_NOT_INSTALLED",
|
|
920
|
+
"E-IMZO klienti yuklanmadi (window.CAPIWS topilmadi). Brauzerda ishlayotganingizni tekshiring."
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
return capiws;
|
|
924
|
+
}
|
|
925
|
+
function getBase64() {
|
|
926
|
+
const b64 = pickGlobal("Base64");
|
|
927
|
+
if (!b64 || typeof b64.encode !== "function") {
|
|
928
|
+
throw new EimzoError("E_NOT_INSTALLED", "Base64 (E-IMZO SDK) yuklanmadi.");
|
|
929
|
+
}
|
|
930
|
+
return b64;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
// src/client.ts
|
|
934
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
935
|
+
var DEFAULT_KEY_LOAD_TIMEOUT_MS = 12e4;
|
|
936
|
+
var DEFAULT_MIN_VERSION = { major: 3, minor: 37 };
|
|
937
|
+
var EimzoClient = class {
|
|
938
|
+
constructor(options) {
|
|
939
|
+
/** Faqat joriy sessiya davomida to'ldiriladi; `signBatch` oxirida tozalanadi. */
|
|
940
|
+
this.activeKeySerial = null;
|
|
941
|
+
if (!Array.isArray(options?.apiKeys) || options.apiKeys.length === 0) {
|
|
942
|
+
throw new EimzoError(
|
|
943
|
+
"E_MISCONFIGURED",
|
|
944
|
+
"EimzoClient: 'apiKeys' berilishi shart ([[domen, kalit], ...])."
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
this.apiKeys = options.apiKeys;
|
|
948
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
949
|
+
this.keyLoadTimeoutMs = options.keyLoadTimeoutMs ?? DEFAULT_KEY_LOAD_TIMEOUT_MS;
|
|
950
|
+
this.minVersion = options.minVersion ?? DEFAULT_MIN_VERSION;
|
|
951
|
+
this.onAudit = options.onAudit;
|
|
952
|
+
}
|
|
953
|
+
// ─── Commanda: o'rnatish ────────────────────────────────────────────────
|
|
954
|
+
/**
|
|
955
|
+
* Versiyani tekshiradi va domen API kalitlarini o'rnatadi.
|
|
956
|
+
* Har imzolash seansidan oldin (yoki ilova yuklanganda bir marta) chaqiring.
|
|
957
|
+
*/
|
|
958
|
+
async install() {
|
|
959
|
+
const version = await this.checkVersion();
|
|
960
|
+
if (!isVersionAtLeast(version, this.minVersion)) {
|
|
961
|
+
throw new EimzoError(
|
|
962
|
+
"E_VERSION_LOW",
|
|
963
|
+
`E-IMZO ${version.major}.${version.minor} \u2014 kamida ${this.minVersion.major}.${this.minVersion.minor} talab qilinadi.`
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
rawClient.API_KEYS = this.apiKeys.flatMap(([domain, key]) => [domain, key]);
|
|
967
|
+
await this.installApiKeys();
|
|
968
|
+
return version;
|
|
969
|
+
}
|
|
970
|
+
checkVersion() {
|
|
971
|
+
return withTimeout(
|
|
972
|
+
this.timeoutMs,
|
|
973
|
+
() => new EimzoError(
|
|
974
|
+
"E_NOT_INSTALLED",
|
|
975
|
+
"E-IMZO dasturi javob bermadi (versiya so'rovi). Dastur ishga tushganini tekshiring."
|
|
976
|
+
),
|
|
977
|
+
(resolve, reject) => {
|
|
978
|
+
rawClient.checkVersion(
|
|
979
|
+
(major, minor) => {
|
|
980
|
+
this.audit({ type: "version_checked", ts: nowIso(), major, minor });
|
|
981
|
+
resolve({ major, minor });
|
|
982
|
+
},
|
|
983
|
+
(error) => reject(
|
|
984
|
+
new EimzoError("E_NOT_INSTALLED", "E-IMZO dasturi topilmadi.", {
|
|
985
|
+
cause: error
|
|
986
|
+
})
|
|
987
|
+
)
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
installApiKeys() {
|
|
993
|
+
return withTimeout(
|
|
994
|
+
this.timeoutMs,
|
|
995
|
+
() => new EimzoError("E_TIMEOUT", "API kalitlari o'rnatilmadi (javob yo'q)."),
|
|
996
|
+
(resolve, reject) => {
|
|
997
|
+
rawClient.installApiKeys(
|
|
998
|
+
() => resolve(),
|
|
999
|
+
(error) => reject(
|
|
1000
|
+
new EimzoError(
|
|
1001
|
+
"E_API_KEY_REJECTED",
|
|
1002
|
+
"Domen API kaliti rad etildi. Domen va kalit juftligini tekshiring.",
|
|
1003
|
+
{ cause: error }
|
|
1004
|
+
)
|
|
1005
|
+
)
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
);
|
|
1009
|
+
}
|
|
1010
|
+
// ─── So'rov: sertifikatlar ───────────────────────────────────────────────
|
|
1011
|
+
/** Foydalanuvchining barcha kalitlari (disk + token). ID-karta bunga kirmaydi. */
|
|
1012
|
+
listCerts() {
|
|
1013
|
+
return withTimeout(
|
|
1014
|
+
this.timeoutMs,
|
|
1015
|
+
() => new EimzoError("E_TIMEOUT", "Sertifikatlar ro'yxati javob bermadi."),
|
|
1016
|
+
(resolve, reject) => {
|
|
1017
|
+
rawClient.listAllUserKeys(
|
|
1018
|
+
(cert, index) => `${cert.serialNumber}-${index}`,
|
|
1019
|
+
(_id, cert) => cert,
|
|
1020
|
+
(items) => {
|
|
1021
|
+
const certs = items.map((raw) => normalizeCert(raw));
|
|
1022
|
+
this.audit({ type: "certs_listed", ts: nowIso(), count: certs.length });
|
|
1023
|
+
resolve(certs);
|
|
1024
|
+
},
|
|
1025
|
+
(error) => reject(
|
|
1026
|
+
new EimzoError("E_NO_CERTS", "Sertifikatlarni o'qib bo'lmadi.", {
|
|
1027
|
+
cause: error
|
|
1028
|
+
})
|
|
1029
|
+
)
|
|
1030
|
+
);
|
|
1031
|
+
}
|
|
1032
|
+
);
|
|
1033
|
+
}
|
|
1034
|
+
/** ID-karta o'quvchiga ulanganmi. Timeout'da `false` qaytaradi (xato tashlamaydi). */
|
|
1035
|
+
isIdCardPlugged() {
|
|
1036
|
+
return new Promise((resolve) => {
|
|
1037
|
+
let settled = false;
|
|
1038
|
+
const finish = (value) => {
|
|
1039
|
+
if (settled) return;
|
|
1040
|
+
settled = true;
|
|
1041
|
+
clearTimeout(timer);
|
|
1042
|
+
resolve(value);
|
|
1043
|
+
};
|
|
1044
|
+
const timer = setTimeout(() => finish(false), this.timeoutMs);
|
|
1045
|
+
try {
|
|
1046
|
+
rawClient.idCardIsPLuggedIn(
|
|
1047
|
+
(plugged) => finish(Boolean(plugged)),
|
|
1048
|
+
() => finish(false)
|
|
1049
|
+
);
|
|
1050
|
+
} catch {
|
|
1051
|
+
finish(false);
|
|
1052
|
+
}
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
/** ID-karta uchun "sertifikat" o'rnini bosuvchi belgili obyekt. */
|
|
1056
|
+
static idCardCert() {
|
|
1057
|
+
const far = new Date(Date.now() + 10 * 365 * 24 * 60 * 60 * 1e3);
|
|
1058
|
+
return {
|
|
1059
|
+
serialNumber: "IDCARD",
|
|
1060
|
+
CN: "ID card",
|
|
1061
|
+
TIN: "",
|
|
1062
|
+
UID: "",
|
|
1063
|
+
O: "",
|
|
1064
|
+
T: "",
|
|
1065
|
+
validFrom: /* @__PURE__ */ new Date(0),
|
|
1066
|
+
validTo: far,
|
|
1067
|
+
type: "idcard",
|
|
1068
|
+
raw: null
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
// ─── Commanda: partiyali imzolash ───────────────────────────────────────
|
|
1072
|
+
/**
|
|
1073
|
+
* Bitta sertifikat bilan bir nechta hujjatni imzolaydi.
|
|
1074
|
+
*
|
|
1075
|
+
* Oqim:
|
|
1076
|
+
* 1. Kalitni bir marta yuklaydi (`idcard` bo'lsa — yuklamaydi).
|
|
1077
|
+
* 2. Har hujjat uchun `create_pkcs7` ni KETMA-KET chaqiradi (parallel EMAS —
|
|
1078
|
+
* CAPIWS bitta soket).
|
|
1079
|
+
* 3. Har natijada `signer_serial_number` ni tekshiradi.
|
|
1080
|
+
* 4. Yakunda kalit holatini tozalaydi.
|
|
1081
|
+
*
|
|
1082
|
+
* Bitta hujjat xato bersa — massivda `ok:false` bilan qoladi, qolganlari davom etadi.
|
|
1083
|
+
* Foydalanuvchi bekor qilsa (`signal`) — `E_CANCELLED` tashlanadi.
|
|
1084
|
+
*/
|
|
1085
|
+
async signBatch(cert, docs, options = {}) {
|
|
1086
|
+
if (docs.length === 0) {
|
|
1087
|
+
throw new EimzoError("E_MISCONFIGURED", "Imzolash uchun hujjat berilmadi.");
|
|
1088
|
+
}
|
|
1089
|
+
assertUniqueIds(docs);
|
|
1090
|
+
const { signal, onProgress } = options;
|
|
1091
|
+
throwIfAborted(signal);
|
|
1092
|
+
const base64 = getBase64();
|
|
1093
|
+
const keyId = await this.acquireKey(cert, signal);
|
|
1094
|
+
const results = [];
|
|
1095
|
+
let signed = 0;
|
|
1096
|
+
let failed = 0;
|
|
1097
|
+
try {
|
|
1098
|
+
for (let i = 0; i < docs.length; i += 1) {
|
|
1099
|
+
throwIfAborted(signal);
|
|
1100
|
+
const doc = docs[i];
|
|
1101
|
+
onProgress?.({ done: i, total: docs.length, currentId: doc.id });
|
|
1102
|
+
this.audit({
|
|
1103
|
+
type: "sign_started",
|
|
1104
|
+
ts: nowIso(),
|
|
1105
|
+
serial: cert.serialNumber,
|
|
1106
|
+
docId: doc.id
|
|
1107
|
+
});
|
|
1108
|
+
try {
|
|
1109
|
+
const raw = await this.createPkcs7(keyId, base64.encode(doc.content), signal);
|
|
1110
|
+
const signerSerial = String(raw["signer_serial_number"] ?? "");
|
|
1111
|
+
if (cert.type !== "idcard" && normalizeSerial(signerSerial) !== normalizeSerial(cert.serialNumber)) {
|
|
1112
|
+
throw new EimzoError(
|
|
1113
|
+
"E_SERIAL_MISMATCH",
|
|
1114
|
+
"Imzolangan sertifikat seriyasi tanlangandan farq qiladi."
|
|
1115
|
+
);
|
|
1116
|
+
}
|
|
1117
|
+
results.push({
|
|
1118
|
+
id: doc.id,
|
|
1119
|
+
ok: true,
|
|
1120
|
+
pkcs7_64: String(raw["pkcs7_64"] ?? ""),
|
|
1121
|
+
signature_hex: String(raw["signature_hex"] ?? ""),
|
|
1122
|
+
signer_serial_number: signerSerial
|
|
1123
|
+
});
|
|
1124
|
+
signed += 1;
|
|
1125
|
+
this.audit({
|
|
1126
|
+
type: "sign_ok",
|
|
1127
|
+
ts: nowIso(),
|
|
1128
|
+
serial: cert.serialNumber,
|
|
1129
|
+
docId: doc.id
|
|
1130
|
+
});
|
|
1131
|
+
} catch (error) {
|
|
1132
|
+
if (EimzoError.is(error, "E_CANCELLED")) throw error;
|
|
1133
|
+
const err = toEimzoError(error, "E_SIGN_FAILED", "Hujjatni imzolab bo'lmadi.");
|
|
1134
|
+
results.push({ id: doc.id, ok: false, error: err });
|
|
1135
|
+
failed += 1;
|
|
1136
|
+
this.audit({
|
|
1137
|
+
type: "sign_failed",
|
|
1138
|
+
ts: nowIso(),
|
|
1139
|
+
docId: doc.id,
|
|
1140
|
+
code: err.code
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
onProgress?.({ done: docs.length, total: docs.length });
|
|
1145
|
+
return results;
|
|
1146
|
+
} finally {
|
|
1147
|
+
this.activeKeySerial = null;
|
|
1148
|
+
this.audit({
|
|
1149
|
+
type: "session_ended",
|
|
1150
|
+
ts: nowIso(),
|
|
1151
|
+
serial: cert.serialNumber,
|
|
1152
|
+
signed,
|
|
1153
|
+
failed
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
/** Yagona hujjatni imzolash — `signBatch` ustidagi qulaylik. */
|
|
1158
|
+
async sign(cert, content, options = {}) {
|
|
1159
|
+
const [item] = await this.signBatch(cert, [{ id: "single", content }], options);
|
|
1160
|
+
return item;
|
|
1161
|
+
}
|
|
1162
|
+
// ─── Ichki ─────────────────────────────────────────────────────────────
|
|
1163
|
+
async acquireKey(cert, signal) {
|
|
1164
|
+
if (cert.type === "idcard") return "idcard";
|
|
1165
|
+
try {
|
|
1166
|
+
return await this.loadKey(cert, signal);
|
|
1167
|
+
} catch (error) {
|
|
1168
|
+
throw toEimzoError(
|
|
1169
|
+
error,
|
|
1170
|
+
"E_KEY_LOAD_CANCELLED",
|
|
1171
|
+
"Kalit yuklanmadi yoki bekor qilindi."
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
loadKey(cert, signal) {
|
|
1176
|
+
return withTimeout(
|
|
1177
|
+
this.keyLoadTimeoutMs,
|
|
1178
|
+
() => new EimzoError(
|
|
1179
|
+
"E_KEY_LOAD_CANCELLED",
|
|
1180
|
+
"Kalit yuklash javob bermadi (parol oynasi ochilmadi yoki yopilmadi)."
|
|
1181
|
+
),
|
|
1182
|
+
(resolve, reject) => {
|
|
1183
|
+
rawClient.loadKey(
|
|
1184
|
+
cert.raw,
|
|
1185
|
+
(id) => {
|
|
1186
|
+
this.activeKeySerial = cert.serialNumber;
|
|
1187
|
+
this.audit({
|
|
1188
|
+
type: "key_loaded",
|
|
1189
|
+
ts: nowIso(),
|
|
1190
|
+
serial: cert.serialNumber
|
|
1191
|
+
});
|
|
1192
|
+
resolve(id);
|
|
1193
|
+
},
|
|
1194
|
+
(error) => reject(
|
|
1195
|
+
new EimzoError("E_KEY_LOAD_CANCELLED", "Kalit yuklanmadi.", {
|
|
1196
|
+
cause: error
|
|
1197
|
+
})
|
|
1198
|
+
)
|
|
1199
|
+
);
|
|
1200
|
+
},
|
|
1201
|
+
signal
|
|
1202
|
+
);
|
|
1203
|
+
}
|
|
1204
|
+
createPkcs7(keyId, contentBase64, signal) {
|
|
1205
|
+
return withTimeout(
|
|
1206
|
+
this.timeoutMs,
|
|
1207
|
+
() => new EimzoError("E_TIMEOUT", "Imzolash javob bermadi (create_pkcs7)."),
|
|
1208
|
+
(resolve, reject) => {
|
|
1209
|
+
let capiws;
|
|
1210
|
+
try {
|
|
1211
|
+
capiws = getCapiws();
|
|
1212
|
+
} catch (error) {
|
|
1213
|
+
reject(error);
|
|
1214
|
+
return;
|
|
1215
|
+
}
|
|
1216
|
+
capiws.callFunction(
|
|
1217
|
+
{
|
|
1218
|
+
plugin: "pkcs7",
|
|
1219
|
+
name: "create_pkcs7",
|
|
1220
|
+
arguments: [contentBase64, keyId, "no"]
|
|
1221
|
+
},
|
|
1222
|
+
(_event, data) => {
|
|
1223
|
+
if (data && data.success) {
|
|
1224
|
+
resolve(data);
|
|
1225
|
+
} else {
|
|
1226
|
+
reject(
|
|
1227
|
+
new EimzoError(
|
|
1228
|
+
"E_SIGN_FAILED",
|
|
1229
|
+
reasonOf(data) || "E-IMZO imzolashni rad etdi.",
|
|
1230
|
+
{ cause: data }
|
|
1231
|
+
)
|
|
1232
|
+
);
|
|
1233
|
+
}
|
|
1234
|
+
},
|
|
1235
|
+
(error) => reject(
|
|
1236
|
+
new EimzoError("E_TRANSPORT", "E-IMZO bilan aloqa uzildi.", {
|
|
1237
|
+
cause: error
|
|
1238
|
+
})
|
|
1239
|
+
)
|
|
1240
|
+
);
|
|
1241
|
+
},
|
|
1242
|
+
signal
|
|
1243
|
+
);
|
|
1244
|
+
}
|
|
1245
|
+
audit(event) {
|
|
1246
|
+
if (!this.onAudit) return;
|
|
1247
|
+
try {
|
|
1248
|
+
this.onAudit(event);
|
|
1249
|
+
} catch {
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
};
|
|
1253
|
+
function isVersionAtLeast(actual, min) {
|
|
1254
|
+
if (actual.major !== min.major) return actual.major > min.major;
|
|
1255
|
+
return actual.minor >= min.minor;
|
|
1256
|
+
}
|
|
1257
|
+
function reasonOf(data) {
|
|
1258
|
+
return data && typeof data.reason === "string" ? data.reason : "";
|
|
1259
|
+
}
|
|
1260
|
+
var KNOWN_TYPES = /* @__PURE__ */ new Set(["pfx", "ftjc", "idcard"]);
|
|
1261
|
+
function normalizeCert(raw) {
|
|
1262
|
+
return {
|
|
1263
|
+
serialNumber: normalizeSerial(raw.serialNumber),
|
|
1264
|
+
CN: str(raw.CN),
|
|
1265
|
+
TIN: str(raw.TIN),
|
|
1266
|
+
UID: str(raw.UID),
|
|
1267
|
+
O: str(raw.O),
|
|
1268
|
+
T: str(raw.T),
|
|
1269
|
+
validFrom: toDate(raw.validFrom),
|
|
1270
|
+
validTo: toDate(raw.validTo),
|
|
1271
|
+
type: KNOWN_TYPES.has(raw.type) ? raw.type : "pfx",
|
|
1272
|
+
raw
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
function str(value) {
|
|
1276
|
+
return value == null ? "" : String(value);
|
|
1277
|
+
}
|
|
1278
|
+
function toDate(value) {
|
|
1279
|
+
if (value instanceof Date) return value;
|
|
1280
|
+
const d = new Date(String(value ?? ""));
|
|
1281
|
+
return Number.isNaN(d.getTime()) ? /* @__PURE__ */ new Date(0) : d;
|
|
1282
|
+
}
|
|
1283
|
+
function assertUniqueIds(docs) {
|
|
1284
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1285
|
+
for (const doc of docs) {
|
|
1286
|
+
if (!doc.id) {
|
|
1287
|
+
throw new EimzoError("E_MISCONFIGURED", "Har bir hujjatda id bo'lishi shart.");
|
|
1288
|
+
}
|
|
1289
|
+
if (seen.has(doc.id)) {
|
|
1290
|
+
throw new EimzoError("E_MISCONFIGURED", `Hujjat id'si takrorlangan: ${doc.id}`);
|
|
1291
|
+
}
|
|
1292
|
+
seen.add(doc.id);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
// src/cert-utils.ts
|
|
1297
|
+
function certIsExpired(cert, at = /* @__PURE__ */ new Date()) {
|
|
1298
|
+
return cert.validTo.getTime() < at.getTime();
|
|
1299
|
+
}
|
|
1300
|
+
function certIsNotYetValid(cert, at = /* @__PURE__ */ new Date()) {
|
|
1301
|
+
return cert.validFrom.getTime() > at.getTime();
|
|
1302
|
+
}
|
|
1303
|
+
function certIsUsable(cert, at = /* @__PURE__ */ new Date()) {
|
|
1304
|
+
return !certIsExpired(cert, at) && !certIsNotYetValid(cert, at);
|
|
1305
|
+
}
|
|
1306
|
+
function certExpiresSoon(cert, withinDays = 14, at = /* @__PURE__ */ new Date()) {
|
|
1307
|
+
if (certIsExpired(cert, at)) return false;
|
|
1308
|
+
const msLeft = cert.validTo.getTime() - at.getTime();
|
|
1309
|
+
return msLeft <= withinDays * 24 * 60 * 60 * 1e3;
|
|
1310
|
+
}
|
|
1311
|
+
function sortCerts(certs, at = /* @__PURE__ */ new Date()) {
|
|
1312
|
+
return [...certs].sort((a, b) => {
|
|
1313
|
+
const au = certIsUsable(a, at);
|
|
1314
|
+
const bu = certIsUsable(b, at);
|
|
1315
|
+
if (au !== bu) return au ? -1 : 1;
|
|
1316
|
+
return b.validTo.getTime() - a.validTo.getTime();
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
function dedupeCerts(certs) {
|
|
1320
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1321
|
+
const out = [];
|
|
1322
|
+
for (const cert of certs) {
|
|
1323
|
+
if (seen.has(cert.serialNumber)) continue;
|
|
1324
|
+
seen.add(cert.serialNumber);
|
|
1325
|
+
out.push(cert);
|
|
1326
|
+
}
|
|
1327
|
+
return out;
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
exports.EimzoClient = EimzoClient;
|
|
1331
|
+
exports.EimzoError = EimzoError;
|
|
1332
|
+
exports.certExpiresSoon = certExpiresSoon;
|
|
1333
|
+
exports.certIsExpired = certIsExpired;
|
|
1334
|
+
exports.certIsNotYetValid = certIsNotYetValid;
|
|
1335
|
+
exports.certIsUsable = certIsUsable;
|
|
1336
|
+
exports.dedupeCerts = dedupeCerts;
|
|
1337
|
+
exports.sortCerts = sortCerts;
|
|
1338
|
+
exports.toEimzoError = toEimzoError;
|
|
1339
|
+
//# sourceMappingURL=index.cjs.map
|
|
1340
|
+
//# sourceMappingURL=index.cjs.map
|