eimzo-sign-core 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/README.md +113 -38
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,62 +1,137 @@
1
1
  # eimzo-sign-core
2
2
 
3
- E-IMZO (O'zbekiston ARM) bilan imzolashning **framework-agnostik yadrosi**.
4
- Vue / React / vanilla — farqi yo'q.
3
+ E-IMZO bilan imzolash mantig'i **oynasiz**, framework'siz.
4
+ UI'ni o'zingiz qurasiz. Vue / React / oddiy JS — farqi yo'q.
5
5
 
6
- ## Kafolatlar
6
+ Tayyor Vue oyna kerak bo'lsa: [`eimzo-sign-vue`](https://www.npmjs.com/package/eimzo-sign-vue).
7
7
 
8
- - Har CAPIWS chaqiruvida **timeout** (osilib qolmaydi).
9
- - `signBatch` kalitni **bir marta** yuklaydi — parol bir marta so'raladi.
10
- - Har imzodan keyin **seriya raqami** tanlangan sertifikatga tekshiriladi
11
- (`E_SERIAL_MISMATCH`).
12
- - Sessiya tugagach yuklangan kalit holati JS'da **saqlanmaydi**.
13
- - `console` ga **hech narsa yozilmaydi** — barchasi `onAudit(event)` orqali,
14
- faqat `serial` / `docId` (shaxsiy ma'lumot emas).
15
- - Barcha rad etishlar `EimzoError` — barqaror `.code` bilan.
8
+ ---
16
9
 
17
- ## Foydalanish
10
+ ## O'rnatish
11
+
12
+ ```sh
13
+ npm i eimzo-sign-core
14
+ ```
15
+
16
+ ---
17
+
18
+ ## Ishlatish
18
19
 
19
20
  ```ts
20
21
  import { EimzoClient } from 'eimzo-sign-core'
21
22
 
22
23
  const eimzo = new EimzoClient({
23
- apiKeys: [['example.uz', process.env.EIMZO_KEY!]],
24
- timeoutMs: 30_000,
25
- onAudit: (e) => auditLog.write(e),
24
+ apiKeys: [['example.uz', import.meta.env.VITE_EIMZO_KEY]], // .env dan
26
25
  })
27
26
 
28
- await eimzo.install() // versiya + API kalitlari
29
- const certs = await eimzo.listCerts() // Cert[]
27
+ // 1. E-IMZO ga ulanish
28
+ await eimzo.install()
29
+
30
+ // 2. Sertifikatlar ro'yxati
31
+ const certs = await eimzo.listCerts()
32
+
33
+ // 3. Imzolash
34
+ const res = await eimzo.sign(certs[0], 'Salom dunyo')
35
+ console.log(res.pkcs7_64) // imzo — serverga shuni yuborasiz
36
+ ```
37
+
38
+ ### Bir nechta hujjat
39
+
40
+ Kalit **bir marta** yuklanadi (bitta parol):
41
+
42
+ ```ts
30
43
  const items = await eimzo.signBatch(certs[0], [
31
- { id: 'doc-1', content: xml1 },
32
- { id: 'doc-2', content: xml2 },
44
+ { id: 'a', content: xml1 },
45
+ { id: 'b', content: xml2 },
46
+ { id: 'c', content: xml3 },
33
47
  ], {
34
- signal: abortController.signal,
35
- onProgress: (p) => console.debug(p.done, '/', p.total),
48
+ onProgress: (p) => console.log(`${p.done}/${p.total}`),
36
49
  })
37
- // items: ({ id, ok:true, pkcs7_64, signature_hex, signer_serial_number } | { id, ok:false, error })[]
50
+
51
+ for (const it of items) {
52
+ if (it.ok) await api.send(it) // { id, pkcs7_64, signature_hex, signer_serial_number }
53
+ else console.warn(it.id, it.error.code) // bittasi xato bo'lsa qolganlari davom etadi
54
+ }
38
55
  ```
39
56
 
40
- ## API
57
+ ### Xatolarni ushlash
41
58
 
42
- | Metod | Qaytadi |
59
+ ```ts
60
+ import { EimzoError } from 'eimzo-sign-core'
61
+
62
+ try {
63
+ await eimzo.install()
64
+ } catch (e) {
65
+ if (EimzoError.is(e, 'E_NOT_INSTALLED')) alert('E-IMZO dasturini ishga tushiring')
66
+ else if (EimzoError.is(e, 'E_VERSION_LOW')) alert('E-IMZO ni yangilang')
67
+ else throw e
68
+ }
69
+ ```
70
+
71
+ ---
72
+
73
+ ## Metodlar
74
+
75
+ | Metod | Nima qiladi |
43
76
  |---|---|
44
- | `install()` | `{ major, minor }` yoki `E_NOT_INSTALLED` / `E_VERSION_LOW` / `E_API_KEY_REJECTED` |
45
- | `checkVersion()` | `{ major, minor }` |
46
- | `listCerts()` | `Cert[]` (normallashtirilgan; `raw` — vendor obyekti) |
47
- | `isIdCardPlugged()` | `boolean` (timeout'da `false`) |
48
- | `signBatch(cert, docs, opts?)` | `BatchSignItem[]` |
49
- | `sign(cert, content, opts?)` | `BatchSignItem` |
50
- | `EimzoClient.idCardCert()` | ID-karta uchun belgili `Cert` |
77
+ | `install()` | Versiyani tekshiradi, API kalitlarini o'rnatadi. Boshida bir marta. |
78
+ | `listCerts()` | Sertifikatlar ro'yxati (`Cert[]`) |
79
+ | `isIdCardPlugged()` | ID-karta o'quvchi ulanganmi (`boolean`) |
80
+ | `sign(cert, matn)` | Bitta hujjatni imzolaydi |
81
+ | `signBatch(cert, docs, opts?)` | Bir nechta hujjatni bitta kalit bilan imzolaydi |
82
+ | `EimzoClient.idCardCert()` | ID-karta uchun "sertifikat" obyekti |
83
+
84
+ Yordamchilar: `sortCerts` (amaldagilar tepada), `certIsUsable`, `certIsExpired`,
85
+ `certExpiresSoon`, `dedupeCerts`.
86
+
87
+ ### `signBatch` natijasi
88
+
89
+ ```ts
90
+ [
91
+ { id: 'a', ok: true, pkcs7_64, signature_hex, signer_serial_number },
92
+ { id: 'b', ok: false, error: EimzoError },
93
+ ]
94
+ ```
95
+
96
+ ---
97
+
98
+ ## Sozlamalar
99
+
100
+ ```ts
101
+ new EimzoClient({
102
+ apiKeys: [['domen', 'kalit']], // majburiy — E-IMZO beradi
103
+ timeoutMs: 30_000, // har chaqiruv uchun kutish
104
+ onAudit: (e) => log(e), // kuzatuv; kutubxona console ga yozmaydi
105
+ })
106
+ ```
107
+
108
+ ---
109
+
110
+ ## Xato kodlari
111
+
112
+ `error.code` (matnni emas):
113
+
114
+ `E_NOT_INSTALLED` · `E_VERSION_LOW` · `E_API_KEY_REJECTED` · `E_NO_CERTS` ·
115
+ `E_KEY_LOAD_CANCELLED` · `E_SERIAL_MISMATCH` · `E_SIGN_FAILED` · `E_TIMEOUT` ·
116
+ `E_CANCELLED` · `E_TRANSPORT` · `E_MISCONFIGURED`
117
+
118
+ ---
119
+
120
+ ## Nima kafolatlanadi
121
+
122
+ - Har chaqiruvda timeout bor — osilib qolmaydi.
123
+ - `signBatch` da parol bir marta so'raladi.
124
+ - Har imzodan keyin sertifikat raqami tekshiriladi (`E_SERIAL_MISMATCH`).
125
+ - Kutubxona `console` ga hech narsa yozmaydi — hammasi `onAudit` orqali,
126
+ faqat `serial` va `docId` (shaxsiy ma'lumot emas).
127
+
128
+ **Serverda tekshiring** — bu kutubxona imzo yasaydi, autentifikatsiya qilmaydi.
51
129
 
52
- Yordamchilar: `certIsExpired`, `certIsNotYetValid`, `certIsUsable`,
53
- `certExpiresSoon`, `sortCerts`, `dedupeCerts`.
130
+ ---
54
131
 
55
132
  ## Vendored SDK
56
133
 
57
- `src/vendor/` — E-IMZO rasmiy brauzer SDK'si, 3 qatorlik bundler-moslik patchi
58
- bilan. Manba, versiya, SHA-256 va yangilash tartibi:
59
- [`src/vendor/VENDOR.md`](src/vendor/VENDOR.md).
134
+ `src/vendor/` — E-IMZO rasmiy brauzer SDK'si (3–4 qatorlik bundler-moslik patchi bilan).
135
+ Manba, versiya, SHA-256: [`src/vendor/VENDOR.md`](src/vendor/VENDOR.md).
60
136
 
61
- > SSR: `install()` modul yuklanganda `window.location` ni o'qiydi — faqat
62
- > brauzerda import qiling.
137
+ > Faqat brauzerda import qiling (SSR emas).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eimzo-sign-core",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Framework-agnostik E-IMZO (O'zbekiston ARM) imzolash yadrosi: tiplangan xatolar, timeout, audit hook, serial tekshiruvi. Ishlab chiqarish muhiti uchun.",
5
5
  "license": "MIT",
6
6
  "keywords": [