Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

gws-client

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gws-client

gws client

latest
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

简介

用于web前端调用GZCA数字证书客户端UKEY证书应用接口,调用前需确保已安装GZCA数字证书客户端并启动,支持TypeScript。

1 快速开始

1.1 安装

使用包管理器

Install with npm

npm install gws-client --save

Install with yarn

yarn add gws-client

Install with pnpm

pnpm add gws-client

1.2 使用

ES Module

使用包管理器

import { GwsService } from "gws-client";
const gwsService = new GwsService(gwsServiceConfig);
import { createService } from "gws-client";
async function foo() {
  const gwsService = await createService(gwsServiceConfig);
}

使用本地文件

import { GwsService } from "./index.es.js"; // SDK文件地址
const gwsService = new GwsService(gwsServiceConfig);
import { createService } from "./index.es.js"; // SDK文件地址
async function foo() {
  const gwsService = await createService(gwsServiceConfig);
}

UMD

<script src="./index.umd.js"></script>
const gwsService = new GWS_CLIENT.GwsService(gwsServiceConfig);
async function foo() {
  const gwsService = await GWS_CLIENT.createService(gwsServiceConfig);
}

实例化参数说明

属性说明类型默认值
isRememberPin可选,是否记住pin码Booleanfalse
pinPolicy可选,口令安全策略0 | 1| 2| 30
onOpen可选,socket连接成功回调(event: Event) => void--
onError可选,socket错误时回调(event: Event) => void--
onClose可选,socket关闭时回调(event: Event) => void--
onMessage可选,socket收到消息时回调(data: Record<string, any>) => void--
onUkeyChange可选,Ukey插入拔出时回调(event: {type: 'remove' | 'insert', data: CertType}) => void--
theme可选,弹窗主题色String#409eff

示例

链式调用

// PKCS1签名
import { createService } from "gws-client";
function pkcs1Sign() {
  createService(gwsServiceConfig).then((gwsService) => {
    gwsService
      .pkcs1Sign({ Data: "hello world" })
      .then((res) => {
        console.log("签名值", res);
      })
      .catch((error) => {
        console.log("签名失败原因", error);
      });
  });
}

同步调用

// PKCS1签名
import { createService } from "gws-client";
async function pkcs1Sign() {
  try {
    const gwsService = await createService();
    const res = await gwsService.pkcs1Sign({ Data: "hello world" });
    console.log("签名值", res);
  } catch (error) {
    console.log("签名失败原因", error);
  }
}

2 API接口

2.1 销毁

断开socket连接

接口名称

destroy

函数签名

type Destroy = () => void;

2.2 重启

重新连接socket,可重新传入新配置

接口名称

restart

函数签名

type Restart = (config?: GwsServiceConfigType) => void;

2.3 获取签名证书

获取签名证书,可获取证书CN项,证书CertB64,sn

接口名称

getSignatureCert

函数签名

type GetSignatureCert = (cert?: CertType) => Promise<CertType>;

2.4 获取签名证书列表

获取签名证书列表

接口名称

getSignatureCertList

函数签名

type GetSignatureCertList = () => Promise<CertType[]>;

2.5 获取加密证书

获取加密证书,可获取证书CN项,证书CertB64,sn

接口名称

getEncryptionCert

函数签名

type GetEncryptionCert = (cert?: CertType) => Promise<CertType>;

2.6 获取加密证书列表

获取加密证书列表

接口名称

getEncryptionCertList

函数签名

type GetEncryptionCertList = () => Promise<CertType[]>;

2.7 获取证书详情

获取证书详情,可获取证书公钥CertPublicKey,证书序列号CertSerial,证书有效期CertValidTime

接口名称

getCertInfo

函数签名

type GetCertInfo = (params: {
  CertB64: string;
}) => Promise<Record<string, unknow>>;

参数说明

属性说明类型默认值
CertB64必填,证书Base64String--

2.8 PKCS1签名

PKCS1签名,返回签名值

接口名称

pkcs1Sign

函数签名

type Pkcs1Sign = (
  params: { Data: string; IsLogin?: string },
  curCert?: CertType
) => Promise<string>;

参数说明

属性说明类型默认值
Data必填,待签名原文String--
IsLogin可选,证书登录状态Y | N--

2.9 PKCS1验签

PKCS1验签,传入curCert时使用该证书,返回验签结果,true为验签成功,验签失败时返回Promise.reject

接口名称

pkcs1VerifySignature

函数签名

type Pkcs1VerifySignature = (
  params: {
    CertB64?: string;
    Data: string;
    SignData: string;
  },
  curCert?: CertType
) => Promise<boolean>;

参数说明

属性说明类型默认值
Data必填,待签名原文String--
SignData必填,Base64编码的签名值String--
CertB64可选,Base64编码的签名证书String--

2.10 PKCS1 B64签名

PKCS1 base64签名,传入curCert时使用该证书,返回签名值

接口名称

pkcs1Base64Sign

函数签名

type Pkcs1Base64Sign = (params: {
  Data?: string;
  DataB64?: string;
  IsLogin?: string;
}) => Promise<string>;

参数说明

属性说明类型默认值
Data与DataB64二选一,待签名原文String--
DataB64与Data二选一 , Base64编码的待签名原文,同时存在时使用DataB64String--
IsLogin可选,证书登录状态Y | N--

2.11 PKCS1 B64验签

PKCS1 base64验签,返回验签结果,true为验签成功,验签失败时返回Promise.reject

接口名称

pkcs1Base64VerifySignature

函数签名

type Pkcs1Base64VerifySignature = (params: {
  Data?: string;
  DataB64?: string;
  SignData: string;
  CertB64?: string;
}) => Promise<boolean>;

参数说明

属性说明类型默认值
Data与DataB64二选一,待签名原文String--
DataB64与Data二选一 , Base64编码的待签名原文,同时存在时使用DataB64String--
SignData必填,Base64编码的签名值String--
CertB64可选,Base64编码的签名证书String--

2.12 PKCS1哈希签名

PKCS1哈希签名,返回签名值

接口名称

pkcs1HashSign

type Pkcs1HashSign = (
  params: {
    DataB64: string;
    HashAlg?: string;
    IsLogin?: string;
  },
  curCert?: CertType
) => Promise<string>;

参数说明

属性说明类型默认值
DataB64必填,Base64编码带签名原文的预处理哈希String--
HashAlg可选,哈希算法sm3 | sha1| sha256sm3
IsLogin可选,证书登录状态Y | N--

2.13 PKCS1哈希验签

PKCS1哈希验签,返回验签结果,传入curCert时使用该证书,true为验签成功,验签失败时返回Promise.reject

接口名称

pkcs1Base64VerifySignature

函数签名

type Pkcs1Base64VerifySignature = (params: {
  DataB64: string;
  SignData: string;
  CertB64?: string;
  HashAlg?: string;
}) => Promise<boolean>;

参数说明

属性说明类型默认值
DataB64必填,Base64编码的待签名的原文预处理哈希String--
SignData必填,签名值String--
CertB64可选,Base64编码的签名证书String--
HashAlg可选,哈希算法sm3 | sha1| sha256sm3

2.14 PKCS7签名

PKCS7签名,返回签名值

接口名称

pkcs7Sign

函数签名

type Pkcs7Sign = (
  params: {
    Data?: string;
    DataB64?: string;
    IsDetached: string;
    IsLogin?: string;
  },
  curCert?: CertType
) => Promise<string>;

参数说明

属性说明类型默认值
Data与DataB64二选一,待签名原文String--
DataB64与Data二选一 , Base64编码的待签名原文,同时存在时使用DataB64String--
IsDetached必填,Y为detach,N为attach,attach模式签名值带了原文Y | N--
IsLogin可选,证书登录状态Y | N--

2.15 PKCS7验签

PKCS7验签,返回验签结果,传入curCert时使用该证书,true为验签成功,验签失败时返回Promise.reject

接口名称

pkcs7VerifySignature

函数签名

type Pkcs7VerifySignature = (params: {
  Data?: string;
  DataB64?: string;
  SignData: string;
}) => Promise<string>;

参数说明

属性说明类型默认值
Data与DataB64二选一,待签名原文String--
DataB64与Data二选一 , Base64编码的待签名原文,同时存在时使用DataB64String--
SignData必填,签名值String--

2.16 base64编码

base64编码,返回base64编码内容

接口名称

base64Encode

函数签名

type Base64Encode = (params: { Data: string }) => string;

参数说明

属性说明类型默认值
Data必填,base64待编码内容String--

2.17 base64解码

base64解码,返回base64解码内容

接口名称

base64Decode

函数签名

type Base64Decode = (params: { DataB64: string }) => string;

参数说明

属性说明类型默认值
DataB64必填,base64待解码内容String--

2.18 SM3哈希

SM3哈希,返回SM3哈希值

接口名称

sm3Hash

函数签名

type Sm3Hash = (params: { Data: string }) => Promise<string>;

参数说明

属性说明类型默认值
Data必填,待计算杂凑值的原文String--

2.19 SM3 B64哈希

SM3 B64哈希

接口名称

sm3HexHash

函数签名

type Sm3HexHash = (params: { DataB64: string }) => Promise<string>;

参数说明

属性说明类型默认值
DataB64必填,待计算杂凑值的原文base64String--

2.20 SM3 文件哈希

SM3 文件哈希

接口名称

sm3FileHash

函数签名

type Sm3FileHash = (params: { SrcFile: string }) => Promise<string>;

参数说明

属性说明类型默认值
SrcFile必填,待计算杂凑值的本地文件全路径。建议使用正斜杠(/)String--

2.21 SM3哈希加密

SM3哈希加密

接口名称

sm3HashEncryption

函数签名

type Sm3HashEncryption = (params: {
  Data?: string;
  DataB64?: string;
  Key?: string;
  KeyB64?: string;
}) => Promise<string>;

参数说明

属性说明类型默认值
Data与DataB64二选一,待加密原文String--
DataB64与Data二选一 , Base64编码的待加密原文,同时存在时使用DataB64String--
Key与KeyB64二选一,密钥String--
KeyB64与Key二选一 , base64编码的密钥,同时存在时使用KeyB64String--

2.22 PKCS7加密

PKCS7加密,返回加密字符串

接口名称

pkcs7Encryption

函数签名

type Pkcs7Encryption = (params: {
  Data?: string;
  DataB64?: string;
  Key: string;
}) => Promise<string>;

参数说明

属性说明类型默认值
Data与DataB64二选一,待加密原文String--
DataB64与Data二选一 , Base64编码的待加密原文,同时存在时使用DataB64String--
CertB64List必填,加密证书base64,多个以|连接String--

2.23 PKCS7解密

PKCS7解密,返回解密字符串

接口名称

pkcs7Decryption

函数签名

type Pkcs7Decryption = (params: {
  DataB64: string;
  shouldDecodeBase64?: boolean;
  IsLogin?: string;
}) => Promise<string>;

参数说明

属性说明类型默认值
DataB64必填,待解密原文String--
shouldDecodeBase64可选,是否需要base64解码Boolean--
IsLogin可选,证书登录状态Y | N--

2.24 非对称加密

非对称加密,返回加密字符串

接口名称

asymmetricDecryption

函数签名

type AsymmetricDecryption = (params: { Data: string;IsLogin?: string }) => Promise<string>;

参数说明

属性说明类型默认值
Data必填,待解密原文String--
CertB64可选,加密证书B64String--
IsLogin可选,证书登录状态Y | N--

2.25 非对称解密

非对称解密,返回解密字符串

接口名称

asymmetricDecryption

函数签名

type AsymmetricDecryption = (
  params: { Data: string },
  curCert?: CertType
) => Promise<string>;

参数说明

属性说明类型默认值
Data必填,待解密原文String--

2.26 SM4对称加密

SM4对称加密,传入curCert时使用该证书,返回加密字符串,加密密钥

接口名称

sm4Encryption

函数签名

type Sm4Encryption = (params: {
  Data: string;
}) => Promise<{ Data: string; KeyB64: string }>;

参数说明

属性说明类型默认值
Data必填,待加密原文String--

返回参数说明

属性说明类型
Data加密密文String
KeyB64Base64对称密钥String

2.27 SM4对称解密

SM4对称解密,返回解密字符串

接口名称

sm4Decryption

函数签名

type Sm4Decryption = (params: {
  Data: string;
  KeyB64: string;
}) => Promise<string>;

参数说明

属性说明类型默认值
Data必填,待解密原文String--
KeyB64必填,Base64对称密钥String--

2.28 获取印章列表

获取印章列表,传入curCert时使用该证书,可获取印章SealId

接口名称

getSealList

函数签名

type getSealList = (
  curCert?: CertType
) => Promise<{ cert: CertType; sealList: SealType[] }>;

Keywords

gzca

FAQs

Package last updated on 19 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts