@h-ai/crypto 0.1.0-alpha.68 → 0.1.0-alpha.70
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.en.md +5 -1
- package/README.ja.md +5 -1
- package/README.md +5 -1
- package/dist/index.d.ts +146 -55
- package/dist/index.js +159 -44
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/README.en.md
CHANGED
|
@@ -252,7 +252,11 @@ Only authenticated protocol v2 is accepted. Independent random SM4-CBC and HMAC-
|
|
|
252
252
|
|
|
253
253
|
Empty POSTs still send an authenticated envelope for empty plaintext. GET/HEAD carry it in X-Hai-Transport; bodyless responses such as 204/304/HEAD use the same header. Other requests/responses carry a JSON envelope and X-Encrypted: true. The client must match the original request context and HTTP status; missing markers, old formats and authentication failures reject. Exclude plaintext endpoints explicitly with excludePaths. CORS must allow and expose X-Hai-Transport. TLS authenticates handshake keys; this protocol does not replace IAM authorization.
|
|
254
254
|
|
|
255
|
-
|
|
255
|
+
Set `transport.maxPlaintextBytes` for both request and response JSON plaintext, measured in UTF-8 bytes: default 1 MiB, integer range 1 KiB–64 MiB. Clients learn the server limit during key exchange. `resolveTransportBodyLimits()` derives encrypted/proxy bytes as twice the plaintext limit plus 32 KiB. Handshake, public-key, header and replay constraints remain independent. Oversized streams are cancelled and readers released: requests return 413; oversized responses return an encrypted 500 capacity error, recognized as `TransportBodyTooLargeError` / `hai:crypto:070`. [容量配置、文件换算与升级](TRANSPORT-CAPACITY.md)。
|
|
256
|
+
|
|
257
|
+
serv/kit return an encrypted HTTP 400 time error for an out-of-window message only after request binding, signature and MAC verification. The client throws `TransportTimeError` (`hai:crypto:071`) with advice to synchronize device/server clocks and refresh. `api-client` maps it to `VALIDATION_FAILED` and preserves `cause.transportCode`. Requests are not replayed automatically and replay windows remain unchanged; tampered or unauthenticated messages retain the generic authentication failure.
|
|
258
|
+
|
|
259
|
+
Custom HTTP adapters check `error instanceof TransportTimeError && error.context`, then encrypt the rejection with `createTransportErrorResponse(error, { manager, context: error.context })`. Never classify an unverified message by its timestamp.
|
|
256
260
|
|
|
257
261
|
Custom HTTP adapters can import the pure `readTransportBody(stream, { maxBytes, signal? })` helper from the root entry without `crypto.init()`. Pass the original stream, rebuild Request/Response after reading, and clear stale Content-Length/Content-Encoding. The helper throws RangeError for byte limits, TypeError for invalid UTF-8, and preserves the original read/abort failure.
|
|
258
262
|
|
package/README.ja.md
CHANGED
|
@@ -252,7 +252,11 @@ const server = crypto.transport.createServer({ serverKeyRing, keyStore })
|
|
|
252
252
|
|
|
253
253
|
空の POST も空平文の認証封装を送ります。GET/HEAD は X-Hai-Transport ヘッダー、204/304/HEAD など本文なし応答も同じヘッダーを使います。他の要求・応答は JSON 本文と X-Encrypted: true を使います。クライアントは元の要求コンテキストと HTTP status を照合し、マーカー欠落、旧形式、認証失敗では reject します。平文 endpoint は excludePaths で明示的に除外し、CORS では X-Hai-Transport を許可・公開してください。鍵交換の公開鍵認証は TLS に依存し、IAM の業務認可は別に必要です。
|
|
254
254
|
|
|
255
|
-
|
|
255
|
+
`transport.maxPlaintextBytes` でリクエストとレスポンスの JSON 平文容量を共通設定します。単位は UTF-8 バイト、既定値は 1 MiB、有効範囲は 1 KiB~64 MiB の整数です。クライアントは鍵交換で上限を取得し、`resolveTransportBodyLimits()` が暗号文とプロキシ容量(平文の 2 倍 + 32 KiB)を算出します。鍵交換、公開鍵、認証ヘッダー、防リプレイ制約は独立です。超過時は元ストリームを停止して reader を解放します。要求は 413、応答は暗号化された 500 容量エラーとなり、`TransportBodyTooLargeError` / `hai:crypto:070` で識別できます。 [容量配置、文件换算与升级](TRANSPORT-CAPACITY.md)。
|
|
256
|
+
|
|
257
|
+
serv/kit は要求の結合、署名、MAC を検証した後、時間窓を超えた報文に暗号化した HTTP 400 時刻エラーを返します。クライアントは `TransportTimeError`(`hai:crypto:071`)で端末とサーバーの時刻同期・再読み込みを案内します。`api-client` は `VALIDATION_FAILED` に変換し `cause.transportCode` に原因を保持します。自動再送やリプレイ時間窓の緩和は行わず、改ざん・未認証の要求は従来の認証エラーです。
|
|
258
|
+
|
|
259
|
+
独自 HTTP アダプターでは `error instanceof TransportTimeError && error.context` を確認し、`createTransportErrorResponse(error, { manager, context: error.context })` で拒否応答を暗号化します。未認証の報文のタイムスタンプだけで時刻異常を診断しないでください。
|
|
256
260
|
|
|
257
261
|
独自 HTTP アダプターではルート入口の純粋関数 `readTransportBody(stream, { maxBytes, signal? })` を `crypto.init()` なしで利用できます。元のストリームを渡し、読み取り後は Request/Response を再構築して古い Content-Length/Content-Encoding を削除してください。上限超過は RangeError、不正 UTF-8 は TypeError、読み取り例外・signal.reason は元の理由で拒否します。ストリームのキャンセル処理が失敗しても元の例外を維持します。
|
|
258
262
|
|
package/README.md
CHANGED
|
@@ -252,7 +252,11 @@ const server = crypto.transport.createServer({ serverKeyRing, keyStore })
|
|
|
252
252
|
|
|
253
253
|
空 POST 也发送空明文的认证封装;GET/HEAD 将封装放在 X-Hai-Transport 头,204/304/HEAD 等无正文响应也使用同名头承载认证封装。其它请求/响应在 JSON 正文承载封装并带 X-Encrypted: true。客户端必须关联原请求上下文和 HTTP status,缺标记、旧格式或认证失败一律 reject;明文接口只能经 excludePaths 显式排除。CORS 须允许并暴露 X-Hai-Transport。握手公钥的真实性依赖 TLS,不替代 IAM 业务授权。
|
|
254
254
|
|
|
255
|
-
|
|
255
|
+
业务容量通过 `transport.maxPlaintextBytes` 统一配置:默认 1 MiB,整数范围 1 KiB~64 MiB,请求和响应共用 UTF-8 明文字节预算。客户端从握手自动获取上限,密文与部署代理预算由 `resolveTransportBodyLimits()` 推导(两倍明文 + 32 KiB)。握手、公钥、认证头和防重放约束独立;超限取消原流并释放 reader,请求 413、响应为加密的 500 容量错误,客户端识别 `TransportBodyTooLargeError` / `hai:crypto:070`。 [容量配置、文件换算与升级](TRANSPORT-CAPACITY.md)。
|
|
256
|
+
|
|
257
|
+
serv/kit 对通过请求绑定、签名和 MAC 校验但超出时间窗口的报文返回加密的 HTTP 400 时间错误;客户端抛 `TransportTimeError`(`hai:crypto:071`),提示同步设备和服务器时间后刷新重试。`api-client` 映射为 `VALIDATION_FAILED`,在 `cause.transportCode` 保留该原因。不会自动重放请求或放宽防重放窗口;篡改或未认证报文仍返回通用认证失败。
|
|
258
|
+
|
|
259
|
+
自定义 HTTP 适配器检查失败原因 `error instanceof TransportTimeError && error.context` 后,使用 `createTransportErrorResponse(error, { manager, context: error.context })` 加密拒绝响应;不能根据未认证报文的时间戳给出可信时间诊断。
|
|
256
260
|
|
|
257
261
|
自定义 HTTP 适配器可从根入口使用纯工具 `readTransportBody(stream, { maxBytes, signal? })`,无需 `crypto.init()`。必须传入原始流;读取成功后重建 Request/Response,并清理旧 Content-Length/Content-Encoding。此工具对超限抛 RangeError,对无效 UTF-8 抛 TypeError,保留读取异常或 signal.reason;流取消清理失败不覆盖原异常。
|
|
258
262
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,13 +4,121 @@ import { CacheFunctions } from '@h-ai/cache';
|
|
|
4
4
|
import { ReldbFunctions } from '@h-ai/reldb';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @h-ai/crypto —
|
|
7
|
+
* @h-ai/crypto — 传输协议的字节预算与有界正文读取。
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* serv/kit 共享相同预算,不依赖可省略或伪造的 Content-Length。
|
|
10
|
+
* @module crypto-transport-body
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* 传输预算;业务预算由明文容量推导,安全字段保持独立。
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { resolveTransportBodyLimits, type TransportBodyLimits } from '@h-ai/crypto'
|
|
17
|
+
* const limits: TransportBodyLimits = resolveTransportBodyLimits(8 * 1024 * 1024)
|
|
18
|
+
* const proxyBytes = limits.encryptedPayloadBytes
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
interface TransportBodyLimits {
|
|
22
|
+
readonly keyExchangeBytes: number;
|
|
23
|
+
readonly envelopeHeaderBytes: number;
|
|
24
|
+
readonly publicKeyBytes: number;
|
|
25
|
+
readonly plaintextBytes: number;
|
|
26
|
+
readonly encryptedPayloadBytes: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 业务明文的有效 UTF-8 字节范围:1 KiB~64 MiB;不支持无限制。
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { TRANSPORT_PLAINTEXT_RANGE } from '@h-ai/crypto'
|
|
33
|
+
* const maximumBytes = TRANSPORT_PLAINTEXT_RANGE.max
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare const TRANSPORT_PLAINTEXT_RANGE: Readonly<{
|
|
37
|
+
min: 1024;
|
|
38
|
+
max: number;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* 默认UTF-8字节预算;按实际流读取,不依赖Content-Length,非字符串字符数限制。
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { readTransportBody, TRANSPORT_BODY_LIMITS } from '@h-ai/crypto'
|
|
46
|
+
* const request = new Request('https://api.example.com/api/v1/orders', { method: 'POST', body: JSON.stringify({ message: 'hello' }) })
|
|
47
|
+
* const text = await readTransportBody(request.body, { maxBytes: TRANSPORT_BODY_LIMITS.plaintextBytes, signal: request.signal })
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
declare const TRANSPORT_BODY_LIMITS: TransportBodyLimits;
|
|
51
|
+
/**
|
|
52
|
+
* 校验单一业务明文容量并推导双向密文预算;返回不可变快照。
|
|
53
|
+
* SM4-CBC 使用十六进制编码,预算为明文的两倍加 32 KiB(填充及认证封装)。
|
|
54
|
+
* @param maxPlaintextBytes - UTF-8 字节数,默认 1 MiB,有效范围 1 KiB~64 MiB 的整数。
|
|
55
|
+
* @returns 明文、密文及独立安全预算。
|
|
56
|
+
* @throws RangeError - 配置无效;不接受字符串、null、无限制或静默回退。
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { resolveTransportBodyLimits } from '@h-ai/crypto'
|
|
60
|
+
* const limits = resolveTransportBodyLimits(8 * 1024 * 1024)
|
|
61
|
+
* const nginxLimit = limits.encryptedPayloadBytes
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
declare function resolveTransportBodyLimits(maxPlaintextBytes?: number): TransportBodyLimits;
|
|
65
|
+
/**
|
|
66
|
+
* 可识别的容量错误;只包含方向、阶段和字节数,不包含报文内容。
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { TransportBodyTooLargeError } from '@h-ai/crypto'
|
|
70
|
+
* const error = new TransportBodyTooLargeError(1024, 1025, { direction: 'request', stage: 'plaintext' })
|
|
71
|
+
* const diagnostic = { code: error.code, limitBytes: error.limitBytes, actualBytes: error.actualBytes }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
declare class TransportBodyTooLargeError extends RangeError {
|
|
75
|
+
readonly code: string | number;
|
|
76
|
+
readonly direction: 'request' | 'response';
|
|
77
|
+
readonly stage: 'plaintext' | 'encrypted' | 'header';
|
|
78
|
+
readonly limitBytes: number;
|
|
79
|
+
readonly actualBytes?: number;
|
|
80
|
+
constructor(limitBytes: number, actualBytes?: number, options?: {
|
|
81
|
+
direction?: 'request' | 'response';
|
|
82
|
+
stage?: 'plaintext' | 'encrypted' | 'header';
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 有界原流读取选项;maxBytes是非负安全整数,signal取消等待和底层流。
|
|
11
87
|
*
|
|
12
|
-
* @
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* import { readTransportBody, type ReadTransportBodyOptions } from '@h-ai/crypto'
|
|
91
|
+
* const request = new Request('https://api.example.com/api/v1/orders', { method: 'POST', body: 'hello' })
|
|
92
|
+
* const options: ReadTransportBodyOptions = { maxBytes: 1024, signal: request.signal }
|
|
93
|
+
* const text = await readTransportBody(request.body, options)
|
|
94
|
+
* ```
|
|
13
95
|
*/
|
|
96
|
+
interface ReadTransportBodyOptions {
|
|
97
|
+
/** 允许读取的字节总数,必须为非负安全整数。 */
|
|
98
|
+
readonly maxBytes: number;
|
|
99
|
+
/** 请求取消时中止等待中的读取并取消底层流。 */
|
|
100
|
+
readonly signal?: AbortSignal;
|
|
101
|
+
/** 超限诊断方向;默认 request。 */
|
|
102
|
+
readonly direction?: 'request' | 'response';
|
|
103
|
+
/** 超限诊断阶段;默认 plaintext。 */
|
|
104
|
+
readonly stage?: 'plaintext' | 'encrypted' | 'header';
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 逐块读取原始字节流并严格UTF-8解码;超限/取消后取消流并释放reader,清理失败不覆盖原异常。
|
|
108
|
+
* 不要传入clone/tee分支,否则另一分支仍可能保留数据。
|
|
109
|
+
* @param stream - 原始流;null返回空串但仍检查取消。
|
|
110
|
+
* @param options - 字节预算与取消信号。
|
|
111
|
+
* @returns 解码文本。
|
|
112
|
+
* @throws RangeError预算无效或超限;非法UTF-8、流异常和signal.reason继续抛出。
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* import { readTransportBody } from '@h-ai/crypto'
|
|
117
|
+
* const request = new Request('https://api.example.com/api/v1/orders', { method: 'POST', body: 'hello' })
|
|
118
|
+
* const text = await readTransportBody(request.body, { maxBytes: 1024, signal: request.signal })
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
declare function readTransportBody(stream: ReadableStream<Uint8Array> | null, options: ReadTransportBodyOptions): Promise<string>;
|
|
14
122
|
|
|
15
123
|
/**
|
|
16
124
|
* 认证传输v2的头名、窗口与默认协商子路径;各HTTP适配器共用,不手写漂移常量。
|
|
@@ -75,6 +183,8 @@ interface KeyExchangeRequest {
|
|
|
75
183
|
* ```
|
|
76
184
|
*/
|
|
77
185
|
interface KeyExchangeResponse {
|
|
186
|
+
/** 服务端业务明文 UTF-8 字节上限;缺省表示旧服务端的 1 MiB 默认值。 */
|
|
187
|
+
readonly maxPlaintextBytes?: number;
|
|
78
188
|
/** 服务端当前加密密钥版本;业务请求必须带回该值。 */
|
|
79
189
|
readonly serverKeyId: string;
|
|
80
190
|
readonly serverPublicKey: string;
|
|
@@ -436,6 +546,8 @@ interface TransportKeyStore {
|
|
|
436
546
|
* ```
|
|
437
547
|
*/
|
|
438
548
|
interface TransportCreateServerOptions {
|
|
549
|
+
/** 双向业务明文 UTF-8 字节上限;默认 1 MiB,整数范围 1 KiB~64 MiB。 */
|
|
550
|
+
readonly maxPlaintextBytes?: number;
|
|
439
551
|
/** 必填受管服务端密钥环;没有隐式随机生成或进程密钥回退。 */
|
|
440
552
|
readonly serverKeyRing: TransportServerKeyRing;
|
|
441
553
|
/** 客户端公钥存储;生产必须注入跨节点共享实现。 */
|
|
@@ -473,6 +585,8 @@ interface TransportCreateServerOptions {
|
|
|
473
585
|
* ```
|
|
474
586
|
*/
|
|
475
587
|
interface TransportEncryptionManager {
|
|
588
|
+
/** 本管理器不可变的双向预算;由 maxPlaintextBytes 推导,安全预算独立。 */
|
|
589
|
+
readonly bodyLimits: TransportBodyLimits;
|
|
476
590
|
/**
|
|
477
591
|
* 当前新协商使用的服务端密钥 ID。
|
|
478
592
|
* @returns 直接返回值,使用前先初始化模块。
|
|
@@ -739,6 +853,8 @@ declare const HaiCryptoError: {
|
|
|
739
853
|
readonly HASH_FAILED: _h_ai_core.HaiErrorDef;
|
|
740
854
|
readonly HMAC_FAILED: _h_ai_core.HaiErrorDef;
|
|
741
855
|
readonly INVALID_IV: _h_ai_core.HaiErrorDef;
|
|
856
|
+
readonly TRANSPORT_PAYLOAD_TOO_LARGE: _h_ai_core.HaiErrorDef;
|
|
857
|
+
readonly TRANSPORT_TIME_INVALID: _h_ai_core.HaiErrorDef;
|
|
742
858
|
};
|
|
743
859
|
/**
|
|
744
860
|
* SM2 密文排列:1为C1C3C2默认值,0为显式C1C2C3;解密必须匹配加密排列。
|
|
@@ -1648,6 +1764,7 @@ interface TransportOperations {
|
|
|
1648
1764
|
* @param options - 实际调用输入,按该方法约束验证。
|
|
1649
1765
|
* @param options.keyExchangeUrl - 密钥协商端点完整 URL。
|
|
1650
1766
|
* @param options.fetch - 实际发送 HTTP 请求的 fetch,默认 `globalThis.fetch`。
|
|
1767
|
+
* @param options.maxPlaintextBytes - 可选本地明文 UTF-8 字节上限,默认跟随服务端。
|
|
1651
1768
|
* @returns 直接返回值,使用前先初始化模块。
|
|
1652
1769
|
*
|
|
1653
1770
|
* @example
|
|
@@ -1671,6 +1788,7 @@ interface TransportOperations {
|
|
|
1671
1788
|
createClient: (options: {
|
|
1672
1789
|
keyExchangeUrl: string;
|
|
1673
1790
|
fetch?: typeof fetch;
|
|
1791
|
+
maxPlaintextBytes?: number;
|
|
1674
1792
|
}) => TransportClient;
|
|
1675
1793
|
/** 协议常量(headers、密钥协商默认路径)。 */
|
|
1676
1794
|
readonly protocol: typeof TRANSPORT_PROTOCOL;
|
|
@@ -1795,67 +1913,40 @@ declare const crypto: CryptoFunctions;
|
|
|
1795
1913
|
*/
|
|
1796
1914
|
declare function isValidSM2PublicKey(publicKey: unknown): publicKey is string;
|
|
1797
1915
|
|
|
1916
|
+
/** @h-ai/crypto — serv/kit 共用的安全传输错误响应。 */
|
|
1917
|
+
|
|
1798
1918
|
/**
|
|
1799
|
-
*
|
|
1800
|
-
*
|
|
1801
|
-
* serv/kit 共享相同预算,不依赖可省略或伪造的 Content-Length。
|
|
1802
|
-
* @module crypto-transport-body
|
|
1803
|
-
*/
|
|
1804
|
-
/**
|
|
1805
|
-
* 协议固定UTF-8字节预算;按实际流读取,不依赖Content-Length,非字符串字符数限制。
|
|
1806
|
-
*
|
|
1807
|
-
* @example
|
|
1808
|
-
* ```ts
|
|
1809
|
-
* import { readTransportBody, TRANSPORT_BODY_LIMITS } from '@h-ai/crypto'
|
|
1810
|
-
* const request = new Request('https://api.example.com/api/v1/orders', { method: 'POST', body: JSON.stringify({ message: 'hello' }) })
|
|
1811
|
-
* const text = await readTransportBody(request.body, { maxBytes: TRANSPORT_BODY_LIMITS.plaintextBytes, signal: request.signal })
|
|
1812
|
-
* ```
|
|
1813
|
-
*/
|
|
1814
|
-
declare const TRANSPORT_BODY_LIMITS: {
|
|
1815
|
-
/** 密钥协商 JSON 的 UTF-8 总字节数。 */
|
|
1816
|
-
readonly keyExchangeBytes: 16384;
|
|
1817
|
-
/** GET/HEAD 请求及无正文响应的认证头封装 UTF-8 上限。 */
|
|
1818
|
-
readonly envelopeHeaderBytes: 16384;
|
|
1819
|
-
/** 单个协商公钥的 UTF-8 字节数。 */
|
|
1820
|
-
readonly publicKeyBytes: 4096;
|
|
1821
|
-
/** 解密后的请求/加密前的响应明文字节数。 */
|
|
1822
|
-
readonly plaintextBytes: 1048576;
|
|
1823
|
-
/** 密文 JSON 的 UTF-8 总字节数(2 MiB + 32 KiB,含 CBC 填充与全部认证字段)。 */
|
|
1824
|
-
readonly encryptedPayloadBytes: 2129920;
|
|
1825
|
-
};
|
|
1826
|
-
/**
|
|
1827
|
-
* 有界原流读取选项;maxBytes是非负安全整数,signal取消等待和底层流。
|
|
1828
|
-
*
|
|
1919
|
+
* 已认证请求的时间窗口错误;只提供校时建议,不调整时钟或放宽防重放窗口。
|
|
1829
1920
|
* @example
|
|
1830
1921
|
* ```ts
|
|
1831
|
-
* import {
|
|
1832
|
-
* const
|
|
1833
|
-
*
|
|
1834
|
-
* const text = await readTransportBody(request.body, options)
|
|
1922
|
+
* import { TransportTimeError } from '@h-ai/crypto'
|
|
1923
|
+
* const error = new TransportTimeError()
|
|
1924
|
+
* // 展示 error.message;同步设备/服务器时间后由用户刷新重试。
|
|
1835
1925
|
* ```
|
|
1836
1926
|
*/
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
readonly
|
|
1840
|
-
|
|
1841
|
-
readonly signal?: AbortSignal;
|
|
1927
|
+
declare class TransportTimeError extends Error {
|
|
1928
|
+
readonly context?: TransportMessageContext | undefined;
|
|
1929
|
+
readonly code: string | number;
|
|
1930
|
+
constructor(context?: TransportMessageContext | undefined);
|
|
1842
1931
|
}
|
|
1843
1932
|
/**
|
|
1844
|
-
*
|
|
1845
|
-
*
|
|
1846
|
-
* @param
|
|
1847
|
-
* @param
|
|
1848
|
-
* @
|
|
1849
|
-
* @
|
|
1850
|
-
*
|
|
1933
|
+
* 创建脱敏传输错误;已验证绑定、签名和 MAC 的时间/响应容量错误继续加密,请求读取超限返回 HTTP 413。
|
|
1934
|
+
* @param error - 容量或时间错误,不包含业务报文。
|
|
1935
|
+
* @param authenticated - 仅在请求绑定、签名和 MAC 已验证后提供管理器和上下文。
|
|
1936
|
+
* @param authenticated.manager - 使用原服务端预算的管理器。
|
|
1937
|
+
* @param authenticated.context - 已验证请求绑定、签名和 MAC 的上下文;时间拒绝不会放行业务。
|
|
1938
|
+
* @returns 可诊断的失败响应;加密失败仍只返回错误,不发送原业务响应。
|
|
1851
1939
|
* @example
|
|
1852
1940
|
* ```ts
|
|
1853
|
-
* import {
|
|
1854
|
-
* const
|
|
1855
|
-
* const
|
|
1941
|
+
* import { createTransportErrorResponse, TransportBodyTooLargeError } from '@h-ai/crypto'
|
|
1942
|
+
* const response = await createTransportErrorResponse(new TransportBodyTooLargeError(1024, 1025))
|
|
1943
|
+
* const status = response.status // 413
|
|
1856
1944
|
* ```
|
|
1857
1945
|
*/
|
|
1858
|
-
declare function
|
|
1946
|
+
declare function createTransportErrorResponse(error: TransportBodyTooLargeError | TransportTimeError, authenticated?: {
|
|
1947
|
+
manager: TransportEncryptionManager;
|
|
1948
|
+
context: TransportMessageContext;
|
|
1949
|
+
}): Promise<Response>;
|
|
1859
1950
|
|
|
1860
1951
|
/**
|
|
1861
1952
|
* @h-ai/crypto — 服务端受管传输密钥环的安全解析。
|
|
@@ -2096,4 +2187,4 @@ interface ReldbTransportKeyStore extends TransportKeyStore {
|
|
|
2096
2187
|
*/
|
|
2097
2188
|
declare function createReldbTransportKeyStore(options: CreateReldbTransportKeyStoreOptions): ReldbTransportKeyStore;
|
|
2098
2189
|
|
|
2099
|
-
export { type AsymmetricEncryptOptions, type AsymmetricOperations, type CipherMode, type CreateRedisTransportKeyStoreOptions, type CreateReldbTransportKeyStoreOptions, type CryptoFunctions, type EncryptWithIVResult, type EncryptedPayload, type EncryptedRequestPayload, HaiCryptoError, type HashOperations, type HashOptions, type KeyExchangeRequest, type KeyExchangeResponse, type KeyPair, type PasswordConfig, type PasswordOperations, type ReadTransportBodyOptions, type ReldbTransportKeyStore, type SignOptions, type SymmetricCbcEncryptedPayload, type SymmetricCiphertextEncoding, type SymmetricDecryptInput, type SymmetricEncryptOptions, type SymmetricEncryptedPayload, type SymmetricMode, type SymmetricOperations, TRANSPORT_BODY_LIMITS, TRANSPORT_PROTOCOL, type TransportClient, type TransportCreateServerOptions, type TransportCryptoServiceLike, type TransportEncryptionManager, type TransportKeyPair, type TransportKeyStore, type TransportMessageContext, type TransportOperations, type TransportRequestContext, type TransportServerKeyRing, authenticateTransportRequest, createInMemoryKeyStore, createRedisTransportKeyStore, createReldbTransportKeyStore, crypto, isValidSM2PublicKey, parseTransportServerKeyRing, readTransportBody };
|
|
2190
|
+
export { type AsymmetricEncryptOptions, type AsymmetricOperations, type CipherMode, type CreateRedisTransportKeyStoreOptions, type CreateReldbTransportKeyStoreOptions, type CryptoFunctions, type EncryptWithIVResult, type EncryptedPayload, type EncryptedRequestPayload, HaiCryptoError, type HashOperations, type HashOptions, type KeyExchangeRequest, type KeyExchangeResponse, type KeyPair, type PasswordConfig, type PasswordOperations, type ReadTransportBodyOptions, type ReldbTransportKeyStore, type SignOptions, type SymmetricCbcEncryptedPayload, type SymmetricCiphertextEncoding, type SymmetricDecryptInput, type SymmetricEncryptOptions, type SymmetricEncryptedPayload, type SymmetricMode, type SymmetricOperations, TRANSPORT_BODY_LIMITS, TRANSPORT_PLAINTEXT_RANGE, TRANSPORT_PROTOCOL, type TransportBodyLimits, TransportBodyTooLargeError, type TransportClient, type TransportCreateServerOptions, type TransportCryptoServiceLike, type TransportEncryptionManager, type TransportKeyPair, type TransportKeyStore, type TransportMessageContext, type TransportOperations, type TransportRequestContext, type TransportServerKeyRing, TransportTimeError, authenticateTransportRequest, createInMemoryKeyStore, createRedisTransportKeyStore, createReldbTransportKeyStore, createTransportErrorResponse, crypto, isValidSM2PublicKey, parseTransportServerKeyRing, readTransportBody, resolveTransportBodyLimits };
|