npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

gws-client

v1.0.3

Published

gws client

Readme

简介

用于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码 | Boolean | false | | pinPolicy | 可选,口令安全策略 | 0 | 1| 2| 3 | 0 | | 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 | 必填,证书Base64 | String | -- |

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编码的待签名原文,同时存在时使用DataB64 | String | -- | | 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编码的待签名原文,同时存在时使用DataB64 | String | -- | | 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| sha256 | sm3 | | 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| sha256 | sm3 |

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编码的待签名原文,同时存在时使用DataB64 | String | -- | | 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编码的待签名原文,同时存在时使用DataB64 | String | -- | | 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 | 必填,待计算杂凑值的原文base64 | String | -- |

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编码的待加密原文,同时存在时使用DataB64 | String | -- | | Key | 与KeyB64二选一,密钥 | String | -- | | KeyB64 | 与Key二选一 , base64编码的密钥,同时存在时使用KeyB64 | String | -- |

2.22 PKCS7加密

PKCS7加密,返回加密字符串

接口名称

pkcs7Encryption

函数签名

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

参数说明

| 属性 | 说明 | 类型 | 默认值 | | ----------- | ------------------------------------------------------------- | -------- | ------ | | Data | 与DataB64二选一,待加密原文 | String | -- | | DataB64 | 与Data二选一 , Base64编码的待加密原文,同时存在时使用DataB64 | String | -- | | 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 | 可选,加密证书B64 | String | -- | | 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 | | KeyB64 | Base64对称密钥 | 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[] }>;