imzo-agnost 1.0.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/LICENSE +15 -0
- package/README.md +340 -0
- package/dist/index.cjs +1818 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +994 -0
- package/dist/index.d.ts +994 -0
- package/dist/index.js +1823 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1807 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +101 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ulugbek Erkinov
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
14
|
+
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
15
|
+
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
# E-IMZO Agnostic Library
|
|
2
|
+
|
|
3
|
+
A modern, type-safe, plugin-based TypeScript library for working with E-IMZO
|
|
4
|
+
cryptographic operations.
|
|
5
|
+
|
|
6
|
+
## 🚀 Features
|
|
7
|
+
|
|
8
|
+
- **Plugin-based Architecture**: Modular design with separate plugins for
|
|
9
|
+
different functionality
|
|
10
|
+
- **TypeScript Support**: Full type safety and IntelliSense support
|
|
11
|
+
- **Dual API**: Both Promise-based and callback-based methods
|
|
12
|
+
- **Backward Compatibility**: Legacy client support for existing code
|
|
13
|
+
- **High Performance**: Optimized for speed and memory efficiency
|
|
14
|
+
- **Auto-completion**: Rich IDE support with comprehensive type definitions
|
|
15
|
+
|
|
16
|
+
## 📦 Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install imzo-agnost
|
|
20
|
+
# or
|
|
21
|
+
yarn add imzo-agnost
|
|
22
|
+
# or
|
|
23
|
+
pnpm add imzo-agnost
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 🎯 Quick Start
|
|
27
|
+
|
|
28
|
+
### Browser Global Objects (Legacy Support)
|
|
29
|
+
|
|
30
|
+
Kutubxonani import qilgandan keyin global obyektlar avtomatik ravishda window
|
|
31
|
+
obyektiga qo'shiladi:
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
// Import qilish (avtomatik global setup)
|
|
35
|
+
import 'imzo-agnost';
|
|
36
|
+
|
|
37
|
+
// Keyin browserda global obyektlar ishlatish mumkin
|
|
38
|
+
console.log(CAPIWS); // ✅ Original CAPIWS object
|
|
39
|
+
console.log(EIMZOClient); // ✅ Original EIMZOClient object
|
|
40
|
+
console.log(capiws); // ✅ Lowercase alias
|
|
41
|
+
console.log(eimzoApi); // ✅ Modern API
|
|
42
|
+
|
|
43
|
+
// Legacy usuli (boshqalar qilganidek)
|
|
44
|
+
CAPIWS.version(
|
|
45
|
+
(event, data) => console.log('Version:', data),
|
|
46
|
+
error => console.error('Error:', error)
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
EIMZOClient.checkVersion(
|
|
50
|
+
(major, minor) => console.log(`Version: ${major}.${minor}`),
|
|
51
|
+
(error, reason) => console.error('Error:', error || reason)
|
|
52
|
+
);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Modern Promise-based API
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { eimzoApi, pfxPlugin, pkcs7Plugin } from 'imzo-agnost';
|
|
59
|
+
|
|
60
|
+
async function signDocument() {
|
|
61
|
+
try {
|
|
62
|
+
// Initialize and check version
|
|
63
|
+
const version = await eimzoApi.initialize();
|
|
64
|
+
console.log(`E-IMZO Version: ${version.major}.${version.minor}`);
|
|
65
|
+
|
|
66
|
+
// Install API keys
|
|
67
|
+
await eimzoApi.installApiKeys();
|
|
68
|
+
|
|
69
|
+
// Get certificates
|
|
70
|
+
const certificates = await pfxPlugin.listAllCertificatesAsync();
|
|
71
|
+
|
|
72
|
+
if (certificates.certificates.length > 0) {
|
|
73
|
+
const cert = certificates.certificates[0];
|
|
74
|
+
|
|
75
|
+
// Load key
|
|
76
|
+
const keyResult = await pfxPlugin.loadKeyAsync(
|
|
77
|
+
cert.disk || '',
|
|
78
|
+
cert.path || '',
|
|
79
|
+
cert.name || '',
|
|
80
|
+
cert.alias || ''
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// Sign data
|
|
84
|
+
const data = btoa('Hello, E-IMZO!');
|
|
85
|
+
const pkcs7Result = await pkcs7Plugin.createPkcs7Async(
|
|
86
|
+
data,
|
|
87
|
+
keyResult.keyId,
|
|
88
|
+
'no'
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
console.log('Signature created:', pkcs7Result.pkcs7_64);
|
|
92
|
+
|
|
93
|
+
// Cleanup
|
|
94
|
+
await pfxPlugin.unloadKeyAsync(keyResult.keyId);
|
|
95
|
+
}
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error('Error:', error);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Legacy Callback API
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { pfxPlugin, pkcs7Plugin } from 'imzo-agnost';
|
|
106
|
+
|
|
107
|
+
pfxPlugin.listAllCertificates(
|
|
108
|
+
(event, data) => {
|
|
109
|
+
console.log('Certificates:', data);
|
|
110
|
+
// Handle success
|
|
111
|
+
},
|
|
112
|
+
error => {
|
|
113
|
+
console.error('Error:', error);
|
|
114
|
+
// Handle error
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## 🏗️ Architecture
|
|
120
|
+
|
|
121
|
+
### Core Components
|
|
122
|
+
|
|
123
|
+
1. **Plugin Base**: Abstract base class for all plugins
|
|
124
|
+
2. **Plugin Manager**: Centralized plugin registration and access
|
|
125
|
+
3. **Type Definitions**: Comprehensive TypeScript types
|
|
126
|
+
4. **Unified API**: Single entry point for all operations
|
|
127
|
+
|
|
128
|
+
### Available Plugins
|
|
129
|
+
|
|
130
|
+
| Plugin | Description | Status |
|
|
131
|
+
| ----------------- | -------------------------------- | ----------- |
|
|
132
|
+
| **PFX** | PFX key storage files | ✅ Complete |
|
|
133
|
+
| **PKCS7** | PKCS#7/CMS operations | ✅ Complete |
|
|
134
|
+
| **FTJC** | USB FT Javacard tokens | ✅ Complete |
|
|
135
|
+
| **CryptoAuth** | Low-level crypto operations | ✅ Complete |
|
|
136
|
+
| **TruststoreJKS** | JKS trust store operations | ✅ Complete |
|
|
137
|
+
| **Tunnel** | Encrypted GOST-28147 connections | ✅ Complete |
|
|
138
|
+
| **CertKey** | Electronic keys and certificates | ✅ Complete |
|
|
139
|
+
| **X509** | X.509 certificate operations | ✅ Complete |
|
|
140
|
+
| **Cipher** | Document encryption/decryption | ✅ Complete |
|
|
141
|
+
| **PKI** | Public Key Infrastructure | ✅ Complete |
|
|
142
|
+
| **PKCS10** | Certificate request generation | ✅ Complete |
|
|
143
|
+
| **IDCard** | E-IMZO ID card operations | ✅ Complete |
|
|
144
|
+
| **Truststore** | Trust store management | ✅ Complete |
|
|
145
|
+
| **CRL** | Certificate Revocation Lists | ✅ Complete |
|
|
146
|
+
| **FileIO** | File input/output operations | ✅ Complete |
|
|
147
|
+
| **TSAClient** | Timestamp token operations | ✅ Complete |
|
|
148
|
+
| **YTKS** | YTKS key storage files | ✅ Complete |
|
|
149
|
+
|
|
150
|
+
## 📖 API Reference
|
|
151
|
+
|
|
152
|
+
### EIMZOApi Class
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
const api = new EIMZOApi();
|
|
156
|
+
|
|
157
|
+
// Core methods
|
|
158
|
+
await api.initialize();
|
|
159
|
+
await api.installApiKeys();
|
|
160
|
+
await api.isIdCardPluggedIn();
|
|
161
|
+
|
|
162
|
+
// Plugin access
|
|
163
|
+
api.pfx; // PFX operations
|
|
164
|
+
api.pkcs7; // PKCS#7 operations
|
|
165
|
+
api.ftjc; // FTJC token operations
|
|
166
|
+
api.cryptoauth; // Cryptographic operations
|
|
167
|
+
api.truststoreJks; // JKS trust store
|
|
168
|
+
api.tunnel; // Encrypted connections
|
|
169
|
+
api.certkey; // Key/certificate management
|
|
170
|
+
api.x509; // X.509 operations
|
|
171
|
+
api.cipher; // Encryption/decryption
|
|
172
|
+
api.pki; // PKI operations
|
|
173
|
+
api.pkcs10; // Certificate requests
|
|
174
|
+
api.idcard; // ID card operations
|
|
175
|
+
api.truststore; // Trust store management
|
|
176
|
+
api.crl; // CRL operations
|
|
177
|
+
api.fileio; // File operations
|
|
178
|
+
api.tsaclient; // Timestamp operations
|
|
179
|
+
api.ytks; // YTKS operations
|
|
180
|
+
await api.getVersion();
|
|
181
|
+
|
|
182
|
+
// Plugin access
|
|
183
|
+
const pfx = api.getPlugin('pfx');
|
|
184
|
+
const plugins = api.getAvailablePlugins();
|
|
185
|
+
const hasPfx = api.hasPlugin('pfx');
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### PFX Plugin
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
import { pfxPlugin } from 'imzo-agnost';
|
|
192
|
+
|
|
193
|
+
// Promise API
|
|
194
|
+
await pfxPlugin.listAllCertificatesAsync();
|
|
195
|
+
await pfxPlugin.loadKeyAsync(disk, path, name, alias);
|
|
196
|
+
await pfxPlugin.unloadKeyAsync(keyId);
|
|
197
|
+
await pfxPlugin.verifyPasswordAsync(keyId);
|
|
198
|
+
|
|
199
|
+
// Callback API
|
|
200
|
+
pfxPlugin.listAllCertificates(onSuccess, onError);
|
|
201
|
+
pfxPlugin.loadKey(disk, path, name, alias, onSuccess, onError);
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### PKCS7 Plugin
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
import { pkcs7Plugin } from 'imzo-agnost';
|
|
208
|
+
|
|
209
|
+
// Promise API
|
|
210
|
+
await pkcs7Plugin.createPkcs7Async(data64, keyId, detached);
|
|
211
|
+
await pkcs7Plugin.getPkcs7AttachedInfoAsync(pkcs764);
|
|
212
|
+
await pkcs7Plugin.verifyPkcs7AttachedAsync(pkcs764, trustStoreId);
|
|
213
|
+
|
|
214
|
+
// Callback API
|
|
215
|
+
pkcs7Plugin.createPkcs7(data64, keyId, detached, onSuccess, onError);
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### FTJC Plugin
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
import { ftjcPlugin } from 'imzo-agnost';
|
|
222
|
+
|
|
223
|
+
// Promise API
|
|
224
|
+
await ftjcPlugin.listAllKeysAsync();
|
|
225
|
+
await ftjcPlugin.loadKeyAsync(cardUID);
|
|
226
|
+
await ftjcPlugin.verifyPinAsync(tokenId, pinType);
|
|
227
|
+
|
|
228
|
+
// Callback API
|
|
229
|
+
ftjcPlugin.listAllKeys(exceptCards, onSuccess, onError);
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## 🔧 Creating Custom Plugins
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import { EIMZOPlugin, RegisterPlugin } from 'imzo-agnost';
|
|
236
|
+
|
|
237
|
+
@RegisterPlugin
|
|
238
|
+
export class MyCustomPlugin extends EIMZOPlugin {
|
|
239
|
+
readonly name = 'my-custom-plugin';
|
|
240
|
+
readonly description = 'My custom E-IMZO plugin';
|
|
241
|
+
|
|
242
|
+
// Callback method
|
|
243
|
+
myMethod = (
|
|
244
|
+
param: string,
|
|
245
|
+
onSuccess: CallbackFunction<MyResponse>,
|
|
246
|
+
onError: ErrorCallback
|
|
247
|
+
): void => {
|
|
248
|
+
this.callMethod('my_method', [param], onSuccess, onError);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// Promise method
|
|
252
|
+
myMethodAsync = this.createPromiseMethod<[string], MyResponse>('my_method');
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## 🔄 Migration from Legacy Code
|
|
257
|
+
|
|
258
|
+
### Before (Legacy)
|
|
259
|
+
|
|
260
|
+
```javascript
|
|
261
|
+
CAPIWS.callFunction(
|
|
262
|
+
{
|
|
263
|
+
plugin: 'pfx',
|
|
264
|
+
name: 'list_all_certificates'
|
|
265
|
+
},
|
|
266
|
+
function (event, data) {
|
|
267
|
+
console.log(data);
|
|
268
|
+
},
|
|
269
|
+
function (error) {
|
|
270
|
+
console.error(error);
|
|
271
|
+
}
|
|
272
|
+
);
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### After (Modern)
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
// Promise style
|
|
279
|
+
const certificates = await pfxPlugin.listAllCertificatesAsync();
|
|
280
|
+
console.log(certificates);
|
|
281
|
+
|
|
282
|
+
// Or callback style (same as before)
|
|
283
|
+
pfxPlugin.listAllCertificates(
|
|
284
|
+
(event, data) => console.log(data),
|
|
285
|
+
error => console.error(error)
|
|
286
|
+
);
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## 🎯 Best Practices
|
|
290
|
+
|
|
291
|
+
1. **Use Promise API**: Prefer `async/await` for cleaner code
|
|
292
|
+
2. **Handle Errors**: Always wrap operations in try-catch blocks
|
|
293
|
+
3. **Cleanup Resources**: Unload keys when done
|
|
294
|
+
4. **Type Safety**: Leverage TypeScript types for better development experience
|
|
295
|
+
5. **Plugin Access**: Use plugin instances for better performance
|
|
296
|
+
|
|
297
|
+
## 🔍 Error Handling
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
try {
|
|
301
|
+
const result = await pfxPlugin.loadKeyAsync(disk, path, name, alias);
|
|
302
|
+
// Success
|
|
303
|
+
} catch (error) {
|
|
304
|
+
if (error.message.includes('password')) {
|
|
305
|
+
// Handle password error
|
|
306
|
+
} else {
|
|
307
|
+
// Handle other errors
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## 📋 Requirements
|
|
313
|
+
|
|
314
|
+
- E-IMZO installed on user's machine
|
|
315
|
+
- Modern browser with WebSocket support
|
|
316
|
+
- TypeScript 4.5+ (for development)
|
|
317
|
+
|
|
318
|
+
## 🤝 Contributing
|
|
319
|
+
|
|
320
|
+
1. Fork the repository
|
|
321
|
+
2. Create a feature branch
|
|
322
|
+
3. Add your plugin or improvement
|
|
323
|
+
4. Write tests
|
|
324
|
+
5. Submit a pull request
|
|
325
|
+
|
|
326
|
+
## 📄 License
|
|
327
|
+
|
|
328
|
+
MIT License - see LICENSE file for details
|
|
329
|
+
|
|
330
|
+
## 🆘 Support
|
|
331
|
+
|
|
332
|
+
For issues and questions:
|
|
333
|
+
|
|
334
|
+
- Check the [documentation](./docs)
|
|
335
|
+
- Open an [issue](https://github.com/Erkinov97/imzo-agnost/issues)
|
|
336
|
+
- Contact support
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
Made with ❤️ for the E-IMZO community
|