wop-python-sdk 0.1.7__tar.gz → 0.2.1__tar.gz
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.
- {wop_python_sdk-0.1.7/src/wop_python_sdk.egg-info → wop_python_sdk-0.2.1}/PKG-INFO +39 -6
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/README.md +38 -5
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/pyproject.toml +21 -2
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1/src/wop_python_sdk.egg-info}/PKG-INFO +39 -6
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_python_sdk.egg-info/SOURCES.txt +10 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_sdk/__init__.py +21 -11
- wop_python_sdk-0.2.1/src/wop_sdk/client.py +515 -0
- wop_python_sdk-0.2.1/src/wop_sdk/config/__init__.py +12 -0
- wop_python_sdk-0.2.1/src/wop_sdk/config/_loader.py +130 -0
- wop_python_sdk-0.2.1/src/wop_sdk/config/_models.py +122 -0
- wop_python_sdk-0.2.1/src/wop_sdk/config/_parser.py +186 -0
- wop_python_sdk-0.2.1/src/wop_sdk/config/_validator.py +114 -0
- wop_python_sdk-0.2.1/src/wop_sdk/config/wopSdkConfig.json +14 -0
- wop_python_sdk-0.2.1/src/wop_sdk/errors.py +103 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_sdk/sm2crypto.py +53 -4
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_sdk/suites.py +3 -2
- wop_python_sdk-0.2.1/src/wop_sdk/transport_discovery.py +50 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_sdk/transports/urllib_transport.py +10 -4
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/tests/test_bdd.py +15 -7
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/tests/test_client.py +153 -9
- wop_python_sdk-0.2.1/tests/test_config.py +350 -0
- wop_python_sdk-0.2.1/tests/test_config_loading.py +306 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/tests/test_coverage_gaps.py +147 -5
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/tests/test_envelope.py +7 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/tests/test_interop.py +25 -12
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/tests/test_keys.py +10 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/tests/test_signature.py +16 -4
- wop_python_sdk-0.2.1/tests/test_submchid.py +193 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/tests/test_suites.py +18 -2
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/tests/test_transports.py +11 -0
- wop_python_sdk-0.1.7/src/wop_sdk/client.py +0 -280
- wop_python_sdk-0.1.7/src/wop_sdk/errors.py +0 -48
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/LICENSE +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/setup.cfg +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_python_sdk.egg-info/dependency_links.txt +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_python_sdk.egg-info/requires.txt +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_python_sdk.egg-info/top_level.txt +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_sdk/canonical.py +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_sdk/digest.py +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_sdk/encoding.py +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_sdk/envelope.py +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_sdk/keys.py +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_sdk/signature.py +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_sdk/sm4gcm.py +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_sdk/transports/__init__.py +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_sdk/transports/httpx_transport.py +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/src/wop_sdk/transports/requests_transport.py +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/tests/test_canonical.py +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/tests/test_digest.py +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/tests/test_encoding.py +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/tests/test_mutation_gaps.py +0 -0
- {wop_python_sdk-0.1.7 → wop_python_sdk-0.2.1}/tests/test_transports_real.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: wop-python-sdk
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: WOP 商户侧官方 Python SDK:协议核心(签名/摘要/数字信封/验签解密)+ 可插拔 HTTP 适配层
|
|
5
5
|
Author: wop-platform
|
|
6
6
|
License: MIT
|
|
@@ -34,14 +34,16 @@ Dynamic: license-file
|
|
|
34
34
|
[](https://github.com/wop-platform/wop-python-sdk/actions/workflows/ci.yml) [](tests/features/wop_merchant.feature) 
|
|
35
35
|
|
|
36
36
|
|
|
37
|
+
> **WOP · 万联易达开放平台** 官方 Python SDK —— 协议与黄金向量真源:[wop-specs](https://github.com/wop-platform/wop-specs)
|
|
38
|
+
|
|
37
39
|
WOP 网关商户侧官方 Python 客户端库:封装协议核心(套件解析 / 结构化签名 / 内容摘要 /
|
|
38
40
|
L2 数字信封 / 验签解密)与可插拔 HTTP 适配层,使商户无需理解 canonicalRequest、
|
|
39
41
|
算法套件推导与线上字节格式即可安全对接网关。
|
|
40
42
|
|
|
41
|
-
- 协议真源:[crypto-strategy-spec.md](https://github.com/wop-platform/wop-specs/blob/main/crypto/crypto-strategy-spec.md)(v0.3-reviewed)+ [wop-sdk-spec.md](https://github.com/wop-platform/wop-specs/blob/main/
|
|
43
|
+
- 协议真源:[crypto-strategy-spec.md](https://github.com/wop-platform/wop-specs/blob/main/crypto/crypto-strategy-spec.md)(v0.3-reviewed)+ [wop-sdk-spec.md](https://github.com/wop-platform/wop-specs/blob/main/docs/specs/wop-sdk-spec.md)(v1.0-ratified)
|
|
42
44
|
- 向量真源:[crypto-vectors.json](https://github.com/wop-platform/wop-specs/blob/main/crypto/crypto-vectors.json)(本仓 fixture 为字节级副本,禁手改)
|
|
43
45
|
- Python ≥ 3.9
|
|
44
|
-
-
|
|
46
|
+
- 四套件全支持:`WOP-RSA2048-SHA256` / `WOP-RSA3072-SHA256` / `WOP-RSA4096-SHA256` / `WOP-SM2-SM3`
|
|
45
47
|
- 密码依赖(唯一指定路径):`cryptography`(RSA/AES)+ `gmssl ≥ 3.2.2`(SM2/SM3/SM4)
|
|
46
48
|
- 主包零额外依赖;HTTP 适配器以 peer 依赖交付(`wop-python-sdk[httpx]` / `wop-python-sdk[requests]`)
|
|
47
49
|
|
|
@@ -58,7 +60,7 @@ from wop_sdk.transports import UrllibTransport, send_draft
|
|
|
58
60
|
|
|
59
61
|
client = WopClient(WopConfig(
|
|
60
62
|
app_key="app_10012481831",
|
|
61
|
-
suite="WOP-
|
|
63
|
+
suite="WOP-RSA2048-SHA256", # 或 WOP-RSA4096-SHA256 / WOP-SM2-SM3
|
|
62
64
|
merchant_private_key=MERCHANT_PRIV_PEM, # 商户私钥(PEM 或 Base64 单行)
|
|
63
65
|
platform_public_key=PLATFORM_PUB_PEM, # 平台公钥(PEM 或 Base64 单行)
|
|
64
66
|
gateway_base_url="https://wop.example.com",
|
|
@@ -78,12 +80,31 @@ else:
|
|
|
78
80
|
print(result.reason) # 验签/解密失败对外模糊(I7),格式/完整性/一致性类明确
|
|
79
81
|
```
|
|
80
82
|
|
|
83
|
+
## ISV 子商户身份(ISV D-13)
|
|
84
|
+
|
|
85
|
+
代子商户调用业务 API 时,按请求传 `sub_mch_id`(值 = 子商户 `plf_co_id`):
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
draft = client.build_request("POST", "/gateway/order/create", body, level="L0",
|
|
89
|
+
sub_mch_id="PLF-SUB-001")
|
|
90
|
+
# 一站式调用:
|
|
91
|
+
result = client.execute("POST", "/gateway/order/create", body, level="L0",
|
|
92
|
+
sub_mch_id="PLF-SUB-001")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
SDK 在签名前写入 `x-wop-sub-mch-id`,并自动纳入 `x-wop-sign` 的 signedHeaders。
|
|
96
|
+
首尾空白 trim 后发送;仅接受可打印 ASCII(0x20–0x7E)、无内部空白、≤128 字符,
|
|
97
|
+
违规抛 `ConfigurationError`。不传或纯空白 = 应用自身身份,头缺席,请求头集合与签名
|
|
98
|
+
与旧版逐字节一致(AC-20)。`extra_headers` 携带该头等价于参数;双来源同传构造即拒。
|
|
99
|
+
该头仅在网关子商户灰度放行且应用为 ISV 应用(`app_type=20`)时生效。
|
|
100
|
+
|
|
81
101
|
## 密钥准备
|
|
82
102
|
|
|
83
103
|
密钥入参为字符串(PEM 或 Base64 单行),SDK 内部解析(D12 分发契约):
|
|
84
104
|
|
|
85
105
|
| 套件 | 商户私钥 | 平台公钥 | 约束 |
|
|
86
106
|
|------|----------|----------|------|
|
|
107
|
+
| `WOP-RSA2048-SHA256` | PKCS#8 DER,Base64/PEM | X.509 SPKI DER,Base64/PEM | 密钥必须 2048 位 |
|
|
87
108
|
| `WOP-RSA3072-SHA256` | PKCS#8 DER,Base64/PEM | X.509 SPKI DER,Base64/PEM | 密钥必须 3072 位 |
|
|
88
109
|
| `WOP-RSA4096-SHA256` | 同上 | 同上 | 密钥必须 4096 位 |
|
|
89
110
|
| `WOP-SM2-SM3` | `d` 标量 32 字节,Base64 | 未压缩点 `04‖X‖Y` 65 字节,Base64 | 点必须在 sm2p256v1 曲线上(I5) |
|
|
@@ -130,14 +151,14 @@ pip install -e '.[httpx]' coverage
|
|
|
130
151
|
python3 -m pytest --cov=wop_sdk --cov-branch --cov-fail-under=98
|
|
131
152
|
```
|
|
132
153
|
|
|
133
|
-
覆盖:
|
|
154
|
+
覆盖:RSA2048/3072/4096 与 SM2 签名字节级断言、OAEP 包装/解包、AES-256-GCM 与 SM4-GCM
|
|
134
155
|
密文字节级断言、SM3/SHA-256 摘要、DEK 载荷组装、digest 头全部格式规则;负向量含
|
|
135
156
|
tamper / 跨族 / 63B、65B 签名 / 带 `=` 的 base64url / C1C2C3 旧国标顺序 /
|
|
136
157
|
MGF1-SHA1 陷阱密文,全部必须拒绝。CI(3.9–3.14 × linux/macOS 矩阵)执行同一命令。
|
|
137
158
|
|
|
138
159
|
另消费 `wop-specs` 组织级 interop 样本集(`tests/fixtures/interop-cases.json` 字节
|
|
139
160
|
副本,sha256 哨兵钉死):build 方向按冻结输入复现 draft(RSA byte-exact;SM2 按
|
|
140
|
-
opaque 剥离签名/包装段),verify 方向
|
|
161
|
+
opaque 剥离签名/包装段),verify 方向 24 条冻结样本逐条对账明文与错误分类
|
|
141
162
|
(canonical class 映射表见 `tests/test_interop.py`)。
|
|
142
163
|
|
|
143
164
|
## 错误处理与模糊化
|
|
@@ -148,3 +169,15 @@ opaque 剥离签名/包装段),verify 方向 23 条冻结样本逐条对账
|
|
|
148
169
|
- **模糊**(依赖密钥参与,防 oracle,I7):签名验证失败、解密失败——对外消息不区分
|
|
149
170
|
tag 失败 / 密钥不符等原因细节;DEK 载荷(解包后明文)结构畸形除 alg 跨族外一律
|
|
150
171
|
归入解密失败(interop 合同 n13 / 故障注入手册 P3)。
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 🧩 WOP 生态导航 | Ecosystem
|
|
176
|
+
|
|
177
|
+
| 类别 | 组件 |
|
|
178
|
+
|------|------|
|
|
179
|
+
| 协议与向量真源 | [wop-specs](https://github.com/wop-platform/wop-specs) —— crypto-strategy-spec · wop-sdk-spec · 黄金测试向量 |
|
|
180
|
+
| 官方 SDK(六语言) | [Java](https://github.com/wop-platform/wop-java-sdk) · [Go](https://github.com/wop-platform/wop-go-sdk) · [Python](https://github.com/wop-platform/wop-python-sdk) · [PHP](https://github.com/wop-platform/wop-php-sdk) · [.NET](https://github.com/wop-platform/wop-dotnet-sdk) · [TypeScript](https://github.com/wop-platform/wop-typescript-sdk) |
|
|
181
|
+
| 浏览器工作台 | [wop-web-tools](https://github.com/wop-platform/wop-web-tools) —— 密钥生成 · 报文联调 · 国密 · 六语言代码片段 |
|
|
182
|
+
| Agent 技能包 | [wop-skills](https://github.com/wop-platform/wop-skills) —— 零代码调用 · 联调对拍 · 62 错误码排错 |
|
|
183
|
+
| 平台服务(企业内部) | 统一接入网关 · 核心逻辑服务 · 回调服务 · 开发者门户 · 文档中心 |
|
|
@@ -4,14 +4,16 @@
|
|
|
4
4
|
[](https://github.com/wop-platform/wop-python-sdk/actions/workflows/ci.yml) [](tests/features/wop_merchant.feature) 
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
> **WOP · 万联易达开放平台** 官方 Python SDK —— 协议与黄金向量真源:[wop-specs](https://github.com/wop-platform/wop-specs)
|
|
8
|
+
|
|
7
9
|
WOP 网关商户侧官方 Python 客户端库:封装协议核心(套件解析 / 结构化签名 / 内容摘要 /
|
|
8
10
|
L2 数字信封 / 验签解密)与可插拔 HTTP 适配层,使商户无需理解 canonicalRequest、
|
|
9
11
|
算法套件推导与线上字节格式即可安全对接网关。
|
|
10
12
|
|
|
11
|
-
- 协议真源:[crypto-strategy-spec.md](https://github.com/wop-platform/wop-specs/blob/main/crypto/crypto-strategy-spec.md)(v0.3-reviewed)+ [wop-sdk-spec.md](https://github.com/wop-platform/wop-specs/blob/main/
|
|
13
|
+
- 协议真源:[crypto-strategy-spec.md](https://github.com/wop-platform/wop-specs/blob/main/crypto/crypto-strategy-spec.md)(v0.3-reviewed)+ [wop-sdk-spec.md](https://github.com/wop-platform/wop-specs/blob/main/docs/specs/wop-sdk-spec.md)(v1.0-ratified)
|
|
12
14
|
- 向量真源:[crypto-vectors.json](https://github.com/wop-platform/wop-specs/blob/main/crypto/crypto-vectors.json)(本仓 fixture 为字节级副本,禁手改)
|
|
13
15
|
- Python ≥ 3.9
|
|
14
|
-
-
|
|
16
|
+
- 四套件全支持:`WOP-RSA2048-SHA256` / `WOP-RSA3072-SHA256` / `WOP-RSA4096-SHA256` / `WOP-SM2-SM3`
|
|
15
17
|
- 密码依赖(唯一指定路径):`cryptography`(RSA/AES)+ `gmssl ≥ 3.2.2`(SM2/SM3/SM4)
|
|
16
18
|
- 主包零额外依赖;HTTP 适配器以 peer 依赖交付(`wop-python-sdk[httpx]` / `wop-python-sdk[requests]`)
|
|
17
19
|
|
|
@@ -28,7 +30,7 @@ from wop_sdk.transports import UrllibTransport, send_draft
|
|
|
28
30
|
|
|
29
31
|
client = WopClient(WopConfig(
|
|
30
32
|
app_key="app_10012481831",
|
|
31
|
-
suite="WOP-
|
|
33
|
+
suite="WOP-RSA2048-SHA256", # 或 WOP-RSA4096-SHA256 / WOP-SM2-SM3
|
|
32
34
|
merchant_private_key=MERCHANT_PRIV_PEM, # 商户私钥(PEM 或 Base64 单行)
|
|
33
35
|
platform_public_key=PLATFORM_PUB_PEM, # 平台公钥(PEM 或 Base64 单行)
|
|
34
36
|
gateway_base_url="https://wop.example.com",
|
|
@@ -48,12 +50,31 @@ else:
|
|
|
48
50
|
print(result.reason) # 验签/解密失败对外模糊(I7),格式/完整性/一致性类明确
|
|
49
51
|
```
|
|
50
52
|
|
|
53
|
+
## ISV 子商户身份(ISV D-13)
|
|
54
|
+
|
|
55
|
+
代子商户调用业务 API 时,按请求传 `sub_mch_id`(值 = 子商户 `plf_co_id`):
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
draft = client.build_request("POST", "/gateway/order/create", body, level="L0",
|
|
59
|
+
sub_mch_id="PLF-SUB-001")
|
|
60
|
+
# 一站式调用:
|
|
61
|
+
result = client.execute("POST", "/gateway/order/create", body, level="L0",
|
|
62
|
+
sub_mch_id="PLF-SUB-001")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
SDK 在签名前写入 `x-wop-sub-mch-id`,并自动纳入 `x-wop-sign` 的 signedHeaders。
|
|
66
|
+
首尾空白 trim 后发送;仅接受可打印 ASCII(0x20–0x7E)、无内部空白、≤128 字符,
|
|
67
|
+
违规抛 `ConfigurationError`。不传或纯空白 = 应用自身身份,头缺席,请求头集合与签名
|
|
68
|
+
与旧版逐字节一致(AC-20)。`extra_headers` 携带该头等价于参数;双来源同传构造即拒。
|
|
69
|
+
该头仅在网关子商户灰度放行且应用为 ISV 应用(`app_type=20`)时生效。
|
|
70
|
+
|
|
51
71
|
## 密钥准备
|
|
52
72
|
|
|
53
73
|
密钥入参为字符串(PEM 或 Base64 单行),SDK 内部解析(D12 分发契约):
|
|
54
74
|
|
|
55
75
|
| 套件 | 商户私钥 | 平台公钥 | 约束 |
|
|
56
76
|
|------|----------|----------|------|
|
|
77
|
+
| `WOP-RSA2048-SHA256` | PKCS#8 DER,Base64/PEM | X.509 SPKI DER,Base64/PEM | 密钥必须 2048 位 |
|
|
57
78
|
| `WOP-RSA3072-SHA256` | PKCS#8 DER,Base64/PEM | X.509 SPKI DER,Base64/PEM | 密钥必须 3072 位 |
|
|
58
79
|
| `WOP-RSA4096-SHA256` | 同上 | 同上 | 密钥必须 4096 位 |
|
|
59
80
|
| `WOP-SM2-SM3` | `d` 标量 32 字节,Base64 | 未压缩点 `04‖X‖Y` 65 字节,Base64 | 点必须在 sm2p256v1 曲线上(I5) |
|
|
@@ -100,14 +121,14 @@ pip install -e '.[httpx]' coverage
|
|
|
100
121
|
python3 -m pytest --cov=wop_sdk --cov-branch --cov-fail-under=98
|
|
101
122
|
```
|
|
102
123
|
|
|
103
|
-
覆盖:
|
|
124
|
+
覆盖:RSA2048/3072/4096 与 SM2 签名字节级断言、OAEP 包装/解包、AES-256-GCM 与 SM4-GCM
|
|
104
125
|
密文字节级断言、SM3/SHA-256 摘要、DEK 载荷组装、digest 头全部格式规则;负向量含
|
|
105
126
|
tamper / 跨族 / 63B、65B 签名 / 带 `=` 的 base64url / C1C2C3 旧国标顺序 /
|
|
106
127
|
MGF1-SHA1 陷阱密文,全部必须拒绝。CI(3.9–3.14 × linux/macOS 矩阵)执行同一命令。
|
|
107
128
|
|
|
108
129
|
另消费 `wop-specs` 组织级 interop 样本集(`tests/fixtures/interop-cases.json` 字节
|
|
109
130
|
副本,sha256 哨兵钉死):build 方向按冻结输入复现 draft(RSA byte-exact;SM2 按
|
|
110
|
-
opaque 剥离签名/包装段),verify 方向
|
|
131
|
+
opaque 剥离签名/包装段),verify 方向 24 条冻结样本逐条对账明文与错误分类
|
|
111
132
|
(canonical class 映射表见 `tests/test_interop.py`)。
|
|
112
133
|
|
|
113
134
|
## 错误处理与模糊化
|
|
@@ -118,3 +139,15 @@ opaque 剥离签名/包装段),verify 方向 23 条冻结样本逐条对账
|
|
|
118
139
|
- **模糊**(依赖密钥参与,防 oracle,I7):签名验证失败、解密失败——对外消息不区分
|
|
119
140
|
tag 失败 / 密钥不符等原因细节;DEK 载荷(解包后明文)结构畸形除 alg 跨族外一律
|
|
120
141
|
归入解密失败(interop 合同 n13 / 故障注入手册 P3)。
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## 🧩 WOP 生态导航 | Ecosystem
|
|
146
|
+
|
|
147
|
+
| 类别 | 组件 |
|
|
148
|
+
|------|------|
|
|
149
|
+
| 协议与向量真源 | [wop-specs](https://github.com/wop-platform/wop-specs) —— crypto-strategy-spec · wop-sdk-spec · 黄金测试向量 |
|
|
150
|
+
| 官方 SDK(六语言) | [Java](https://github.com/wop-platform/wop-java-sdk) · [Go](https://github.com/wop-platform/wop-go-sdk) · [Python](https://github.com/wop-platform/wop-python-sdk) · [PHP](https://github.com/wop-platform/wop-php-sdk) · [.NET](https://github.com/wop-platform/wop-dotnet-sdk) · [TypeScript](https://github.com/wop-platform/wop-typescript-sdk) |
|
|
151
|
+
| 浏览器工作台 | [wop-web-tools](https://github.com/wop-platform/wop-web-tools) —— 密钥生成 · 报文联调 · 国密 · 六语言代码片段 |
|
|
152
|
+
| Agent 技能包 | [wop-skills](https://github.com/wop-platform/wop-skills) —— 零代码调用 · 联调对拍 · 62 错误码排错 |
|
|
153
|
+
| 平台服务(企业内部) | 统一接入网关 · 核心逻辑服务 · 回调服务 · 开发者门户 · 文档中心 |
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "wop-python-sdk"
|
|
7
|
-
version = "0.1
|
|
7
|
+
version = "0.2.1"
|
|
8
8
|
description = "WOP 商户侧官方 Python SDK:协议核心(签名/摘要/数字信封/验签解密)+ 可插拔 HTTP 适配层"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { text = "MIT" }
|
|
@@ -38,7 +38,9 @@ requests = ["requests>=2.28"]
|
|
|
38
38
|
[dependency-groups]
|
|
39
39
|
# 发布构建前端 + BDD 测试工具链(PEP 735,不进发布元数据):
|
|
40
40
|
# pip install --group dev && python -m build
|
|
41
|
-
|
|
41
|
+
# griffe:公共 API 快照门禁工具,版本锁定保证快照字节确定性
|
|
42
|
+
# (scripts/check-api-snapshot.py 与 ci.yml api-snapshot job)
|
|
43
|
+
dev = ["build", "pytest-bdd>=8.0,<9.0", "griffe==1.14.0"]
|
|
42
44
|
|
|
43
45
|
[project.urls]
|
|
44
46
|
Homepage = "https://github.com/wop-platform/wop-python-sdk"
|
|
@@ -46,6 +48,10 @@ Homepage = "https://github.com/wop-platform/wop-python-sdk"
|
|
|
46
48
|
[tool.setuptools.packages.find]
|
|
47
49
|
where = ["src"]
|
|
48
50
|
|
|
51
|
+
# 配置发现兜底来源(K6 优先级 6):打包资源随包分发,setuptools 默认不收 JSON
|
|
52
|
+
[tool.setuptools.package-data]
|
|
53
|
+
"wop_sdk.config" = ["*.json"]
|
|
54
|
+
|
|
49
55
|
[tool.pytest.ini_options]
|
|
50
56
|
testpaths = ["tests"]
|
|
51
57
|
pythonpath = ["src"]
|
|
@@ -58,3 +64,16 @@ branch = true
|
|
|
58
64
|
[tool.coverage.report]
|
|
59
65
|
show_missing = true
|
|
60
66
|
precision = 2
|
|
67
|
+
|
|
68
|
+
[tool.ruff]
|
|
69
|
+
target-version = "py39"
|
|
70
|
+
line-length = 120
|
|
71
|
+
# .factory:从上游同步的 vendored 工厂副本,不在本仓维护,排除以免同步覆盖与噪声
|
|
72
|
+
extend-exclude = [".factory"]
|
|
73
|
+
|
|
74
|
+
[tool.ruff.lint]
|
|
75
|
+
# E4/E7/E9/F:语法/未定义名/未用导入变量/重定义等真实错误。
|
|
76
|
+
# E741/E702/E731 是历史代码纯风格(歧义单字母名、分号多语句、lambda 赋值——后者
|
|
77
|
+
# 是模块级公共 API `request_id_generator`,改为 def 会动 griffe API 快照),基线忽略。
|
|
78
|
+
select = ["E4", "E7", "E9", "F"]
|
|
79
|
+
ignore = ["E741", "E702", "E731"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: wop-python-sdk
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: WOP 商户侧官方 Python SDK:协议核心(签名/摘要/数字信封/验签解密)+ 可插拔 HTTP 适配层
|
|
5
5
|
Author: wop-platform
|
|
6
6
|
License: MIT
|
|
@@ -34,14 +34,16 @@ Dynamic: license-file
|
|
|
34
34
|
[](https://github.com/wop-platform/wop-python-sdk/actions/workflows/ci.yml) [](tests/features/wop_merchant.feature) 
|
|
35
35
|
|
|
36
36
|
|
|
37
|
+
> **WOP · 万联易达开放平台** 官方 Python SDK —— 协议与黄金向量真源:[wop-specs](https://github.com/wop-platform/wop-specs)
|
|
38
|
+
|
|
37
39
|
WOP 网关商户侧官方 Python 客户端库:封装协议核心(套件解析 / 结构化签名 / 内容摘要 /
|
|
38
40
|
L2 数字信封 / 验签解密)与可插拔 HTTP 适配层,使商户无需理解 canonicalRequest、
|
|
39
41
|
算法套件推导与线上字节格式即可安全对接网关。
|
|
40
42
|
|
|
41
|
-
- 协议真源:[crypto-strategy-spec.md](https://github.com/wop-platform/wop-specs/blob/main/crypto/crypto-strategy-spec.md)(v0.3-reviewed)+ [wop-sdk-spec.md](https://github.com/wop-platform/wop-specs/blob/main/
|
|
43
|
+
- 协议真源:[crypto-strategy-spec.md](https://github.com/wop-platform/wop-specs/blob/main/crypto/crypto-strategy-spec.md)(v0.3-reviewed)+ [wop-sdk-spec.md](https://github.com/wop-platform/wop-specs/blob/main/docs/specs/wop-sdk-spec.md)(v1.0-ratified)
|
|
42
44
|
- 向量真源:[crypto-vectors.json](https://github.com/wop-platform/wop-specs/blob/main/crypto/crypto-vectors.json)(本仓 fixture 为字节级副本,禁手改)
|
|
43
45
|
- Python ≥ 3.9
|
|
44
|
-
-
|
|
46
|
+
- 四套件全支持:`WOP-RSA2048-SHA256` / `WOP-RSA3072-SHA256` / `WOP-RSA4096-SHA256` / `WOP-SM2-SM3`
|
|
45
47
|
- 密码依赖(唯一指定路径):`cryptography`(RSA/AES)+ `gmssl ≥ 3.2.2`(SM2/SM3/SM4)
|
|
46
48
|
- 主包零额外依赖;HTTP 适配器以 peer 依赖交付(`wop-python-sdk[httpx]` / `wop-python-sdk[requests]`)
|
|
47
49
|
|
|
@@ -58,7 +60,7 @@ from wop_sdk.transports import UrllibTransport, send_draft
|
|
|
58
60
|
|
|
59
61
|
client = WopClient(WopConfig(
|
|
60
62
|
app_key="app_10012481831",
|
|
61
|
-
suite="WOP-
|
|
63
|
+
suite="WOP-RSA2048-SHA256", # 或 WOP-RSA4096-SHA256 / WOP-SM2-SM3
|
|
62
64
|
merchant_private_key=MERCHANT_PRIV_PEM, # 商户私钥(PEM 或 Base64 单行)
|
|
63
65
|
platform_public_key=PLATFORM_PUB_PEM, # 平台公钥(PEM 或 Base64 单行)
|
|
64
66
|
gateway_base_url="https://wop.example.com",
|
|
@@ -78,12 +80,31 @@ else:
|
|
|
78
80
|
print(result.reason) # 验签/解密失败对外模糊(I7),格式/完整性/一致性类明确
|
|
79
81
|
```
|
|
80
82
|
|
|
83
|
+
## ISV 子商户身份(ISV D-13)
|
|
84
|
+
|
|
85
|
+
代子商户调用业务 API 时,按请求传 `sub_mch_id`(值 = 子商户 `plf_co_id`):
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
draft = client.build_request("POST", "/gateway/order/create", body, level="L0",
|
|
89
|
+
sub_mch_id="PLF-SUB-001")
|
|
90
|
+
# 一站式调用:
|
|
91
|
+
result = client.execute("POST", "/gateway/order/create", body, level="L0",
|
|
92
|
+
sub_mch_id="PLF-SUB-001")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
SDK 在签名前写入 `x-wop-sub-mch-id`,并自动纳入 `x-wop-sign` 的 signedHeaders。
|
|
96
|
+
首尾空白 trim 后发送;仅接受可打印 ASCII(0x20–0x7E)、无内部空白、≤128 字符,
|
|
97
|
+
违规抛 `ConfigurationError`。不传或纯空白 = 应用自身身份,头缺席,请求头集合与签名
|
|
98
|
+
与旧版逐字节一致(AC-20)。`extra_headers` 携带该头等价于参数;双来源同传构造即拒。
|
|
99
|
+
该头仅在网关子商户灰度放行且应用为 ISV 应用(`app_type=20`)时生效。
|
|
100
|
+
|
|
81
101
|
## 密钥准备
|
|
82
102
|
|
|
83
103
|
密钥入参为字符串(PEM 或 Base64 单行),SDK 内部解析(D12 分发契约):
|
|
84
104
|
|
|
85
105
|
| 套件 | 商户私钥 | 平台公钥 | 约束 |
|
|
86
106
|
|------|----------|----------|------|
|
|
107
|
+
| `WOP-RSA2048-SHA256` | PKCS#8 DER,Base64/PEM | X.509 SPKI DER,Base64/PEM | 密钥必须 2048 位 |
|
|
87
108
|
| `WOP-RSA3072-SHA256` | PKCS#8 DER,Base64/PEM | X.509 SPKI DER,Base64/PEM | 密钥必须 3072 位 |
|
|
88
109
|
| `WOP-RSA4096-SHA256` | 同上 | 同上 | 密钥必须 4096 位 |
|
|
89
110
|
| `WOP-SM2-SM3` | `d` 标量 32 字节,Base64 | 未压缩点 `04‖X‖Y` 65 字节,Base64 | 点必须在 sm2p256v1 曲线上(I5) |
|
|
@@ -130,14 +151,14 @@ pip install -e '.[httpx]' coverage
|
|
|
130
151
|
python3 -m pytest --cov=wop_sdk --cov-branch --cov-fail-under=98
|
|
131
152
|
```
|
|
132
153
|
|
|
133
|
-
覆盖:
|
|
154
|
+
覆盖:RSA2048/3072/4096 与 SM2 签名字节级断言、OAEP 包装/解包、AES-256-GCM 与 SM4-GCM
|
|
134
155
|
密文字节级断言、SM3/SHA-256 摘要、DEK 载荷组装、digest 头全部格式规则;负向量含
|
|
135
156
|
tamper / 跨族 / 63B、65B 签名 / 带 `=` 的 base64url / C1C2C3 旧国标顺序 /
|
|
136
157
|
MGF1-SHA1 陷阱密文,全部必须拒绝。CI(3.9–3.14 × linux/macOS 矩阵)执行同一命令。
|
|
137
158
|
|
|
138
159
|
另消费 `wop-specs` 组织级 interop 样本集(`tests/fixtures/interop-cases.json` 字节
|
|
139
160
|
副本,sha256 哨兵钉死):build 方向按冻结输入复现 draft(RSA byte-exact;SM2 按
|
|
140
|
-
opaque 剥离签名/包装段),verify 方向
|
|
161
|
+
opaque 剥离签名/包装段),verify 方向 24 条冻结样本逐条对账明文与错误分类
|
|
141
162
|
(canonical class 映射表见 `tests/test_interop.py`)。
|
|
142
163
|
|
|
143
164
|
## 错误处理与模糊化
|
|
@@ -148,3 +169,15 @@ opaque 剥离签名/包装段),verify 方向 23 条冻结样本逐条对账
|
|
|
148
169
|
- **模糊**(依赖密钥参与,防 oracle,I7):签名验证失败、解密失败——对外消息不区分
|
|
149
170
|
tag 失败 / 密钥不符等原因细节;DEK 载荷(解包后明文)结构畸形除 alg 跨族外一律
|
|
150
171
|
归入解密失败(interop 合同 n13 / 故障注入手册 P3)。
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 🧩 WOP 生态导航 | Ecosystem
|
|
176
|
+
|
|
177
|
+
| 类别 | 组件 |
|
|
178
|
+
|------|------|
|
|
179
|
+
| 协议与向量真源 | [wop-specs](https://github.com/wop-platform/wop-specs) —— crypto-strategy-spec · wop-sdk-spec · 黄金测试向量 |
|
|
180
|
+
| 官方 SDK(六语言) | [Java](https://github.com/wop-platform/wop-java-sdk) · [Go](https://github.com/wop-platform/wop-go-sdk) · [Python](https://github.com/wop-platform/wop-python-sdk) · [PHP](https://github.com/wop-platform/wop-php-sdk) · [.NET](https://github.com/wop-platform/wop-dotnet-sdk) · [TypeScript](https://github.com/wop-platform/wop-typescript-sdk) |
|
|
181
|
+
| 浏览器工作台 | [wop-web-tools](https://github.com/wop-platform/wop-web-tools) —— 密钥生成 · 报文联调 · 国密 · 六语言代码片段 |
|
|
182
|
+
| Agent 技能包 | [wop-skills](https://github.com/wop-platform/wop-skills) —— 零代码调用 · 联调对拍 · 62 错误码排错 |
|
|
183
|
+
| 平台服务(企业内部) | 统一接入网关 · 核心逻辑服务 · 回调服务 · 开发者门户 · 文档中心 |
|
|
@@ -18,6 +18,13 @@ src/wop_sdk/signature.py
|
|
|
18
18
|
src/wop_sdk/sm2crypto.py
|
|
19
19
|
src/wop_sdk/sm4gcm.py
|
|
20
20
|
src/wop_sdk/suites.py
|
|
21
|
+
src/wop_sdk/transport_discovery.py
|
|
22
|
+
src/wop_sdk/config/__init__.py
|
|
23
|
+
src/wop_sdk/config/_loader.py
|
|
24
|
+
src/wop_sdk/config/_models.py
|
|
25
|
+
src/wop_sdk/config/_parser.py
|
|
26
|
+
src/wop_sdk/config/_validator.py
|
|
27
|
+
src/wop_sdk/config/wopSdkConfig.json
|
|
21
28
|
src/wop_sdk/transports/__init__.py
|
|
22
29
|
src/wop_sdk/transports/httpx_transport.py
|
|
23
30
|
src/wop_sdk/transports/requests_transport.py
|
|
@@ -25,6 +32,8 @@ src/wop_sdk/transports/urllib_transport.py
|
|
|
25
32
|
tests/test_bdd.py
|
|
26
33
|
tests/test_canonical.py
|
|
27
34
|
tests/test_client.py
|
|
35
|
+
tests/test_config.py
|
|
36
|
+
tests/test_config_loading.py
|
|
28
37
|
tests/test_coverage_gaps.py
|
|
29
38
|
tests/test_digest.py
|
|
30
39
|
tests/test_encoding.py
|
|
@@ -33,6 +42,7 @@ tests/test_interop.py
|
|
|
33
42
|
tests/test_keys.py
|
|
34
43
|
tests/test_mutation_gaps.py
|
|
35
44
|
tests/test_signature.py
|
|
45
|
+
tests/test_submchid.py
|
|
36
46
|
tests/test_suites.py
|
|
37
47
|
tests/test_transports.py
|
|
38
48
|
tests/test_transports_real.py
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
from importlib.metadata import PackageNotFoundError, version as _dist_version
|
|
7
7
|
|
|
8
8
|
from .client import RequestDraft, VerifyResult, WopClient, WopConfig
|
|
9
|
+
from .config import HttpClientSettings, WopSdkConfig, clear_cache, load, load_default
|
|
9
10
|
from .errors import (
|
|
11
|
+
ConfigurationError,
|
|
10
12
|
DecryptError,
|
|
11
13
|
DekConsistencyError,
|
|
12
14
|
DigestMismatchError,
|
|
@@ -15,6 +17,7 @@ from .errors import (
|
|
|
15
17
|
SignatureVerifyError,
|
|
16
18
|
SuiteParseError,
|
|
17
19
|
UnsupportedSuiteError,
|
|
20
|
+
WopGatewayResponseError,
|
|
18
21
|
WopSdkError,
|
|
19
22
|
)
|
|
20
23
|
from .suites import Suite, parse_suite
|
|
@@ -27,20 +30,27 @@ except PackageNotFoundError: # pragma: no cover —— 无分发元数据时的
|
|
|
27
30
|
__version__ = "0.0.0"
|
|
28
31
|
|
|
29
32
|
__all__ = [
|
|
30
|
-
"
|
|
31
|
-
"
|
|
33
|
+
"ConfigurationError",
|
|
34
|
+
"DecryptError",
|
|
35
|
+
"DekConsistencyError",
|
|
36
|
+
"DigestMismatchError",
|
|
37
|
+
"HttpClientSettings",
|
|
38
|
+
"KeyMaterialError",
|
|
39
|
+
"ProtocolFormatError",
|
|
32
40
|
"RequestDraft",
|
|
33
|
-
"
|
|
41
|
+
"SignatureVerifyError",
|
|
34
42
|
"Suite",
|
|
35
|
-
"parse_suite",
|
|
36
|
-
"WopSdkError",
|
|
37
43
|
"SuiteParseError",
|
|
38
44
|
"UnsupportedSuiteError",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
+
"VerifyResult",
|
|
46
|
+
"WopClient",
|
|
47
|
+
"WopConfig",
|
|
48
|
+
"WopGatewayResponseError",
|
|
49
|
+
"WopSdkConfig",
|
|
50
|
+
"WopSdkError",
|
|
45
51
|
"__version__",
|
|
52
|
+
"clear_cache",
|
|
53
|
+
"load",
|
|
54
|
+
"load_default",
|
|
55
|
+
"parse_suite",
|
|
46
56
|
]
|