@h-ai/crypto 0.1.0-alpha.18 → 0.1.0-alpha.20
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 +43 -14
- package/dist/index.d.ts +126 -31
- package/dist/index.js +250 -61
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
|
|
14
14
|
## 安全声明
|
|
15
15
|
|
|
16
|
-
- **SM4
|
|
16
|
+
- **SM4 默认加密返回结构化密文**:`crypto.symmetric.encrypt(data, key)` 默认使用 CBC + 随机 IV,返回 `{ mode, ciphertext, iv, encoding }`;解密时把该对象传给 `crypto.symmetric.decrypt(payload, key)`。
|
|
17
17
|
- **SM4 `deriveKey(password, salt)` 不是 KDF**:仅为单次 SM3 哈希,不具备密码爆破抗性,**禁止用于密码存储**。如需密码哈希,使用 `crypto.password.hash(password)`;如需从密码派生密钥,请采用 PBKDF2 / scrypt / Argon2。
|
|
18
|
-
- **IV 必须唯一**:相同密钥下禁止复用 IV
|
|
18
|
+
- **IV 必须唯一**:相同密钥下禁止复用 IV;推荐使用默认 CBC 或 `encryptWithIV()` 每次自动生成。密文与 IV 需一同传输与存储(IV 可公开,不必保密)。
|
|
19
19
|
|
|
20
20
|
## 快速开始
|
|
21
21
|
|
|
@@ -81,33 +81,40 @@ if (hash.success) {
|
|
|
81
81
|
}
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
### 对称加密(
|
|
84
|
+
### 对称加密(CBC 默认 / 结构化密文)
|
|
85
85
|
|
|
86
86
|
```ts
|
|
87
87
|
// 生成随机密钥和 IV
|
|
88
88
|
const key = crypto.symmetric.generateKey()
|
|
89
89
|
const iv = crypto.symmetric.generateIV()
|
|
90
90
|
|
|
91
|
-
//
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
// 默认:CBC + 自动随机 IV,返回结构化密文
|
|
92
|
+
const safeEnc = crypto.symmetric.encrypt('data', key)
|
|
93
|
+
if (safeEnc.success) {
|
|
94
|
+
// safeEnc.data: { mode: 'cbc', ciphertext, iv, encoding: 'hex' }
|
|
95
|
+
const safeDec = crypto.symmetric.decrypt(safeEnc.data, key)
|
|
96
|
+
// safeDec.data === 'data'
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
// CBC
|
|
99
|
+
// CBC 指定 IV(仍然返回结构化密文)
|
|
99
100
|
const cbcEnc = crypto.symmetric.encrypt('data', key, { mode: 'cbc', iv })
|
|
100
101
|
if (cbcEnc.success) {
|
|
101
|
-
const cbcDec = crypto.symmetric.decrypt(cbcEnc.data, key
|
|
102
|
+
const cbcDec = crypto.symmetric.decrypt(cbcEnc.data, key)
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
//
|
|
105
|
+
// 结构化结果:自动生成 IV 的 CBC 加解密
|
|
105
106
|
const withIV = crypto.symmetric.encryptWithIV('data', key)
|
|
106
107
|
if (withIV.success) {
|
|
107
108
|
const dec = crypto.symmetric.decryptWithIV(withIV.data.ciphertext, key, withIV.data.iv)
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
//
|
|
111
|
+
// ECB 模式(❌ 不安全;只有底层协议明确要求时才显式指定)
|
|
112
|
+
const ecbEnc = crypto.symmetric.encrypt('data', key, { mode: 'ecb' })
|
|
113
|
+
if (ecbEnc.success) {
|
|
114
|
+
const ecbDec = crypto.symmetric.decrypt(ecbEnc.data, key)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 输出 base64 格式(ciphertext 字段为 base64,encoding 字段会标明)
|
|
111
118
|
const b64Enc = crypto.symmetric.encrypt('data', key, { outputFormat: 'base64' })
|
|
112
119
|
|
|
113
120
|
// ⚠️ 已弃用:从密码派生密钥(仅为单次 SM3 哈希,不是 KDF,禁止用于密码存储场景)
|
|
@@ -155,7 +162,7 @@ if (hashed.success) {
|
|
|
155
162
|
#### 使用流程
|
|
156
163
|
|
|
157
164
|
1. 先 `await crypto.init()`,确保 `crypto.asymmetric` 与 `crypto.symmetric` 已初始化。
|
|
158
|
-
2. 服务端调用 `crypto.transport.createServer()` 创建 `manager
|
|
165
|
+
2. 服务端调用 `crypto.transport.createServer()` 创建 `manager`;它持有服务端密钥对,并负责保存客户端公钥。多节点部署时可注入共享 `keyStore`。
|
|
159
166
|
3. 服务端提供一个 POST 密钥协商端点:接收 `{ clientPublicKey }`,调用 `manager.registerClientKey()` 注册客户端,再返回 `{ serverPublicKey: manager.getServerPublicKey(), clientId }`。
|
|
160
167
|
4. 客户端调用 `crypto.transport.createClient({ keyExchangeUrl })` 创建会话;首次 `client.init()` 或 `client.encryptedFetch()` 会自动完成这次协商。
|
|
161
168
|
5. 协商完成后,客户端请求会附带 `X-Client-Id`;若请求有 body,则 body 会被包装成 `{ encryptedKey, ciphertext, iv }`,并带上 `X-Encrypted: true`。无 body 的请求只附带 `X-Client-Id`,不会额外生成密文 body。
|
|
@@ -163,7 +170,13 @@ if (hashed.success) {
|
|
|
163
170
|
7. 服务端返回 JSON 响应前,用 `manager.encryptResponse(clientId, data)` 重新加密,并设置 `X-Encrypted: true`;客户端收到后会自动解密。
|
|
164
171
|
8. 客户端调用 `client.destroy()` 可清空当前会话;服务端调用 `manager.close()`,或在模块级调用 `await crypto.close()`,用于释放资源。
|
|
165
172
|
|
|
166
|
-
> 默认 `keyStore`
|
|
173
|
+
> 默认 `keyStore` 是进程内 FIFO 内存实现,超过 `maxClients` 会淘汰最早注册的客户端。多节点部署时,需要会话粘性(sticky session),或改用共享的 `TransportKeyStore` 实现来保存客户端公钥。
|
|
174
|
+
|
|
175
|
+
共享存储可直接复用 `@h-ai/crypto` 根入口导出的 provider 工厂:
|
|
176
|
+
|
|
177
|
+
- `createInMemoryKeyStore(maxClients)`:显式创建默认内存实现,常用于测试或自定义容量
|
|
178
|
+
- `createRedisTransportKeyStore({ cache, ttlSeconds? })`:复用 `@h-ai/cache`,通常配合 Redis provider 获取跨节点共享
|
|
179
|
+
- `createReldbTransportKeyStore({ reldb, ttlSeconds? })`:复用 `@h-ai/reldb`,自动建表 `hai_crypto_transport_client_keys`
|
|
167
180
|
|
|
168
181
|
```ts
|
|
169
182
|
// 服务端:通常由 serv.createApp({ transport: { crypto } }) 或 kit.createHandle({ crypto }) 内部调用
|
|
@@ -182,6 +195,22 @@ const response = await client.encryptedFetch('https://api.example.com/api/v1/ech
|
|
|
182
195
|
})
|
|
183
196
|
```
|
|
184
197
|
|
|
198
|
+
```ts
|
|
199
|
+
import { cache } from '@h-ai/cache'
|
|
200
|
+
import { createRedisTransportKeyStore, crypto } from '@h-ai/crypto'
|
|
201
|
+
|
|
202
|
+
await crypto.init()
|
|
203
|
+
await cache.init({ type: 'redis', host: '127.0.0.1', port: 6379 })
|
|
204
|
+
|
|
205
|
+
const server = crypto.transport.createServer({
|
|
206
|
+
keyStore: createRedisTransportKeyStore({ cache, ttlSeconds: 3600 }),
|
|
207
|
+
})
|
|
208
|
+
if (!server.success)
|
|
209
|
+
throw new Error(server.error.message)
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`encryptedFetch()` 的语义与原生 `fetch` 一致:网络失败、密钥协商失败、请求加密失败或响应解密失败时会 reject;业务层应在调用处按 fetch 错误处理策略统一捕获。
|
|
213
|
+
|
|
185
214
|
协议常量通过 `crypto.transport.protocol`(或 `TRANSPORT_PROTOCOL`)访问:`X-Client-Id`、`X-Encrypted`、默认 `/_hai/key-exchange`。
|
|
186
215
|
|
|
187
216
|
### 关闭模块
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as _h_ai_core from '@h-ai/core';
|
|
2
2
|
import { HaiResult } from '@h-ai/core';
|
|
3
|
+
import { CacheFunctions } from '@h-ai/cache';
|
|
4
|
+
import { ReldbFunctions } from '@h-ai/reldb';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* @h-ai/crypto — 传输加密类型与协议常量
|
|
@@ -40,8 +42,8 @@ interface KeyExchangeResponse {
|
|
|
40
42
|
}
|
|
41
43
|
/** 非对称密钥对。 */
|
|
42
44
|
interface TransportKeyPair {
|
|
43
|
-
publicKey: string;
|
|
44
|
-
privateKey: string;
|
|
45
|
+
readonly publicKey: string;
|
|
46
|
+
readonly privateKey: string;
|
|
45
47
|
}
|
|
46
48
|
/**
|
|
47
49
|
* 端到端传输的加密载荷格式。
|
|
@@ -94,6 +96,18 @@ interface TransportKeyStore {
|
|
|
94
96
|
/** 释放底层资源(关闭连接、清理定时器等)。 */
|
|
95
97
|
close?: () => Promise<void>;
|
|
96
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* 创建服务端传输加密管理器的配置。
|
|
101
|
+
*
|
|
102
|
+
* `keyStore` 未传时,默认使用 {@link createInMemoryKeyStore};此时可通过 `maxClients`
|
|
103
|
+
* 控制进程内 FIFO 容量。若传入共享 `keyStore`,则 `maxClients` 不再生效。
|
|
104
|
+
*/
|
|
105
|
+
interface TransportCreateServerOptions {
|
|
106
|
+
/** 客户端公钥存储;多节点部署时建议注入共享实现。 */
|
|
107
|
+
readonly keyStore?: TransportKeyStore;
|
|
108
|
+
/** 默认内存 keyStore 的最大容量(仅当 `keyStore` 未提供时生效)。 */
|
|
109
|
+
readonly maxClients?: number;
|
|
110
|
+
}
|
|
97
111
|
/**
|
|
98
112
|
* 服务端传输加密管理器。
|
|
99
113
|
*
|
|
@@ -139,7 +153,11 @@ interface TransportClient {
|
|
|
139
153
|
* 通常无需手动调用:`encryptedFetch` 在首次请求前会自动 `init()`。
|
|
140
154
|
*/
|
|
141
155
|
init: () => Promise<HaiResult<void>>;
|
|
142
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* 包装后的 fetch;签名与全局 `fetch` 一致,请求/响应自动加解密。
|
|
158
|
+
*
|
|
159
|
+
* @throws 与原生 fetch 一样,网络错误、密钥协商失败、加密失败或解密失败会 reject。
|
|
160
|
+
*/
|
|
143
161
|
encryptedFetch: typeof fetch;
|
|
144
162
|
/** 是否已完成密钥协商。 */
|
|
145
163
|
ready: () => boolean;
|
|
@@ -191,24 +209,37 @@ interface HashOptions {
|
|
|
191
209
|
}
|
|
192
210
|
/** 对称加密模式 */
|
|
193
211
|
type SymmetricMode = 'ecb' | 'cbc';
|
|
194
|
-
/**
|
|
195
|
-
|
|
196
|
-
|
|
212
|
+
/** 对称密文编码 */
|
|
213
|
+
type SymmetricCiphertextEncoding = 'hex' | 'base64';
|
|
214
|
+
/** 对称加密选项。默认 CBC,并自动生成随机 IV。 */
|
|
215
|
+
interface SymmetricEncryptOptions {
|
|
216
|
+
/** 加密模式;默认 cbc */
|
|
197
217
|
mode?: SymmetricMode;
|
|
198
|
-
/** IV 向量(CBC
|
|
218
|
+
/** IV 向量(CBC 模式可选;未传时自动生成,32 个十六进制字符) */
|
|
199
219
|
iv?: string;
|
|
200
|
-
/**
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
220
|
+
/** 密文输出编码;默认 hex */
|
|
221
|
+
outputFormat?: SymmetricCiphertextEncoding;
|
|
222
|
+
}
|
|
223
|
+
/** 对称加密结构化结果。 */
|
|
224
|
+
interface SymmetricEncryptedPayload {
|
|
225
|
+
/** 加密模式 */
|
|
226
|
+
readonly mode: SymmetricMode;
|
|
227
|
+
/** 密文内容,编码由 encoding 字段说明 */
|
|
228
|
+
readonly ciphertext: string;
|
|
229
|
+
/** CBC 模式的 IV 向量;ECB 模式无该字段 */
|
|
230
|
+
readonly iv?: string;
|
|
231
|
+
/** ciphertext 字段的编码 */
|
|
232
|
+
readonly encoding: SymmetricCiphertextEncoding;
|
|
204
233
|
}
|
|
205
|
-
/**
|
|
206
|
-
interface
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
/** IV 向量 */
|
|
210
|
-
iv: string;
|
|
234
|
+
/** CBC 模式结构化结果。 */
|
|
235
|
+
interface SymmetricCbcEncryptedPayload extends SymmetricEncryptedPayload {
|
|
236
|
+
readonly mode: 'cbc';
|
|
237
|
+
readonly iv: string;
|
|
211
238
|
}
|
|
239
|
+
/** 对称解密输入。 */
|
|
240
|
+
type SymmetricDecryptInput = SymmetricEncryptedPayload;
|
|
241
|
+
/** 带 IV 加密结果。 */
|
|
242
|
+
type EncryptWithIVResult = SymmetricCbcEncryptedPayload;
|
|
212
243
|
/** 密码哈希配置 */
|
|
213
244
|
interface PasswordConfig {
|
|
214
245
|
/** 盐值长度(默认 16) */
|
|
@@ -320,7 +351,7 @@ interface HashOperations {
|
|
|
320
351
|
* 对称加密操作接口
|
|
321
352
|
*
|
|
322
353
|
* 通过 `crypto.symmetric` 访问,需先调用 `crypto.init()`。
|
|
323
|
-
*
|
|
354
|
+
* 默认使用 CBC 并自动生成 IV;密文以结构化字段返回。
|
|
324
355
|
*/
|
|
325
356
|
interface SymmetricOperations {
|
|
326
357
|
/** 生成随机密钥(16 字节 = 32 个十六进制字符) */
|
|
@@ -330,23 +361,25 @@ interface SymmetricOperations {
|
|
|
330
361
|
/**
|
|
331
362
|
* 对称加密
|
|
332
363
|
*
|
|
364
|
+
* 默认 CBC + 自动随机 IV,返回 `{ mode, ciphertext, iv, encoding }`。
|
|
365
|
+
* 显式 `{ mode: 'ecb' }` 可使用 ECB,但不推荐用于新数据。
|
|
366
|
+
*
|
|
333
367
|
* @param data - 待加密明文
|
|
334
368
|
* @param key - 密钥(32 字符十六进制)
|
|
335
369
|
* @param options - 加密模式/IV/输出格式
|
|
336
|
-
* @returns
|
|
370
|
+
* @returns 成功时返回结构化密文;失败时返回 INVALID_KEY/INVALID_IV/ENCRYPTION_FAILED
|
|
337
371
|
*/
|
|
338
|
-
encrypt: (data: string, key: string, options?:
|
|
372
|
+
encrypt: (data: string, key: string, options?: SymmetricEncryptOptions) => HaiResult<SymmetricEncryptedPayload>;
|
|
339
373
|
/**
|
|
340
374
|
* 对称解密
|
|
341
375
|
*
|
|
342
|
-
*
|
|
376
|
+
* 解密 `encrypt()` 返回的结构化密文;不猜测字符串格式。
|
|
343
377
|
*
|
|
344
|
-
* @param
|
|
378
|
+
* @param payload - 结构化密文(包含 mode/ciphertext/iv/encoding)
|
|
345
379
|
* @param key - 密钥(32 字符十六进制)
|
|
346
|
-
* @param options - 解密模式/IV(需与加密时一致)
|
|
347
380
|
* @returns 成功时返回明文;失败时返回 INVALID_KEY/INVALID_IV/DECRYPTION_FAILED
|
|
348
381
|
*/
|
|
349
|
-
decrypt: (
|
|
382
|
+
decrypt: (payload: SymmetricDecryptInput, key: string) => HaiResult<string>;
|
|
350
383
|
/**
|
|
351
384
|
* 带 IV 加密(CBC 模式,自动生成随机 IV)
|
|
352
385
|
*
|
|
@@ -421,7 +454,7 @@ interface PasswordOperations {
|
|
|
421
454
|
* 使用流程(直接使用底层 transport 工厂时):
|
|
422
455
|
*
|
|
423
456
|
* 1. 先 `await crypto.init()`,确保 `crypto.asymmetric` / `crypto.symmetric` 已就绪。
|
|
424
|
-
* 2. 服务端调用 `crypto.transport.createServer()` 创建 `TransportEncryptionManager
|
|
457
|
+
* 2. 服务端调用 `crypto.transport.createServer()` 创建 `TransportEncryptionManager`;该管理器负责持有服务端密钥对,并管理客户端公钥。多节点部署时可通过 `options.keyStore` 注入共享存储。
|
|
425
458
|
* 3. 服务端暴露一个 POST 密钥协商端点:接收 `{ clientPublicKey }`,调用 `manager.registerClientKey()` 注册客户端公钥,再返回 `{ serverPublicKey: manager.getServerPublicKey(), clientId }`。
|
|
426
459
|
* 4. 客户端调用 `crypto.transport.createClient({ keyExchangeUrl })` 创建会话;首次 `client.init()` 或 `client.encryptedFetch()` 会自动完成密钥协商。
|
|
427
460
|
* 5. 协商完成后,客户端每次请求都会附带 `X-Client-Id`;若请求有 body,则 body 会被包装成 `{ encryptedKey, ciphertext, iv }`,并设置 `X-Encrypted: true`。
|
|
@@ -435,7 +468,9 @@ interface PasswordOperations {
|
|
|
435
468
|
*
|
|
436
469
|
* @example 服务端
|
|
437
470
|
* ```ts
|
|
438
|
-
* const result = crypto.transport.createServer(
|
|
471
|
+
* const result = crypto.transport.createServer({
|
|
472
|
+
* keyStore: createRedisTransportKeyStore({ cache, ttlSeconds: 3600 }),
|
|
473
|
+
* })
|
|
439
474
|
* if (!result.success) throw result.error
|
|
440
475
|
* const manager = result.data
|
|
441
476
|
* ```
|
|
@@ -454,15 +489,14 @@ interface TransportOperations {
|
|
|
454
489
|
/**
|
|
455
490
|
* 创建服务端传输加密管理器。
|
|
456
491
|
*
|
|
457
|
-
* options.
|
|
492
|
+
* options.keyStore:注入共享客户端公钥存储。
|
|
493
|
+
* options.maxClients:默认内存 keyStore 的最大客户端数(默认 10000,仅在未传 keyStore 时生效)。
|
|
458
494
|
* 成功返回 manager;密钥生成失败返回 `HaiCommonError.INTERNAL_ERROR`。
|
|
459
495
|
*
|
|
460
496
|
* @remarks
|
|
461
497
|
* 通常在服务启动阶段创建一次,并交给 HTTP 中间件 / 路由处理器复用。
|
|
462
498
|
*/
|
|
463
|
-
createServer: (options?:
|
|
464
|
-
maxClients?: number;
|
|
465
|
-
}) => HaiResult<TransportEncryptionManager>;
|
|
499
|
+
createServer: (options?: TransportCreateServerOptions) => HaiResult<TransportEncryptionManager>;
|
|
466
500
|
/**
|
|
467
501
|
* 创建客户端传输加密会话。
|
|
468
502
|
*
|
|
@@ -549,4 +583,65 @@ interface CryptoFunctions {
|
|
|
549
583
|
*/
|
|
550
584
|
declare const crypto: CryptoFunctions;
|
|
551
585
|
|
|
552
|
-
|
|
586
|
+
/**
|
|
587
|
+
* @h-ai/crypto — 传输加密内存 key store
|
|
588
|
+
*
|
|
589
|
+
* 提供默认的进程内客户端公钥存储实现。
|
|
590
|
+
* @module crypto-transport-store-memory
|
|
591
|
+
*/
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* 创建进程内 FIFO 客户端密钥存储。
|
|
595
|
+
*
|
|
596
|
+
* ⚠️ 进程内实现:多节点部署时需让客户端首次请求后保持「会话粘性」(sticky session),
|
|
597
|
+
* 否则后续请求路由到其他节点会因找不到客户端公钥而失败。需要跨节点请改用
|
|
598
|
+
* Redis / 数据库实现 {@link TransportKeyStore}。
|
|
599
|
+
*
|
|
600
|
+
* @param maxClients - 最大客户端数(默认 10000),超过后按注册顺序淘汰最早条目。
|
|
601
|
+
*/
|
|
602
|
+
declare function createInMemoryKeyStore(maxClients?: number): TransportKeyStore;
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* @h-ai/crypto — 传输加密 Redis key store
|
|
606
|
+
*
|
|
607
|
+
* 通过 `@h-ai/cache` 持久化客户端公钥;通常应传入已初始化为 Redis 的 `cache` 实例。
|
|
608
|
+
* @module crypto-transport-store-redis
|
|
609
|
+
*/
|
|
610
|
+
|
|
611
|
+
/** 创建 Redis 版传输 key store 的配置。 */
|
|
612
|
+
interface CreateRedisTransportKeyStoreOptions {
|
|
613
|
+
/** 已初始化的 `@h-ai/cache` 实例;生产环境通常应使用 Redis provider。 */
|
|
614
|
+
readonly cache: CacheFunctions;
|
|
615
|
+
/** 客户端公钥的 TTL(秒);未传则保持不过期。 */
|
|
616
|
+
readonly ttlSeconds?: number;
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* 创建基于 `@h-ai/cache` 的传输 key store。
|
|
620
|
+
*
|
|
621
|
+
* 说明:本实现依赖 cache 模块的 KV 语义;若要获得跨节点共享能力,应传入
|
|
622
|
+
* 已连接 Redis 的 `cache` 实例,而不是内存 provider。
|
|
623
|
+
*/
|
|
624
|
+
declare function createRedisTransportKeyStore(options: CreateRedisTransportKeyStoreOptions): TransportKeyStore;
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* @h-ai/crypto — 传输加密关系数据库 key store
|
|
628
|
+
*
|
|
629
|
+
* 通过 `@h-ai/reldb` 保存客户端公钥,适用于需要跨节点共享状态的服务端部署。
|
|
630
|
+
* @module crypto-transport-store-reldb
|
|
631
|
+
*/
|
|
632
|
+
|
|
633
|
+
/** 创建关系数据库版传输 key store 的配置。 */
|
|
634
|
+
interface CreateReldbTransportKeyStoreOptions {
|
|
635
|
+
/** 已初始化的 `@h-ai/reldb` 实例。 */
|
|
636
|
+
readonly reldb: ReldbFunctions;
|
|
637
|
+
/** 客户端公钥的 TTL(秒);未传则保持不过期。 */
|
|
638
|
+
readonly ttlSeconds?: number;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* 创建基于 `@h-ai/reldb` 的传输 key store。
|
|
642
|
+
*
|
|
643
|
+
* 首次读写时会自动创建 `hai_crypto_transport_client_keys` 表。
|
|
644
|
+
*/
|
|
645
|
+
declare function createReldbTransportKeyStore(options: CreateReldbTransportKeyStoreOptions): TransportKeyStore;
|
|
646
|
+
|
|
647
|
+
export { type AsymmetricEncryptOptions, type AsymmetricOperations, type CipherMode, type CreateRedisTransportKeyStoreOptions, type CreateReldbTransportKeyStoreOptions, type CryptoFunctions, type EncryptWithIVResult, type EncryptedPayload, HaiCryptoError, type HashOperations, type HashOptions, type KeyExchangeRequest, type KeyExchangeResponse, type KeyPair, type PasswordConfig, type PasswordOperations, type SignOptions, type SymmetricCbcEncryptedPayload, type SymmetricCiphertextEncoding, type SymmetricDecryptInput, type SymmetricEncryptOptions, type SymmetricEncryptedPayload, type SymmetricMode, type SymmetricOperations, TRANSPORT_PROTOCOL, type TransportClient, type TransportCreateServerOptions, type TransportCryptoServiceLike, type TransportEncryptionManager, type TransportKeyPair, type TransportKeyStore, type TransportOperations, createInMemoryKeyStore, createRedisTransportKeyStore, createReldbTransportKeyStore, crypto };
|