gws-client 1.0.2 → 1.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 CHANGED
@@ -1,746 +1,3 @@
1
- ## 简介
1
+ ## gws-client
2
2
 
3
- 用于web前端调用GZCA数字证书客户端UKEY证书应用接口,调用前需确保已安装GZCA数字证书客户端并启动,支持TypeScript。
4
-
5
- ## 1 快速开始
6
-
7
- ### 1.1 安装
8
-
9
- #### 使用包管理器
10
-
11
- Install with npm
12
-
13
- ```sh
14
- npm install gws-client --save
15
- ```
16
-
17
- Install with yarn
18
-
19
- ```sh
20
- yarn add gws-client
21
- ```
22
-
23
- Install with pnpm
24
-
25
- ```sh
26
- pnpm add gws-client
27
- ```
28
-
29
- ### 1.2 使用
30
-
31
- #### ES Module
32
-
33
- 使用包管理器
34
-
35
- ```ts
36
- import { GwsService } from "gws-client";
37
- const gwsService = new GwsService(gwsServiceConfig);
38
- ```
39
-
40
- ```ts
41
- import { createService } from "gws-client";
42
- async function foo() {
43
- const gwsService = await createService(gwsServiceConfig);
44
- }
45
- ```
46
-
47
- 使用本地文件
48
-
49
- ```ts
50
- import { GwsService } from "./index.es.js"; // SDK文件地址
51
- const gwsService = new GwsService(gwsServiceConfig);
52
- ```
53
-
54
- ```ts
55
- import { createService } from "./index.es.js"; // SDK文件地址
56
- async function foo() {
57
- const gwsService = await createService(gwsServiceConfig);
58
- }
59
- ```
60
-
61
- #### UMD
62
-
63
- ```html
64
- <script src="./index.umd.js"></script>
65
- ```
66
-
67
- ```ts
68
- const gwsService = new GWS_CLIENT.GwsService(gwsServiceConfig);
69
- ```
70
-
71
- ```ts
72
- async function foo() {
73
- const gwsService = await GWS_CLIENT.createService(gwsServiceConfig);
74
- }
75
- ```
76
-
77
- #### 实例化参数说明
78
-
79
- | 属性 | 说明 | 类型 | 默认值 |
80
- | ------------- | -------------------------- | --------------------------------------------------------------- | --------- |
81
- | isRememberPin | 可选,是否记住pin码 | `Boolean` | `false` |
82
- | pinPolicy | 可选,口令安全策略 | `0` \| `1`\| `2`\| `3` | `0` |
83
- | onOpen | 可选,socket连接成功回调 | `(event: Event) => void` | -- |
84
- | onError | 可选,socket错误时回调 | `(event: Event) => void` | -- |
85
- | onClose | 可选,socket关闭时回调 | `(event: Event) => void` | -- |
86
- | onMessage | 可选,socket收到消息时回调 | `(data: Record<string, any>) => void` | -- |
87
- | onUkeyChange | 可选,Ukey插入拔出时回调 | `(event: {type: 'remove' \| 'insert', data: CertType}) => void` | -- |
88
- | theme | 可选,弹窗主题色 | `String` | `#409eff` |
89
-
90
- #### 示例
91
-
92
- 链式调用
93
-
94
- ```ts
95
- // PKCS1签名
96
- import { createService } from "gws-client";
97
- function pkcs1Sign() {
98
- createService(gwsServiceConfig).then((gwsService) => {
99
- gwsService
100
- .pkcs1Sign({ Data: "hello world" })
101
- .then((res) => {
102
- console.log("签名值", res);
103
- })
104
- .catch((error) => {
105
- console.log("签名失败原因", error);
106
- });
107
- });
108
- }
109
- ```
110
-
111
- 同步调用
112
-
113
- ```ts
114
- // PKCS1签名
115
- import { createService } from "gws-client";
116
- async function pkcs1Sign() {
117
- try {
118
- const gwsService = await createService();
119
- const res = await gwsService.pkcs1Sign({ Data: "hello world" });
120
- console.log("签名值", res);
121
- } catch (error) {
122
- console.log("签名失败原因", error);
123
- }
124
- }
125
- ```
126
-
127
- ## 2 API接口
128
-
129
- ### 2.1 销毁
130
-
131
- 断开socket连接
132
-
133
- #### 接口名称
134
-
135
- destroy
136
-
137
- #### 函数签名
138
-
139
- ```ts
140
- type Destroy = () => void;
141
- ```
142
-
143
- ### 2.2 重启
144
-
145
- 重新连接socket,可重新传入新配置
146
-
147
- #### 接口名称
148
-
149
- restart
150
-
151
- #### 函数签名
152
-
153
- ```ts
154
- type Restart = (config?: GwsServiceConfigType) => void;
155
- ```
156
-
157
- ### 2.3 获取签名证书
158
-
159
- 获取签名证书,可获取证书CN项,证书CertB64,sn
160
-
161
- #### 接口名称
162
-
163
- getSignatureCert
164
-
165
- #### 函数签名
166
-
167
- ```ts
168
- type GetSignatureCert = (cert?: CertType) => Promise<CertType>;
169
- ```
170
-
171
- ### 2.4 获取签名证书列表
172
-
173
- 获取签名证书列表
174
-
175
- #### 接口名称
176
-
177
- getSignatureCertList
178
-
179
- #### 函数签名
180
-
181
- ```ts
182
- type GetSignatureCertList = () => Promise<CertType[]>;
183
- ```
184
-
185
- ### 2.5 获取加密证书
186
-
187
- 获取加密证书,可获取证书CN项,证书CertB64,sn
188
-
189
- #### 接口名称
190
-
191
- getEncryptionCert
192
-
193
- #### 函数签名
194
-
195
- ```ts
196
- type GetEncryptionCert = (cert?: CertType) => Promise<CertType>;
197
- ```
198
-
199
- ### 2.6 获取加密证书列表
200
-
201
- 获取加密证书列表
202
-
203
- #### 接口名称
204
-
205
- getEncryptionCertList
206
-
207
- #### 函数签名
208
-
209
- ```ts
210
- type GetEncryptionCertList = () => Promise<CertType[]>;
211
- ```
212
-
213
- ### 2.7 获取证书详情
214
-
215
- 获取证书详情,可获取证书公钥CertPublicKey,证书序列号CertSerial,证书有效期CertValidTime
216
-
217
- #### 接口名称
218
-
219
- getCertInfo
220
-
221
- #### 函数签名
222
-
223
- ```ts
224
- type GetCertInfo = (params: {
225
- CertB64: string;
226
- }) => Promise<Record<string, unknow>>;
227
- ```
228
-
229
- #### 参数说明
230
-
231
- | 属性 | 说明 | 类型 | 默认值 |
232
- | ------- | ---------------- | -------- | ------ |
233
- | CertB64 | 必填,证书Base64 | `String` | -- |
234
-
235
- ### 2.8 PKCS1签名
236
-
237
- PKCS1签名,返回签名值
238
-
239
- #### 接口名称
240
-
241
- pkcs1Sign
242
-
243
- #### 函数签名
244
-
245
- ```ts
246
- type Pkcs1Sign = (
247
- params: { Data: string; IsLogin?: string },
248
- curCert?: CertType
249
- ) => Promise<string>;
250
- ```
251
-
252
- #### 参数说明
253
-
254
- | 属性 | 说明 | 类型 | 默认值 |
255
- | ------- | ------------------ | ---------- | ------ |
256
- | Data | 必填,待签名原文 | `String` | -- |
257
- | IsLogin | 可选,证书登录状态 | `Y` \| `N` | -- |
258
-
259
- ### 2.9 PKCS1验签
260
-
261
- PKCS1验签,传入curCert时使用该证书,返回验签结果,`true`为验签成功,验签失败时返回`Promise.reject`
262
-
263
- #### 接口名称
264
-
265
- pkcs1VerifySignature
266
-
267
- #### 函数签名
268
-
269
- ```ts
270
- type Pkcs1VerifySignature = (
271
- params: {
272
- CertB64?: string;
273
- Data: string;
274
- SignData: string;
275
- },
276
- curCert?: CertType
277
- ) => Promise<boolean>;
278
- ```
279
-
280
- #### 参数说明
281
-
282
- | 属性 | 说明 | 类型 | 默认值 |
283
- | -------- | -------------------------- | -------- | ------ |
284
- | Data | 必填,待签名原文 | `String` | -- |
285
- | SignData | 必填,Base64编码的签名值 | `String` | -- |
286
- | CertB64 | 可选,Base64编码的签名证书 | `String` | -- |
287
-
288
- ### 2.10 PKCS1 B64签名
289
-
290
- PKCS1 base64签名,传入curCert时使用该证书,返回签名值
291
-
292
- #### 接口名称
293
-
294
- pkcs1Base64Sign
295
-
296
- #### 函数签名
297
-
298
- ```ts
299
- type Pkcs1Base64Sign = (params: {
300
- Data?: string;
301
- DataB64?: string;
302
- IsLogin?: string;
303
- }) => Promise<string>;
304
- ```
305
-
306
- #### 参数说明
307
-
308
- | 属性 | 说明 | 类型 | 默认值 |
309
- | ------- | ------------------------------------------------------------- | ---------- | ------ |
310
- | Data | 与DataB64二选一,待签名原文 | `String` | -- |
311
- | DataB64 | 与Data二选一 , Base64编码的待签名原文,同时存在时使用DataB64 | `String` | -- |
312
- | IsLogin | 可选,证书登录状态 | `Y` \| `N` | -- |
313
-
314
- ### 2.11 PKCS1 B64验签
315
-
316
- PKCS1 base64验签,返回验签结果,`true`为验签成功,验签失败时返回`Promise.reject`
317
-
318
- #### 接口名称
319
-
320
- pkcs1Base64VerifySignature
321
-
322
- #### 函数签名
323
-
324
- ```ts
325
- type Pkcs1Base64VerifySignature = (params: {
326
- Data?: string;
327
- DataB64?: string;
328
- SignData: string;
329
- CertB64?: string;
330
- }) => Promise<boolean>;
331
- ```
332
-
333
- #### 参数说明
334
-
335
- | 属性 | 说明 | 类型 | 默认值 |
336
- | -------- | ------------------------------------------------------------- | -------- | ------ |
337
- | Data | 与DataB64二选一,待签名原文 | `String` | -- |
338
- | DataB64 | 与Data二选一 , Base64编码的待签名原文,同时存在时使用DataB64 | `String` | -- |
339
- | SignData | 必填,Base64编码的签名值 | `String` | -- |
340
- | CertB64 | 可选,Base64编码的签名证书 | `String` | -- |
341
-
342
- ### 2.12 PKCS1哈希签名
343
-
344
- PKCS1哈希签名,返回签名值
345
-
346
- #### 接口名称
347
-
348
- pkcs1HashSign
349
-
350
- ```ts
351
- type Pkcs1HashSign = (
352
- params: {
353
- DataB64: string;
354
- HashAlg?: string;
355
- IsLogin?: string;
356
- },
357
- curCert?: CertType
358
- ) => Promise<string>;
359
- ```
360
-
361
- #### 参数说明
362
-
363
- | 属性 | 说明 | 类型 | 默认值 |
364
- | ------- | -------------------------------------- | -------------------------- | ------ |
365
- | DataB64 | 必填,Base64编码带签名原文的预处理哈希 | `String` | -- |
366
- | HashAlg | 可选,哈希算法 | `sm3` \| `sha1`\| `sha256` | `sm3` |
367
- | IsLogin | 可选,证书登录状态 | `Y` \| `N` | -- |
368
-
369
- ### 2.13 PKCS1哈希验签
370
-
371
- PKCS1哈希验签,返回验签结果,传入curCert时使用该证书,`true`为验签成功,验签失败时返回`Promise.reject`
372
-
373
- #### 接口名称
374
-
375
- pkcs1Base64VerifySignature
376
-
377
- #### 函数签名
378
-
379
- ```ts
380
- type Pkcs1Base64VerifySignature = (params: {
381
- DataB64: string;
382
- SignData: string;
383
- CertB64?: string;
384
- HashAlg?: string;
385
- }) => Promise<boolean>;
386
- ```
387
-
388
- #### 参数说明
389
-
390
- | 属性 | 说明 | 类型 | 默认值 |
391
- | -------- | ---------------------------------------- | -------------------------- | ------ |
392
- | DataB64 | 必填,Base64编码的待签名的原文预处理哈希 | `String` | -- |
393
- | SignData | 必填,签名值 | `String` | -- |
394
- | CertB64 | 可选,Base64编码的签名证书 | `String` | -- |
395
- | HashAlg | 可选,哈希算法 | `sm3` \| `sha1`\| `sha256` | `sm3` |
396
-
397
- ### 2.14 PKCS7签名
398
-
399
- PKCS7签名,返回签名值
400
-
401
- #### 接口名称
402
-
403
- pkcs7Sign
404
-
405
- #### 函数签名
406
-
407
- ```ts
408
- type Pkcs7Sign = (
409
- params: {
410
- Data?: string;
411
- DataB64?: string;
412
- IsDetached: string;
413
- IsLogin?: string;
414
- },
415
- curCert?: CertType
416
- ) => Promise<string>;
417
- ```
418
-
419
- #### 参数说明
420
-
421
- | 属性 | 说明 | 类型 | 默认值 |
422
- | ---------- | ------------------------------------------------------------- | ---------- | ------ |
423
- | Data | 与DataB64二选一,待签名原文 | `String` | -- |
424
- | DataB64 | 与Data二选一 , Base64编码的待签名原文,同时存在时使用DataB64 | `String` | -- |
425
- | IsDetached | 必填,Y为detach,N为attach,attach模式签名值带了原文 | `Y` \| `N` | -- |
426
- | IsLogin | 可选,证书登录状态 | `Y` \| `N` | -- |
427
-
428
- ### 2.15 PKCS7验签
429
-
430
- PKCS7验签,返回验签结果,传入curCert时使用该证书,`true`为验签成功,验签失败时返回`Promise.reject`
431
-
432
- #### 接口名称
433
-
434
- pkcs7VerifySignature
435
-
436
- #### 函数签名
437
-
438
- ```ts
439
- type Pkcs7VerifySignature = (params: {
440
- Data?: string;
441
- DataB64?: string;
442
- SignData: string;
443
- }) => Promise<string>;
444
- ```
445
-
446
- #### 参数说明
447
-
448
- | 属性 | 说明 | 类型 | 默认值 |
449
- | -------- | ------------------------------------------------------------- | -------- | ------ |
450
- | Data | 与DataB64二选一,待签名原文 | `String` | -- |
451
- | DataB64 | 与Data二选一 , Base64编码的待签名原文,同时存在时使用DataB64 | `String` | -- |
452
- | SignData | 必填,签名值 | `String` | -- |
453
-
454
- ### 2.16 base64编码
455
-
456
- base64编码,返回base64编码内容
457
-
458
- #### 接口名称
459
-
460
- base64Encode
461
-
462
- #### 函数签名
463
-
464
- ```ts
465
- type Base64Encode = (params: { Data: string }) => string;
466
- ```
467
-
468
- #### 参数说明
469
-
470
- | 属性 | 说明 | 类型 | 默认值 |
471
- | ---- | ---------------------- | -------- | ------ |
472
- | Data | 必填,base64待编码内容 | `String` | -- |
473
-
474
- ### 2.17 base64解码
475
-
476
- base64解码,返回base64解码内容
477
-
478
- #### 接口名称
479
-
480
- base64Decode
481
-
482
- #### 函数签名
483
-
484
- ```ts
485
- type Base64Decode = (params: { DataB64: string }) => string;
486
- ```
487
-
488
- #### 参数说明
489
-
490
- | 属性 | 说明 | 类型 | 默认值 |
491
- | ------- | ---------------------- | -------- | ------ |
492
- | DataB64 | 必填,base64待解码内容 | `String` | -- |
493
-
494
- ### 2.18 SM3哈希
495
-
496
- SM3哈希,返回SM3哈希值
497
-
498
- #### 接口名称
499
-
500
- sm3Hash
501
-
502
- #### 函数签名
503
-
504
- ```ts
505
- type Sm3Hash = (params: { Data: string }) => Promise<string>;
506
- ```
507
-
508
- #### 参数说明
509
-
510
- | 属性 | 说明 | 类型 | 默认值 |
511
- | ---- | ------------------------ | -------- | ------ |
512
- | Data | 必填,待计算杂凑值的原文 | `String` | -- |
513
-
514
- ### 2.19 SM3 B64哈希
515
-
516
- SM3 B64哈希
517
-
518
- #### 接口名称
519
-
520
- sm3HexHash
521
-
522
- #### 函数签名
523
-
524
- ```ts
525
- type Sm3HexHash = (params: { DataB64: string }) => Promise<string>;
526
- ```
527
-
528
- #### 参数说明
529
-
530
- | 属性 | 说明 | 类型 | 默认值 |
531
- | ------- | ------------------------------ | -------- | ------ |
532
- | DataB64 | 必填,待计算杂凑值的原文base64 | `String` | -- |
533
-
534
- ### 2.20 SM3 文件哈希
535
-
536
- SM3 文件哈希
537
-
538
- #### 接口名称
539
-
540
- sm3FileHash
541
-
542
- #### 函数签名
543
-
544
- ```ts
545
- type Sm3FileHash = (params: { SrcFile: string }) => Promise<string>;
546
- ```
547
-
548
- #### 参数说明
549
-
550
- | 属性 | 说明 | 类型 | 默认值 |
551
- | ------- | ------------------------------------------------------- | -------- | ------ |
552
- | SrcFile | 必填,待计算杂凑值的本地文件全路径。建议使用正斜杠(/) | `String` | -- |
553
-
554
- ### 2.21 SM3哈希加密
555
-
556
- SM3哈希加密
557
-
558
- #### 接口名称
559
-
560
- sm3HashEncryption
561
-
562
- #### 函数签名
563
-
564
- ```ts
565
- type Sm3HashEncryption = (params: {
566
- Data?: string;
567
- DataB64?: string;
568
- Key?: string;
569
- KeyB64?: string;
570
- }) => Promise<string>;
571
- ```
572
-
573
- #### 参数说明
574
-
575
- | 属性 | 说明 | 类型 | 默认值 |
576
- | ------- | ------------------------------------------------------------- | -------- | ------ |
577
- | Data | 与DataB64二选一,待加密原文 | `String` | -- |
578
- | DataB64 | 与Data二选一 , Base64编码的待加密原文,同时存在时使用DataB64 | `String` | -- |
579
- | Key | 与KeyB64二选一,密钥 | `String` | -- |
580
- | KeyB64 | 与Key二选一 , base64编码的密钥,同时存在时使用KeyB64 | `String` | -- |
581
-
582
- ### 2.22 PKCS7加密
583
-
584
- PKCS7加密,返回加密字符串
585
-
586
- #### 接口名称
587
-
588
- pkcs7Encryption
589
-
590
- #### 函数签名
591
-
592
- ```ts
593
- type Pkcs7Encryption = (params: {
594
- Data?: string;
595
- DataB64?: string;
596
- Key: string;
597
- }) => Promise<string>;
598
- ```
599
-
600
- #### 参数说明
601
-
602
- | 属性 | 说明 | 类型 | 默认值 |
603
- | ----------- | ------------------------------------------------------------- | -------- | ------ |
604
- | Data | 与DataB64二选一,待加密原文 | `String` | -- |
605
- | DataB64 | 与Data二选一 , Base64编码的待加密原文,同时存在时使用DataB64 | `String` | -- |
606
- | CertB64List | 必填,加密证书base64,多个以\|连接 | `String` | -- |
607
-
608
- ### 2.23 PKCS7解密
609
-
610
- PKCS7解密,返回解密字符串
611
-
612
- #### 接口名称
613
-
614
- pkcs7Decryption
615
-
616
- #### 函数签名
617
-
618
- ```ts
619
- type Pkcs7Decryption = (params: {
620
- DataB64: string;
621
- shouldDecodeBase64?: boolean;
622
- IsLogin?: string;
623
- }) => Promise<string>;
624
- ```
625
-
626
- #### 参数说明
627
-
628
- | 属性 | 说明 | 类型 | 默认值 |
629
- | ------------------ | ------------------------ | ---------- | ------ |
630
- | DataB64 | 必填,待解密原文 | `String` | -- |
631
- | shouldDecodeBase64 | 可选,是否需要base64解码 | `Boolean` | -- |
632
- | IsLogin | 可选,证书登录状态 | `Y` \| `N` | -- |
633
-
634
- ### 2.24 非对称加密
635
-
636
- 非对称加密,返回加密字符串
637
-
638
- #### 接口名称
639
-
640
- asymmetricDecryption
641
-
642
- #### 函数签名
643
-
644
- ```ts
645
- type AsymmetricDecryption = (params: { Data: string;IsLogin?: string }) => Promise<string>;
646
- ```
647
-
648
- #### 参数说明
649
-
650
- | 属性 | 说明 | 类型 | 默认值 |
651
- | ------- | ------------------ | ---------- | ------ |
652
- | Data | 必填,待解密原文 | `String` | -- |
653
- | CertB64 | 可选,加密证书B64 | `String` | -- |
654
- | IsLogin | 可选,证书登录状态 | `Y` \| `N` | -- |
655
-
656
- ### 2.25 非对称解密
657
-
658
- 非对称解密,返回解密字符串
659
-
660
- #### 接口名称
661
-
662
- asymmetricDecryption
663
-
664
- #### 函数签名
665
-
666
- ```ts
667
- type AsymmetricDecryption = (
668
- params: { Data: string },
669
- curCert?: CertType
670
- ) => Promise<string>;
671
- ```
672
-
673
- #### 参数说明
674
-
675
- | 属性 | 说明 | 类型 | 默认值 |
676
- | ---- | ---------------- | -------- | ------ |
677
- | Data | 必填,待解密原文 | `String` | -- |
678
-
679
- ### 2.26 SM4对称加密
680
-
681
- SM4对称加密,传入curCert时使用该证书,返回加密字符串,加密密钥
682
-
683
- #### 接口名称
684
-
685
- sm4Encryption
686
-
687
- #### 函数签名
688
-
689
- ```ts
690
- type Sm4Encryption = (params: {
691
- Data: string;
692
- }) => Promise<{ Data: string; KeyB64: string }>;
693
- ```
694
-
695
- #### 参数说明
696
-
697
- | 属性 | 说明 | 类型 | 默认值 |
698
- | ---- | ---------------- | -------- | ------ |
699
- | Data | 必填,待加密原文 | `String` | -- |
700
-
701
- #### 返回参数说明
702
-
703
- | 属性 | 说明 | 类型 |
704
- | ------ | -------------- | -------- |
705
- | Data | 加密密文 | `String` |
706
- | KeyB64 | Base64对称密钥 | `String` |
707
-
708
- ### 2.27 SM4对称解密
709
-
710
- SM4对称解密,返回解密字符串
711
-
712
- #### 接口名称
713
-
714
- sm4Decryption
715
-
716
- #### 函数签名
717
-
718
- ```ts
719
- type Sm4Decryption = (params: {
720
- Data: string;
721
- KeyB64: string;
722
- }) => Promise<string>;
723
- ```
724
-
725
- #### 参数说明
726
-
727
- | 属性 | 说明 | 类型 | 默认值 |
728
- | ------ | -------------------- | -------- | ------ |
729
- | Data | 必填,待解密原文 | `String` | -- |
730
- | KeyB64 | 必填,Base64对称密钥 | `String` | -- |
731
-
732
- ### 2.28 获取印章列表
733
-
734
- 获取印章列表,传入curCert时使用该证书,可获取印章SealId
735
-
736
- #### 接口名称
737
-
738
- getSealList
739
-
740
- #### 函数签名
741
-
742
- ```ts
743
- type getSealList = (
744
- curCert?: CertType
745
- ) => Promise<{ cert: CertType; sealList: SealType[] }>;
746
- ```
3
+ 用于WEB前端调用GZCA数字证书客户端UKEY证书应用接口,调用前需确保已安装GZCA数字证书客户端并启动,支持CommonJs、ES Module、UMD,支持TypeScript。