@islom929/react-eimzo 0.3.1 → 0.4.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 +17 -60
- package/dist/index.cjs +16 -11
- package/dist/index.js +16 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @islom929/react-eimzo
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React hook for E-IMZO digital signatures. Simple API, zero UI dependencies — works with any component library.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -19,13 +19,20 @@ import { EimzoProvider } from '@islom929/react-eimzo'
|
|
|
19
19
|
|
|
20
20
|
function App() {
|
|
21
21
|
return (
|
|
22
|
-
<EimzoProvider
|
|
22
|
+
<EimzoProvider
|
|
23
|
+
apiKeys={[
|
|
24
|
+
'yourdomain.uz', 'YOUR_PRODUCTION_API_KEY_HERE',
|
|
25
|
+
'test.yourdomain.uz', 'YOUR_TEST_API_KEY_HERE',
|
|
26
|
+
]}
|
|
27
|
+
>
|
|
23
28
|
<YourApp />
|
|
24
29
|
</EimzoProvider>
|
|
25
30
|
)
|
|
26
31
|
}
|
|
27
32
|
```
|
|
28
33
|
|
|
34
|
+
Default keys for `localhost` and `127.0.0.1` are always included.
|
|
35
|
+
|
|
29
36
|
### 2. Use the hook
|
|
30
37
|
|
|
31
38
|
```tsx
|
|
@@ -121,19 +128,15 @@ function PfxSign() {
|
|
|
121
128
|
}
|
|
122
129
|
```
|
|
123
130
|
|
|
124
|
-
### Sign with
|
|
131
|
+
### Sign with tokens
|
|
125
132
|
|
|
126
|
-
No certificate selection needed. Pass device type directly.
|
|
133
|
+
No certificate selection needed. Pass device type directly. Device status is checked automatically on mount.
|
|
127
134
|
|
|
128
135
|
```tsx
|
|
129
|
-
function
|
|
130
|
-
const { sign, deviceStatus,
|
|
131
|
-
|
|
132
|
-
useEffect(() => {
|
|
133
|
-
if (isInstalled) loadKeys()
|
|
134
|
-
}, [isInstalled])
|
|
136
|
+
function TokenSign() {
|
|
137
|
+
const { sign, deviceStatus, isLoading } = useEimzo()
|
|
135
138
|
|
|
136
|
-
const
|
|
139
|
+
const handleTokenSign = (device: 'idcard' | 'baikey' | 'ckc') => {
|
|
137
140
|
sign({
|
|
138
141
|
keyId: device,
|
|
139
142
|
data: JSON.stringify({ document: 'content' }),
|
|
@@ -145,21 +148,21 @@ function DeviceSign() {
|
|
|
145
148
|
return (
|
|
146
149
|
<div>
|
|
147
150
|
<button
|
|
148
|
-
onClick={() =>
|
|
151
|
+
onClick={() => handleTokenSign('idcard')}
|
|
149
152
|
disabled={!deviceStatus.idcard || isLoading}
|
|
150
153
|
>
|
|
151
154
|
ID Card {deviceStatus.idcard ? '(connected)' : '(not connected)'}
|
|
152
155
|
</button>
|
|
153
156
|
|
|
154
157
|
<button
|
|
155
|
-
onClick={() =>
|
|
158
|
+
onClick={() => handleTokenSign('baikey')}
|
|
156
159
|
disabled={!deviceStatus.baikey || isLoading}
|
|
157
160
|
>
|
|
158
161
|
BAIK Token {deviceStatus.baikey ? '(connected)' : '(not connected)'}
|
|
159
162
|
</button>
|
|
160
163
|
|
|
161
164
|
<button
|
|
162
|
-
onClick={() =>
|
|
165
|
+
onClick={() => handleTokenSign('ckc')}
|
|
163
166
|
disabled={!deviceStatus.ckc || isLoading}
|
|
164
167
|
>
|
|
165
168
|
CKC {deviceStatus.ckc ? '(connected)' : '(not connected)'}
|
|
@@ -241,23 +244,6 @@ function ApplicationForm() {
|
|
|
241
244
|
}
|
|
242
245
|
```
|
|
243
246
|
|
|
244
|
-
### Production API keys
|
|
245
|
-
|
|
246
|
-
Add your domain's API key for production deployment.
|
|
247
|
-
|
|
248
|
-
```tsx
|
|
249
|
-
<EimzoProvider
|
|
250
|
-
apiKeys={[
|
|
251
|
-
'yourdomain.uz', 'YOUR_PRODUCTION_API_KEY_HERE',
|
|
252
|
-
'test.yourdomain.uz', 'YOUR_TEST_API_KEY_HERE',
|
|
253
|
-
]}
|
|
254
|
-
>
|
|
255
|
-
<App />
|
|
256
|
-
</EimzoProvider>
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
Default keys for `localhost` and `127.0.0.1` are always included.
|
|
260
|
-
|
|
261
247
|
### Check E-IMZO installation
|
|
262
248
|
|
|
263
249
|
```tsx
|
|
@@ -277,35 +263,6 @@ function EimzoStatus() {
|
|
|
277
263
|
}
|
|
278
264
|
```
|
|
279
265
|
|
|
280
|
-
### Filter certificates
|
|
281
|
-
|
|
282
|
-
```tsx
|
|
283
|
-
function FilteredKeys() {
|
|
284
|
-
const { keyList, loadKeys, isInstalled } = useEimzo()
|
|
285
|
-
|
|
286
|
-
useEffect(() => {
|
|
287
|
-
if (isInstalled) loadKeys()
|
|
288
|
-
}, [isInstalled])
|
|
289
|
-
|
|
290
|
-
// Only valid (not expired) certificates
|
|
291
|
-
const validCerts = keyList.filter((cert) => !cert.expired)
|
|
292
|
-
|
|
293
|
-
// Filter by organization
|
|
294
|
-
const orgCerts = keyList.filter((cert) => cert.O === 'MY COMPANY')
|
|
295
|
-
|
|
296
|
-
// Filter by PINFL
|
|
297
|
-
const userCerts = keyList.filter((cert) => cert.PINFL === '12345678901234')
|
|
298
|
-
|
|
299
|
-
return (
|
|
300
|
-
<div>
|
|
301
|
-
<p>All: {keyList.length}</p>
|
|
302
|
-
<p>Valid: {validCerts.length}</p>
|
|
303
|
-
<p>My org: {orgCerts.length}</p>
|
|
304
|
-
</div>
|
|
305
|
-
)
|
|
306
|
-
}
|
|
307
|
-
```
|
|
308
|
-
|
|
309
266
|
## API
|
|
310
267
|
|
|
311
268
|
### EimzoProvider
|
package/dist/index.cjs
CHANGED
|
@@ -814,24 +814,29 @@ function EimzoProvider({ apiKeys, children }) {
|
|
|
814
814
|
baikey: false,
|
|
815
815
|
ckc: false
|
|
816
816
|
});
|
|
817
|
+
const checkDevices = (0, import_react.useCallback)(async () => {
|
|
818
|
+
const [idcard, baikey, ckc] = await Promise.allSettled([
|
|
819
|
+
checkIdCard(),
|
|
820
|
+
checkBaikToken(),
|
|
821
|
+
checkCkc()
|
|
822
|
+
]);
|
|
823
|
+
setDeviceStatus({
|
|
824
|
+
idcard: idcard.status === "fulfilled" && idcard.value,
|
|
825
|
+
baikey: baikey.status === "fulfilled" && baikey.value,
|
|
826
|
+
ckc: ckc.status === "fulfilled" && ckc.value
|
|
827
|
+
});
|
|
828
|
+
}, []);
|
|
817
829
|
(0, import_react.useEffect)(() => {
|
|
818
|
-
install(apiKeys).then(
|
|
830
|
+
install(apiKeys).then(async () => {
|
|
831
|
+
setIsInstalled(true);
|
|
832
|
+
await checkDevices();
|
|
833
|
+
}).catch(() => setIsInstalled(false));
|
|
819
834
|
}, []);
|
|
820
835
|
const loadKeys = (0, import_react.useCallback)(async () => {
|
|
821
836
|
setIsLoading(true);
|
|
822
837
|
try {
|
|
823
838
|
const certs = await listAllUserKeys();
|
|
824
839
|
setKeyList(certs);
|
|
825
|
-
const [idcard, baikey, ckc] = await Promise.allSettled([
|
|
826
|
-
checkIdCard(),
|
|
827
|
-
checkBaikToken(),
|
|
828
|
-
checkCkc()
|
|
829
|
-
]);
|
|
830
|
-
setDeviceStatus({
|
|
831
|
-
idcard: idcard.status === "fulfilled" && idcard.value,
|
|
832
|
-
baikey: baikey.status === "fulfilled" && baikey.value,
|
|
833
|
-
ckc: ckc.status === "fulfilled" && ckc.value
|
|
834
|
-
});
|
|
835
840
|
} catch (err) {
|
|
836
841
|
console.error("E-IMZO: Failed to load keys", err);
|
|
837
842
|
} finally {
|
package/dist/index.js
CHANGED
|
@@ -793,24 +793,29 @@ function EimzoProvider({ apiKeys, children }) {
|
|
|
793
793
|
baikey: false,
|
|
794
794
|
ckc: false
|
|
795
795
|
});
|
|
796
|
+
const checkDevices = useCallback(async () => {
|
|
797
|
+
const [idcard, baikey, ckc] = await Promise.allSettled([
|
|
798
|
+
checkIdCard(),
|
|
799
|
+
checkBaikToken(),
|
|
800
|
+
checkCkc()
|
|
801
|
+
]);
|
|
802
|
+
setDeviceStatus({
|
|
803
|
+
idcard: idcard.status === "fulfilled" && idcard.value,
|
|
804
|
+
baikey: baikey.status === "fulfilled" && baikey.value,
|
|
805
|
+
ckc: ckc.status === "fulfilled" && ckc.value
|
|
806
|
+
});
|
|
807
|
+
}, []);
|
|
796
808
|
useEffect(() => {
|
|
797
|
-
install(apiKeys).then(
|
|
809
|
+
install(apiKeys).then(async () => {
|
|
810
|
+
setIsInstalled(true);
|
|
811
|
+
await checkDevices();
|
|
812
|
+
}).catch(() => setIsInstalled(false));
|
|
798
813
|
}, []);
|
|
799
814
|
const loadKeys = useCallback(async () => {
|
|
800
815
|
setIsLoading(true);
|
|
801
816
|
try {
|
|
802
817
|
const certs = await listAllUserKeys();
|
|
803
818
|
setKeyList(certs);
|
|
804
|
-
const [idcard, baikey, ckc] = await Promise.allSettled([
|
|
805
|
-
checkIdCard(),
|
|
806
|
-
checkBaikToken(),
|
|
807
|
-
checkCkc()
|
|
808
|
-
]);
|
|
809
|
-
setDeviceStatus({
|
|
810
|
-
idcard: idcard.status === "fulfilled" && idcard.value,
|
|
811
|
-
baikey: baikey.status === "fulfilled" && baikey.value,
|
|
812
|
-
ckc: ckc.status === "fulfilled" && ckc.value
|
|
813
|
-
});
|
|
814
819
|
} catch (err) {
|
|
815
820
|
console.error("E-IMZO: Failed to load keys", err);
|
|
816
821
|
} finally {
|