@polyv/request-plugin-sm2 2.7.1 → 2.8.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
@@ -4,19 +4,19 @@
4
4
 
5
5
  ## 实例化参数
6
6
 
7
- | 参数名 | 用途 | 类型 | 默认值 |
8
- | - | - | - | - |
9
- | `platformPublicKey` | 平台公钥(接口提交参数加密用) | `string` | - |
10
- | `userPrivateKey` | 用户私钥(接口响应内容解密用) | `string` | - |
11
- | `includeIgnoreEncryptFields` | 额外的忽略加密字段 | `string[]` | - |
12
- | `useSM2` | 是否使用 SM2 加密 | `boolean` | `true` |
13
- | `encryptPostSM2` | 是否对 POST 请求主体进行 SM2 加密 | `boolean` | `true` |
7
+ | 参数名 | 用途 | 类型 | 默认值 |
8
+ | ---------------------------- | --------------------------------- | ---------- | ------ |
9
+ | `platformPublicKey` | 平台公钥(接口提交参数加密用) | `string` | - |
10
+ | `userPrivateKey` | 用户私钥(接口响应内容解密用) | `string` | - |
11
+ | `includeIgnoreEncryptFields` | 额外的忽略加密字段 | `string[]` | - |
12
+ | `useSM2` | 是否使用 SM2 加密 | `boolean` | `true` |
13
+ | `encryptPostSM2` | 是否对 POST 请求主体进行 SM2 加密 | `boolean` | `true` |
14
14
 
15
15
  ## 请求选项
16
16
 
17
- | 参数名 | 用途 | 类型 | 默认值 |
18
- | - | - | - | - |
19
- | `useSM2` | 是否使用 SM2 加密 | `boolean` | `true` |
17
+ | 参数名 | 用途 | 类型 | 默认值 |
18
+ | ---------------- | --------------------------------- | --------- | ------ |
19
+ | `useSM2` | 是否使用 SM2 加密 | `boolean` | `true` |
20
20
  | `encryptPostSM2` | 是否对 POST 请求主体进行 SM2 加密 | `boolean` | `true` |
21
21
 
22
22
  ## 使用方式
@@ -32,7 +32,7 @@ const requester = new PolyvRequest({
32
32
  platformPublicKey: 'yourPlatformPublicKey',
33
33
  userPrivateKey: 'yourUserPrivateKey',
34
34
  }),
35
- ]
35
+ ],
36
36
  });
37
37
 
38
38
  // 配置额外的忽略加密字段
@@ -43,16 +43,20 @@ const requester = new PolyvRequest({
43
43
  userPrivateKey: 'yourUserPrivateKey',
44
44
  includeIgnoreEncryptFields: ['customField1', 'customField2'],
45
45
  }),
46
- ]
46
+ ],
47
47
  });
48
48
  // 此时请求时,被忽略的字段不会加入到加密内容中
49
- requester.post('/api/data', {
50
- customField1: 'abc',
51
- }, {
52
- params: {
53
- customField2: 'def',
54
- }
55
- });
49
+ requester.post(
50
+ '/api/data',
51
+ {
52
+ customField1: 'abc',
53
+ },
54
+ {
55
+ params: {
56
+ customField2: 'def',
57
+ },
58
+ },
59
+ );
56
60
 
57
61
  // 禁用 POST 请求主体加密
58
62
  const requester = new PolyvRequest({
@@ -62,16 +66,24 @@ const requester = new PolyvRequest({
62
66
  userPrivateKey: 'yourUserPrivateKey',
63
67
  encryptPostSM2: false,
64
68
  }),
65
- ]
69
+ ],
66
70
  });
67
71
 
68
72
  // 在某个请求中禁用 SM2 加密
69
- requester.get('/api/data', {}, {
70
- useSM2: false,
71
- });
73
+ requester.get(
74
+ '/api/data',
75
+ {},
76
+ {
77
+ useSM2: false,
78
+ },
79
+ );
72
80
 
73
81
  // 在某个请求中禁用 POST 请求主体加密
74
- requester.post('/api/data', { name: 'test' }, {
75
- encryptPostSM2: false,
76
- });
82
+ requester.post(
83
+ '/api/data',
84
+ { name: 'test' },
85
+ {
86
+ encryptPostSM2: false,
87
+ },
88
+ );
77
89
  ```
package/config.js CHANGED
@@ -2,7 +2,15 @@ import { decode } from 'js-base64';
2
2
  /**
3
3
  * 忽略的加密字段
4
4
  */
5
- export const defaultIgnoreEncryptFields = ['appId', 'signatureMethod', 'signatureNonce', 'timestamp', 'viewerToken', 'sign', 'encryptResponseType'];
5
+ export const defaultIgnoreEncryptFields = [
6
+ 'appId',
7
+ 'signatureMethod',
8
+ 'signatureNonce',
9
+ 'timestamp',
10
+ 'viewerToken',
11
+ 'sign',
12
+ 'encryptResponseType',
13
+ ];
6
14
  /**
7
15
  * @ignore
8
16
  */
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@polyv/request-plugin-sm2",
3
- "version": "2.7.1",
3
+ "version": "2.8.0",
4
4
  "main": "./index.js",
5
5
  "dependencies": {
6
- "@polyv/request-core": "2.7.1",
6
+ "@polyv/request-core": "2.8.0",
7
7
  "sm-crypto": "^0.3.7",
8
8
  "js-base64": "^3.7.5"
9
9
  },
10
- "types": "./index.d.ts"
10
+ "types": "./index.d.ts",
11
+ "type": "module",
12
+ "miniprogram": "./"
11
13
  }
package/sm2-plugin.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { RequestOptions, RequestPlugin, RequestResult } from '@polyv/request-core';
2
- import { SM2RequestPluginConfig } from './types';
2
+ import { type SM2RequestPluginConfig } from './types';
3
3
  /**
4
4
  * SM2 请求插件
5
5
  */
package/sm2-plugin.js CHANGED
@@ -12,7 +12,7 @@ import { padding04 } from './utils';
12
12
  // - 对 POST 请求的 body 数据(requetType 为 json),加密内容会作为请求提提交
13
13
  // - 对 POST 请求的 body 数据(requetType 为 form),加密内容会放在 `xparam` 字段中
14
14
  // 5. 当服务端返回加密数据时(`encryption: true`),插件会自动对响应数据进行解密
15
- // 6. 如果请求中包含 `appId` 参数,将使用配置的公钥和私钥;否则使用内部的默认密钥
15
+ // 6. 如果请求中包含 `appId` 参数,将使用配置的公钥和私钥;否则使用内部的默认密钥
16
16
  /**
17
17
  * SM2 请求插件
18
18
  */
@@ -132,7 +132,7 @@ export class SM2RequestPlugin {
132
132
  const ignoreObj = {};
133
133
  // 业务参数
134
134
  const businessObj = {};
135
- keys.forEach((item) => {
135
+ keys.forEach(item => {
136
136
  if (this.__ignoreEncryptFields.includes(item)) {
137
137
  ignoreObj[item] = targetObj[item];
138
138
  }