qsh-webview-sdk 2.0.2 → 2.0.4
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 +42 -1
- package/dist/index.d.ts +20 -0
- package/dist/uni-webview.es.js +1587 -197
- package/dist/uni-webview.es.js.map +1 -1
- package/dist/uni-webview.umd.js +1 -1
- package/dist/uni-webview.umd.js.map +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ npm install qsh-webview-sdk
|
|
|
33
33
|
<!-- 微信小程序环境(可选)-->
|
|
34
34
|
<script type="text/javascript">
|
|
35
35
|
if (/miniProgram/i.test(navigator.userAgent) && /micromessenger/i.test(navigator.userAgent)) {
|
|
36
|
-
document.write('<script src="https://res.wx.qq.com/open/js/jweixin-1.
|
|
36
|
+
document.write('<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"><\/script>');
|
|
37
37
|
}
|
|
38
38
|
</script>
|
|
39
39
|
|
|
@@ -115,6 +115,45 @@ console.log('是否微信小程序:', env.isWeixinMiniProgram);
|
|
|
115
115
|
console.log('是否 APP:', env.isAppPlus);
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
+
### 加密能力(SM2/SM3/SM4)
|
|
119
|
+
|
|
120
|
+
- 已内置并通过 `qsh.crypto` 暴露以下能力:`sm2`(密钥对/加解密/签名验签)、`sm3`(杂凑/HMAC)、`sm4`(对称加解密)。
|
|
121
|
+
- 参考实现来源:[miniprogram-sm-crypto(GitHub)](https://github.com/wechat-miniprogram/sm-crypto)。
|
|
122
|
+
|
|
123
|
+
#### ESM 使用
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
import qsh from 'qsh-webview-sdk';
|
|
127
|
+
|
|
128
|
+
// SM3 杂凑
|
|
129
|
+
const hash = qsh.crypto.sm3Hash('abc');
|
|
130
|
+
|
|
131
|
+
// SM2:生成密钥对 + 签名 + 验签(示例使用 DER 编码)
|
|
132
|
+
const { publicKey, privateKey } = qsh.crypto.sm2GenerateKeyPair();
|
|
133
|
+
const sig = qsh.crypto.sm2Sign('hello sm2', privateKey, { der: true });
|
|
134
|
+
const ok = qsh.crypto.sm2Verify('hello sm2', sig, publicKey, { der: true });
|
|
135
|
+
|
|
136
|
+
// SM4:默认 ECB + pkcs#7 填充
|
|
137
|
+
const key = '0123456789abcdeffedcba9876543210';
|
|
138
|
+
const cipher = qsh.crypto.sm4Encrypt('hello', key);
|
|
139
|
+
const plain = qsh.crypto.sm4Decrypt(cipher, key);
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### UMD 使用
|
|
143
|
+
|
|
144
|
+
```html
|
|
145
|
+
<script src="path/to/uni-webview.umd.js"></script>
|
|
146
|
+
<script>
|
|
147
|
+
// 直接通过全局 qsh 访问
|
|
148
|
+
const hash = window.qsh.crypto.sm3Hash('abc');
|
|
149
|
+
</script>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
提示:
|
|
153
|
+
- SM2 默认使用 C1C3C2(cipherMode=1)。与其他工具互通时请确保模式一致。
|
|
154
|
+
- SM4 支持 ECB/CBC 等模式;CBC 需提供 `iv`。
|
|
155
|
+
- 如需数组输入/输出,可通过 `options.output = 'array'` 控制(与上游库一致)。
|
|
156
|
+
|
|
118
157
|
## API 文档
|
|
119
158
|
|
|
120
159
|
### 导航 API
|
|
@@ -171,6 +210,7 @@ npm run build
|
|
|
171
210
|
|
|
172
211
|
- `example/test.html` - 完整的测试页面,包含所有功能演示
|
|
173
212
|
- `example/simple.html` - 简单示例,展示基础用法
|
|
213
|
+
- `example/npm-usage.html` - 以 ESModule 方式演示,包括加密能力示例
|
|
174
214
|
- `test.html` - 快速测试页面
|
|
175
215
|
|
|
176
216
|
## 项目结构
|
|
@@ -187,6 +227,7 @@ src/
|
|
|
187
227
|
├── api/ # API 接口
|
|
188
228
|
│ ├── navigation.js # 导航 API
|
|
189
229
|
│ └── message.js # 消息 API
|
|
230
|
+
│ └── crypto.js # 加密 API(SM2/SM3/SM4)
|
|
190
231
|
├── index.js # 主入口
|
|
191
232
|
└── index.d.ts # 类型定义
|
|
192
233
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -90,6 +90,26 @@ declare namespace UniWebView {
|
|
|
90
90
|
ready(): Promise<void>;
|
|
91
91
|
/** WebView 对象(兼容旧版本) */
|
|
92
92
|
webView: WebView | null;
|
|
93
|
+
/** 加密 API(SM2/SM3/SM4) */
|
|
94
|
+
crypto: {
|
|
95
|
+
// SM2
|
|
96
|
+
sm2GenerateKeyPair(random?: any): { publicKey: string; privateKey: string };
|
|
97
|
+
sm2Encrypt(message: string | number[], publicKey: string, cipherMode?: 0 | 1, options?: Record<string, any>): string | number[];
|
|
98
|
+
sm2Decrypt(cipherText: string | number[], privateKey: string, cipherMode?: 0 | 1, options?: { output?: 'array' | 'string' }): string | number[];
|
|
99
|
+
sm2Sign(message: string | number[], privateKey: string, options?: Record<string, any>): string;
|
|
100
|
+
sm2Verify(message: string | number[], signatureHex: string, publicKey: string, options?: Record<string, any>): boolean;
|
|
101
|
+
sm2GetPublicKey(privateKey: string): string;
|
|
102
|
+
sm2GetPoint(): any;
|
|
103
|
+
sm2CompressPublicKey(publicKey: string): string;
|
|
104
|
+
sm2ComparePublicKey(a: string, b: string): boolean;
|
|
105
|
+
sm2VerifyPublicKey(publicKey: string): boolean;
|
|
106
|
+
// SM3
|
|
107
|
+
sm3Hash(message: string | number[], options?: { key?: string | number[] }): string;
|
|
108
|
+
// SM4
|
|
109
|
+
sm4Encrypt(message: string | number[], key: string | number[], options?: { padding?: 'pkcs#7' | 'pkcs#5' | 'none'; output?: 'array' | 'string'; mode?: 'ecb' | 'cbc'; iv?: string | number[] }): string | number[];
|
|
110
|
+
sm4Decrypt(cipherText: string | number[], key: string | number[], options?: { padding?: 'pkcs#7' | 'pkcs#5' | 'none'; output?: 'array' | 'string'; mode?: 'ecb' | 'cbc'; iv?: string | number[] }): string | number[];
|
|
111
|
+
__raw__: any;
|
|
112
|
+
};
|
|
93
113
|
}
|
|
94
114
|
}
|
|
95
115
|
|