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
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
(function (global) {
|
|
3
|
+
'use strict';
|
|
4
|
+
// existing version for noConflict()
|
|
5
|
+
var _Base64 = global.Base64;
|
|
6
|
+
var version = "2.1.4";
|
|
7
|
+
// if node.js, we use Buffer
|
|
8
|
+
var buffer;
|
|
9
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
10
|
+
buffer = require('buffer').Buffer;
|
|
11
|
+
}
|
|
12
|
+
// constants
|
|
13
|
+
var b64chars
|
|
14
|
+
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
15
|
+
var b64tab = function (bin) {
|
|
16
|
+
var t = {};
|
|
17
|
+
for (var i = 0, l = bin.length; i < l; i++) t[bin.charAt(i)] = i;
|
|
18
|
+
return t;
|
|
19
|
+
}(b64chars);
|
|
20
|
+
var fromCharCode = String.fromCharCode;
|
|
21
|
+
// encoder stuff
|
|
22
|
+
var cb_utob = function (c) {
|
|
23
|
+
if (c.length < 2) {
|
|
24
|
+
var cc = c.charCodeAt(0);
|
|
25
|
+
return cc < 0x80 ? c
|
|
26
|
+
: cc < 0x800 ? (fromCharCode(0xc0 | (cc >>> 6))
|
|
27
|
+
+ fromCharCode(0x80 | (cc & 0x3f)))
|
|
28
|
+
: (fromCharCode(0xe0 | ((cc >>> 12) & 0x0f))
|
|
29
|
+
+ fromCharCode(0x80 | ((cc >>> 6) & 0x3f))
|
|
30
|
+
+ fromCharCode(0x80 | (cc & 0x3f)));
|
|
31
|
+
} else {
|
|
32
|
+
var cc = 0x10000
|
|
33
|
+
+ (c.charCodeAt(0) - 0xD800) * 0x400
|
|
34
|
+
+ (c.charCodeAt(1) - 0xDC00);
|
|
35
|
+
return (fromCharCode(0xf0 | ((cc >>> 18) & 0x07))
|
|
36
|
+
+ fromCharCode(0x80 | ((cc >>> 12) & 0x3f))
|
|
37
|
+
+ fromCharCode(0x80 | ((cc >>> 6) & 0x3f))
|
|
38
|
+
+ fromCharCode(0x80 | (cc & 0x3f)));
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
|
42
|
+
var utob = function (u) {
|
|
43
|
+
return u.replace(re_utob, cb_utob);
|
|
44
|
+
};
|
|
45
|
+
var cb_encode = function (ccc) {
|
|
46
|
+
var padlen = [0, 2, 1][ccc.length % 3],
|
|
47
|
+
ord = ccc.charCodeAt(0) << 16
|
|
48
|
+
| ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8)
|
|
49
|
+
| ((ccc.length > 2 ? ccc.charCodeAt(2) : 0)),
|
|
50
|
+
chars = [
|
|
51
|
+
b64chars.charAt(ord >>> 18),
|
|
52
|
+
b64chars.charAt((ord >>> 12) & 63),
|
|
53
|
+
padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63),
|
|
54
|
+
padlen >= 1 ? '=' : b64chars.charAt(ord & 63)
|
|
55
|
+
];
|
|
56
|
+
return chars.join('');
|
|
57
|
+
};
|
|
58
|
+
var btoa = global.btoa ? function (b) {
|
|
59
|
+
return global.btoa(b);
|
|
60
|
+
} : function (b) {
|
|
61
|
+
return b.replace(/[\s\S]{1,3}/g, cb_encode);
|
|
62
|
+
};
|
|
63
|
+
var _encode = buffer
|
|
64
|
+
? function (u) {
|
|
65
|
+
return (new buffer(u)).toString('base64')
|
|
66
|
+
}
|
|
67
|
+
: function (u) {
|
|
68
|
+
return btoa(utob(u))
|
|
69
|
+
}
|
|
70
|
+
;
|
|
71
|
+
var encode = function (u, urisafe) {
|
|
72
|
+
return !urisafe
|
|
73
|
+
? _encode(u)
|
|
74
|
+
: _encode(u).replace(/[+\/]/g, function (m0) {
|
|
75
|
+
return m0 == '+' ? '-' : '_';
|
|
76
|
+
}).replace(/=/g, '');
|
|
77
|
+
};
|
|
78
|
+
var encodeURI = function (u) {
|
|
79
|
+
return encode(u, true)
|
|
80
|
+
};
|
|
81
|
+
// decoder stuff
|
|
82
|
+
var re_btou = new RegExp([
|
|
83
|
+
'[\xC0-\xDF][\x80-\xBF]',
|
|
84
|
+
'[\xE0-\xEF][\x80-\xBF]{2}',
|
|
85
|
+
'[\xF0-\xF7][\x80-\xBF]{3}'
|
|
86
|
+
].join('|'), 'g');
|
|
87
|
+
var cb_btou = function (cccc) {
|
|
88
|
+
switch (cccc.length) {
|
|
89
|
+
case 4:
|
|
90
|
+
var cp = ((0x07 & cccc.charCodeAt(0)) << 18)
|
|
91
|
+
| ((0x3f & cccc.charCodeAt(1)) << 12)
|
|
92
|
+
| ((0x3f & cccc.charCodeAt(2)) << 6)
|
|
93
|
+
| (0x3f & cccc.charCodeAt(3)),
|
|
94
|
+
offset = cp - 0x10000;
|
|
95
|
+
return (fromCharCode((offset >>> 10) + 0xD800)
|
|
96
|
+
+ fromCharCode((offset & 0x3FF) + 0xDC00));
|
|
97
|
+
case 3:
|
|
98
|
+
return fromCharCode(
|
|
99
|
+
((0x0f & cccc.charCodeAt(0)) << 12)
|
|
100
|
+
| ((0x3f & cccc.charCodeAt(1)) << 6)
|
|
101
|
+
| (0x3f & cccc.charCodeAt(2))
|
|
102
|
+
);
|
|
103
|
+
default:
|
|
104
|
+
return fromCharCode(
|
|
105
|
+
((0x1f & cccc.charCodeAt(0)) << 6)
|
|
106
|
+
| (0x3f & cccc.charCodeAt(1))
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
var btou = function (b) {
|
|
111
|
+
return b.replace(re_btou, cb_btou);
|
|
112
|
+
};
|
|
113
|
+
var cb_decode = function (cccc) {
|
|
114
|
+
var len = cccc.length,
|
|
115
|
+
padlen = len % 4,
|
|
116
|
+
n = (len > 0 ? b64tab[cccc.charAt(0)] << 18 : 0)
|
|
117
|
+
| (len > 1 ? b64tab[cccc.charAt(1)] << 12 : 0)
|
|
118
|
+
| (len > 2 ? b64tab[cccc.charAt(2)] << 6 : 0)
|
|
119
|
+
| (len > 3 ? b64tab[cccc.charAt(3)] : 0),
|
|
120
|
+
chars = [
|
|
121
|
+
fromCharCode(n >>> 16),
|
|
122
|
+
fromCharCode((n >>> 8) & 0xff),
|
|
123
|
+
fromCharCode(n & 0xff)
|
|
124
|
+
];
|
|
125
|
+
chars.length -= [0, 0, 2, 1][padlen];
|
|
126
|
+
return chars.join('');
|
|
127
|
+
};
|
|
128
|
+
var atob = global.atob ? function (a) {
|
|
129
|
+
return global.atob(a);
|
|
130
|
+
} : function (a) {
|
|
131
|
+
return a.replace(/[\s\S]{1,4}/g, cb_decode);
|
|
132
|
+
};
|
|
133
|
+
var _decode = buffer
|
|
134
|
+
? function (a) {
|
|
135
|
+
return (new buffer(a, 'base64')).toString()
|
|
136
|
+
}
|
|
137
|
+
: function (a) {
|
|
138
|
+
return btou(atob(a))
|
|
139
|
+
};
|
|
140
|
+
var decode = function (a) {
|
|
141
|
+
return _decode(
|
|
142
|
+
a.replace(/[-_]/g, function (m0) {
|
|
143
|
+
return m0 == '-' ? '+' : '/'
|
|
144
|
+
})
|
|
145
|
+
.replace(/[^A-Za-z0-9\+\/]/g, '')
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
var noConflict = function () {
|
|
149
|
+
var Base64 = global.Base64;
|
|
150
|
+
global.Base64 = _Base64;
|
|
151
|
+
return Base64;
|
|
152
|
+
};
|
|
153
|
+
// export Base64
|
|
154
|
+
global.Base64 = {
|
|
155
|
+
VERSION: version,
|
|
156
|
+
atob: atob,
|
|
157
|
+
btoa: btoa,
|
|
158
|
+
fromBase64: decode,
|
|
159
|
+
toBase64: encode,
|
|
160
|
+
utob: utob,
|
|
161
|
+
encode: encode,
|
|
162
|
+
encodeURI: encodeURI,
|
|
163
|
+
btou: btou,
|
|
164
|
+
decode: decode,
|
|
165
|
+
noConflict: noConflict
|
|
166
|
+
};
|
|
167
|
+
// if ES5 is available, make Base64.extendString() available
|
|
168
|
+
if (typeof Object.defineProperty === 'function') {
|
|
169
|
+
var noEnum = function (v) {
|
|
170
|
+
return {value: v, enumerable: false, writable: true, configurable: true};
|
|
171
|
+
};
|
|
172
|
+
global.Base64.extendString = function () {
|
|
173
|
+
Object.defineProperty(
|
|
174
|
+
String.prototype, 'fromBase64', noEnum(function () {
|
|
175
|
+
return decode(this)
|
|
176
|
+
}));
|
|
177
|
+
Object.defineProperty(
|
|
178
|
+
String.prototype, 'toBase64', noEnum(function (urisafe) {
|
|
179
|
+
return encode(this, urisafe)
|
|
180
|
+
}));
|
|
181
|
+
Object.defineProperty(
|
|
182
|
+
String.prototype, 'toBase64URI', noEnum(function () {
|
|
183
|
+
return encode(this, true)
|
|
184
|
+
}));
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
// that's it!
|
|
188
|
+
|
|
189
|
+
'use strict'
|
|
190
|
+
// existing version for noConflict()
|
|
191
|
+
var _Base64 = global.Base64
|
|
192
|
+
var version = '2.1.4'
|
|
193
|
+
// if node.js, we use Buffer
|
|
194
|
+
var buffer
|
|
195
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
196
|
+
buffer = require('buffer').Buffer
|
|
197
|
+
}
|
|
198
|
+
// constants
|
|
199
|
+
var b64chars
|
|
200
|
+
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
|
201
|
+
var b64tab = function (bin) {
|
|
202
|
+
var t = {}
|
|
203
|
+
for (var i = 0, l = bin.length; i < l; i++) t[bin.charAt(i)] = i
|
|
204
|
+
return t
|
|
205
|
+
}(b64chars)
|
|
206
|
+
var fromCharCode = String.fromCharCode
|
|
207
|
+
// encoder stuff
|
|
208
|
+
var cb_utob = function (c) {
|
|
209
|
+
if (c.length < 2) {
|
|
210
|
+
let cc = c.charCodeAt(0)
|
|
211
|
+
return cc < 0x80 ? c
|
|
212
|
+
: cc < 0x800 ? (fromCharCode(0xc0 | (cc >>> 6))
|
|
213
|
+
+ fromCharCode(0x80 | (cc & 0x3f)))
|
|
214
|
+
: (fromCharCode(0xe0 | ((cc >>> 12) & 0x0f))
|
|
215
|
+
+ fromCharCode(0x80 | ((cc >>> 6) & 0x3f))
|
|
216
|
+
+ fromCharCode(0x80 | (cc & 0x3f)))
|
|
217
|
+
} else {
|
|
218
|
+
let cc = 0x10000
|
|
219
|
+
+ (c.charCodeAt(0) - 0xD800) * 0x400
|
|
220
|
+
+ (c.charCodeAt(1) - 0xDC00)
|
|
221
|
+
return (fromCharCode(0xf0 | ((cc >>> 18) & 0x07))
|
|
222
|
+
+ fromCharCode(0x80 | ((cc >>> 12) & 0x3f))
|
|
223
|
+
+ fromCharCode(0x80 | ((cc >>> 6) & 0x3f))
|
|
224
|
+
+ fromCharCode(0x80 | (cc & 0x3f)))
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g
|
|
228
|
+
var utob = function (u) {
|
|
229
|
+
return u.replace(re_utob, cb_utob)
|
|
230
|
+
}
|
|
231
|
+
var cb_encode = function (ccc) {
|
|
232
|
+
var padlen = [0, 2, 1][ccc.length % 3],
|
|
233
|
+
ord = ccc.charCodeAt(0) << 16
|
|
234
|
+
| ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8)
|
|
235
|
+
| ((ccc.length > 2 ? ccc.charCodeAt(2) : 0)),
|
|
236
|
+
chars = [
|
|
237
|
+
b64chars.charAt(ord >>> 18),
|
|
238
|
+
b64chars.charAt((ord >>> 12) & 63),
|
|
239
|
+
padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63),
|
|
240
|
+
padlen >= 1 ? '=' : b64chars.charAt(ord & 63)
|
|
241
|
+
]
|
|
242
|
+
return chars.join('')
|
|
243
|
+
}
|
|
244
|
+
var btoa = global.btoa ? function (b) {
|
|
245
|
+
return global.btoa(b)
|
|
246
|
+
} : function (b) {
|
|
247
|
+
return b.replace(/[\s\S]{1,3}/g, cb_encode)
|
|
248
|
+
}
|
|
249
|
+
var _encode = buffer
|
|
250
|
+
? function (u) {
|
|
251
|
+
return (new buffer(u)).toString('base64')
|
|
252
|
+
}
|
|
253
|
+
: function (u) {
|
|
254
|
+
return btoa(utob(u))
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
var encode = function (u, urisafe) {
|
|
258
|
+
return !urisafe
|
|
259
|
+
? _encode(u)
|
|
260
|
+
: _encode(u).replace(/[+\/]/g, function (m0) {
|
|
261
|
+
return m0 == '+' ? '-' : '_'
|
|
262
|
+
}).replace(/=/g, '')
|
|
263
|
+
}
|
|
264
|
+
var encodeURI = function (u) {
|
|
265
|
+
return encode(u, true)
|
|
266
|
+
}
|
|
267
|
+
// decoder stuff
|
|
268
|
+
var re_btou = new RegExp([
|
|
269
|
+
'[\xC0-\xDF][\x80-\xBF]',
|
|
270
|
+
'[\xE0-\xEF][\x80-\xBF]{2}',
|
|
271
|
+
'[\xF0-\xF7][\x80-\xBF]{3}'
|
|
272
|
+
].join('|'), 'g')
|
|
273
|
+
var cb_btou = function (cccc) {
|
|
274
|
+
switch (cccc.length) {
|
|
275
|
+
case 4:
|
|
276
|
+
var cp = ((0x07 & cccc.charCodeAt(0)) << 18)
|
|
277
|
+
| ((0x3f & cccc.charCodeAt(1)) << 12)
|
|
278
|
+
| ((0x3f & cccc.charCodeAt(2)) << 6)
|
|
279
|
+
| (0x3f & cccc.charCodeAt(3)),
|
|
280
|
+
offset = cp - 0x10000
|
|
281
|
+
return (fromCharCode((offset >>> 10) + 0xD800)
|
|
282
|
+
+ fromCharCode((offset & 0x3FF) + 0xDC00))
|
|
283
|
+
case 3:
|
|
284
|
+
return fromCharCode(
|
|
285
|
+
((0x0f & cccc.charCodeAt(0)) << 12)
|
|
286
|
+
| ((0x3f & cccc.charCodeAt(1)) << 6)
|
|
287
|
+
| (0x3f & cccc.charCodeAt(2))
|
|
288
|
+
)
|
|
289
|
+
default:
|
|
290
|
+
return fromCharCode(
|
|
291
|
+
((0x1f & cccc.charCodeAt(0)) << 6)
|
|
292
|
+
| (0x3f & cccc.charCodeAt(1))
|
|
293
|
+
)
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
var btou = function (b) {
|
|
297
|
+
return b.replace(re_btou, cb_btou)
|
|
298
|
+
}
|
|
299
|
+
var cb_decode = function (cccc) {
|
|
300
|
+
var len = cccc.length,
|
|
301
|
+
padlen = len % 4,
|
|
302
|
+
n = (len > 0 ? b64tab[cccc.charAt(0)] << 18 : 0)
|
|
303
|
+
| (len > 1 ? b64tab[cccc.charAt(1)] << 12 : 0)
|
|
304
|
+
| (len > 2 ? b64tab[cccc.charAt(2)] << 6 : 0)
|
|
305
|
+
| (len > 3 ? b64tab[cccc.charAt(3)] : 0),
|
|
306
|
+
chars = [
|
|
307
|
+
fromCharCode(n >>> 16),
|
|
308
|
+
fromCharCode((n >>> 8) & 0xff),
|
|
309
|
+
fromCharCode(n & 0xff)
|
|
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
|
|
320
|
+
? function (a) {
|
|
321
|
+
return (new buffer(a, 'base64')).toString()
|
|
322
|
+
}
|
|
323
|
+
: function (a) {
|
|
324
|
+
return btou(atob(a))
|
|
325
|
+
}
|
|
326
|
+
var decode = function (a) {
|
|
327
|
+
return _decode(
|
|
328
|
+
a.replace(/[-_]/g, function (m0) {
|
|
329
|
+
return m0 == '-' ? '+' : '/'
|
|
330
|
+
})
|
|
331
|
+
.replace(/[^A-Za-z0-9\+\/]/g, '')
|
|
332
|
+
)
|
|
333
|
+
}
|
|
334
|
+
var noConflict = function () {
|
|
335
|
+
var Base64 = global.Base64
|
|
336
|
+
global.Base64 = _Base64
|
|
337
|
+
return Base64
|
|
338
|
+
}
|
|
339
|
+
// export Base64
|
|
340
|
+
global.Base64 = {
|
|
341
|
+
VERSION: version,
|
|
342
|
+
atob: atob,
|
|
343
|
+
btoa: btoa,
|
|
344
|
+
fromBase64: decode,
|
|
345
|
+
toBase64: encode,
|
|
346
|
+
utob: utob,
|
|
347
|
+
encode: encode,
|
|
348
|
+
encodeURI: encodeURI,
|
|
349
|
+
btou: btou,
|
|
350
|
+
decode: decode,
|
|
351
|
+
noConflict: noConflict
|
|
352
|
+
}
|
|
353
|
+
// if ES5 is available, make Base64.extendString() available
|
|
354
|
+
if (typeof Object.defineProperty === 'function') {
|
|
355
|
+
var noEnum = function (v) {
|
|
356
|
+
return {value: v, enumerable: false, writable: true, configurable: true}
|
|
357
|
+
}
|
|
358
|
+
global.Base64.extendString = function () {
|
|
359
|
+
Object.defineProperty(
|
|
360
|
+
String.prototype, 'fromBase64', noEnum(function () {
|
|
361
|
+
return decode(this)
|
|
362
|
+
}))
|
|
363
|
+
Object.defineProperty(
|
|
364
|
+
String.prototype, 'toBase64', noEnum(function (urisafe) {
|
|
365
|
+
return encode(this, urisafe)
|
|
366
|
+
}))
|
|
367
|
+
Object.defineProperty(
|
|
368
|
+
String.prototype, 'toBase64URI', noEnum(function () {
|
|
369
|
+
return encode(this, true)
|
|
370
|
+
}))
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
// that's it!
|
|
374
|
+
|
|
375
|
+
if (typeof window !== 'undefined') window.Base64 = global.Base64;
|
|
376
|
+
})(typeof globalThis !== 'undefined' ? globalThis : this);
|
|
377
|
+
|
|
378
|
+
globalThis.CAPIWS = (typeof EIMZOEXT !== 'undefined') ? EIMZOEXT : {
|
|
379
|
+
URL: ((typeof window !== 'undefined' ? window.location.protocol : '').toLowerCase() === "https:" ? "wss://127.0.0.1:64443" : "ws://127.0.0.1:64646") + "/service/cryptapi",
|
|
380
|
+
callFunction: function (funcDef, callback, error) {
|
|
381
|
+
if (!window.WebSocket) {
|
|
382
|
+
if (error)
|
|
383
|
+
error();
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
var socket;
|
|
387
|
+
try {
|
|
388
|
+
socket = new WebSocket(this.URL);
|
|
389
|
+
} catch (e) {
|
|
390
|
+
error(e);
|
|
391
|
+
}
|
|
392
|
+
socket.onerror = function (e) {
|
|
393
|
+
if (error)
|
|
394
|
+
error(e);
|
|
395
|
+
};
|
|
396
|
+
socket.onmessage = function (event) {
|
|
397
|
+
var data = JSON.parse(event.data);
|
|
398
|
+
socket.close();
|
|
399
|
+
callback(event, data);
|
|
400
|
+
};
|
|
401
|
+
socket.onopen = function () {
|
|
402
|
+
socket.send(JSON.stringify(funcDef));
|
|
403
|
+
};
|
|
404
|
+
},
|
|
405
|
+
version: function (callback, error) {
|
|
406
|
+
if (!window.WebSocket) {
|
|
407
|
+
if (error)
|
|
408
|
+
error();
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
var socket;
|
|
412
|
+
try {
|
|
413
|
+
socket = new WebSocket(this.URL);
|
|
414
|
+
} catch (e) {
|
|
415
|
+
error(e);
|
|
416
|
+
}
|
|
417
|
+
socket.onerror = function (e) {
|
|
418
|
+
if (error)
|
|
419
|
+
error(e);
|
|
420
|
+
};
|
|
421
|
+
socket.onmessage = function (event) {
|
|
422
|
+
var data = JSON.parse(event.data);
|
|
423
|
+
socket.close();
|
|
424
|
+
callback(event, data);
|
|
425
|
+
};
|
|
426
|
+
socket.onopen = function () {
|
|
427
|
+
var o = {name: 'version'};
|
|
428
|
+
socket.send(JSON.stringify(o));
|
|
429
|
+
};
|
|
430
|
+
},
|
|
431
|
+
apidoc: function (callback, error) {
|
|
432
|
+
if (!window.WebSocket) {
|
|
433
|
+
if (error)
|
|
434
|
+
error();
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
var socket;
|
|
438
|
+
try {
|
|
439
|
+
socket = new WebSocket(this.URL);
|
|
440
|
+
} catch (e) {
|
|
441
|
+
error(e);
|
|
442
|
+
}
|
|
443
|
+
socket.onerror = function (e) {
|
|
444
|
+
if (error)
|
|
445
|
+
error(e);
|
|
446
|
+
};
|
|
447
|
+
socket.onmessage = function (event) {
|
|
448
|
+
var data = JSON.parse(event.data);
|
|
449
|
+
socket.close();
|
|
450
|
+
callback(event, data);
|
|
451
|
+
};
|
|
452
|
+
socket.onopen = function () {
|
|
453
|
+
var o = {name: 'apidoc'};
|
|
454
|
+
socket.send(JSON.stringify(o));
|
|
455
|
+
};
|
|
456
|
+
},
|
|
457
|
+
apikey: function (domainAndKey, callback, error) {
|
|
458
|
+
if (!window.WebSocket) {
|
|
459
|
+
if (error)
|
|
460
|
+
error();
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
var socket;
|
|
464
|
+
try {
|
|
465
|
+
socket = new WebSocket(this.URL);
|
|
466
|
+
} catch (e) {
|
|
467
|
+
error(e);
|
|
468
|
+
}
|
|
469
|
+
socket.onerror = function (e) {
|
|
470
|
+
if (error)
|
|
471
|
+
error(e);
|
|
472
|
+
};
|
|
473
|
+
socket.onmessage = function (event) {
|
|
474
|
+
var data = JSON.parse(event.data);
|
|
475
|
+
socket.close();
|
|
476
|
+
callback(event, data);
|
|
477
|
+
};
|
|
478
|
+
socket.onopen = function () {
|
|
479
|
+
var o = {name: 'apikey', arguments: domainAndKey};
|
|
480
|
+
socket.send(JSON.stringify(o));
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendored E-IMZO SDK'ni yuklaydi va tiplangan yuzasini beradi.
|
|
3
|
+
*
|
|
4
|
+
* `./e-imzo.js` — side-effect: `window.CAPIWS` va `window.Base64` ni o'rnatadi.
|
|
5
|
+
* `./e-imzo-client.js` — ESM eksport `EIMZOClient`.
|
|
6
|
+
*/
|
|
7
|
+
import './e-imzo.js'
|
|
8
|
+
import { EIMZOClient } from './e-imzo-client.js'
|
|
9
|
+
|
|
10
|
+
import { EimzoError } from '../errors'
|
|
11
|
+
import type { RawCapiws, RawEimzoClient } from '../raw-types'
|
|
12
|
+
|
|
13
|
+
export const rawClient: RawEimzoClient = EIMZOClient
|
|
14
|
+
|
|
15
|
+
interface Base64Global {
|
|
16
|
+
encode(input: string): string
|
|
17
|
+
decode(input: string): string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function pickGlobal<T>(name: 'CAPIWS' | 'Base64'): T | undefined {
|
|
21
|
+
const g = globalThis as Record<string, unknown>
|
|
22
|
+
if (g[name] != null) return g[name] as T
|
|
23
|
+
const w = g['window'] as Record<string, unknown> | undefined
|
|
24
|
+
return w?.[name] as T | undefined
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** `window.CAPIWS` — E-IMZO lokal soket ko'prigi. Topilmasa E_NOT_INSTALLED. */
|
|
28
|
+
export function getCapiws(): RawCapiws {
|
|
29
|
+
const capiws = pickGlobal<RawCapiws>('CAPIWS')
|
|
30
|
+
if (!capiws || typeof capiws.callFunction !== 'function') {
|
|
31
|
+
throw new EimzoError(
|
|
32
|
+
'E_NOT_INSTALLED',
|
|
33
|
+
"E-IMZO klienti yuklanmadi (window.CAPIWS topilmadi). Brauzerda ishlayotganingizni tekshiring.",
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
return capiws
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** `window.Base64` — SDK bilan birga keladigan kodlagich. */
|
|
40
|
+
export function getBase64(): Base64Global {
|
|
41
|
+
const b64 = pickGlobal<Base64Global>('Base64')
|
|
42
|
+
if (!b64 || typeof b64.encode !== 'function') {
|
|
43
|
+
throw new EimzoError('E_NOT_INSTALLED', 'Base64 (E-IMZO SDK) yuklanmadi.')
|
|
44
|
+
}
|
|
45
|
+
return b64
|
|
46
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Vendored E-IMZO SDK — tiplarsiz JS. Faqat quyida ishlatadigan yuzani e'lon qilamiz.
|
|
2
|
+
// To'liq xom shakllar `../raw-types.ts` da.
|
|
3
|
+
|
|
4
|
+
declare module './e-imzo.js'
|
|
5
|
+
|
|
6
|
+
declare module './e-imzo-client.js' {
|
|
7
|
+
import type { RawEimzoClient } from '../raw-types'
|
|
8
|
+
export const EIMZOClient: RawEimzoClient
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface Window {
|
|
12
|
+
CAPIWS?: unknown
|
|
13
|
+
Base64?: unknown
|
|
14
|
+
EIMZOEXT?: unknown
|
|
15
|
+
}
|