secure-crypto-top-sdk 0.1.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/LICENSE +21 -0
- package/README.md +238 -0
- package/dist/base-v1-7dHNy.d.mts +183 -0
- package/dist/base-v1-7dHNy.d.ts +183 -0
- package/dist/client.d.mts +72 -0
- package/dist/client.d.ts +72 -0
- package/dist/client.js +1436 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +1406 -0
- package/dist/client.mjs.map +1 -0
- package/dist/index.d.mts +162 -0
- package/dist/index.d.ts +162 -0
- package/dist/index.js +1393 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1335 -0
- package/dist/index.mjs.map +1 -0
- package/dist/key-store-BCmOK04m.d.ts +49 -0
- package/dist/key-store-BF0_3do0.d.mts +49 -0
- package/dist/server.d.mts +60 -0
- package/dist/server.d.ts +60 -0
- package/dist/server.js +1369 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +1338 -0
- package/dist/server.mjs.map +1 -0
- package/package.json +70 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { P as ProtocolKind, C as CipherAlgorithm, D as DigestAlgorithm } from './base-v1-7dHNy.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 浏览器端客户端公共类型
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
interface BaseClientConfig {
|
|
8
|
+
baseURL: string;
|
|
9
|
+
/** 加密密钥 - 64 字符 hex(32 字节) */
|
|
10
|
+
encryptionKey: string;
|
|
11
|
+
/** 签名密钥(>= 32 字符) */
|
|
12
|
+
hmacSecret: string;
|
|
13
|
+
/** 应用标识(TOP 协议需要) */
|
|
14
|
+
appKey?: string;
|
|
15
|
+
/** 客户端默认协议 */
|
|
16
|
+
protocol?: ProtocolKind;
|
|
17
|
+
/** 默认加密算法 */
|
|
18
|
+
cipher?: CipherAlgorithm;
|
|
19
|
+
/** 默认签名算法 */
|
|
20
|
+
digest?: DigestAlgorithm;
|
|
21
|
+
defaultHeaders?: Record<string, string>;
|
|
22
|
+
requestWindowMs?: number;
|
|
23
|
+
/** RSA 公钥 PEM(混合加密场景) */
|
|
24
|
+
rsaPublicKeyPem?: string;
|
|
25
|
+
fetchImpl?: typeof fetch;
|
|
26
|
+
}
|
|
27
|
+
interface RequestOptions {
|
|
28
|
+
session?: string;
|
|
29
|
+
cipher?: CipherAlgorithm;
|
|
30
|
+
digest?: DigestAlgorithm;
|
|
31
|
+
protocol?: ProtocolKind;
|
|
32
|
+
headers?: Record<string, string>;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 浏览器端 / 通用 fetch 客户端
|
|
38
|
+
*
|
|
39
|
+
* 支持:
|
|
40
|
+
* - 多种协议(protocol: 'custom' | 'top'),通过 envelope.protocol 字段协商
|
|
41
|
+
* - 多种加密/签名算法(可按请求级别覆盖)
|
|
42
|
+
* - 自动加密请求 + 解密响应 + 验签
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
declare class SecureClient {
|
|
46
|
+
protected readonly baseURL: string;
|
|
47
|
+
protected readonly encryptionKey: Buffer;
|
|
48
|
+
protected readonly hmacSecret: string;
|
|
49
|
+
protected readonly appKey?: string;
|
|
50
|
+
protected readonly defaultProtocol: ProtocolKind;
|
|
51
|
+
protected readonly defaultCipher: BaseClientConfig['cipher'];
|
|
52
|
+
protected readonly defaultDigest: BaseClientConfig['digest'];
|
|
53
|
+
protected readonly defaultHeaders: Record<string, string>;
|
|
54
|
+
protected readonly requestWindowMs: number;
|
|
55
|
+
protected readonly rsaPublicKeyPem?: string;
|
|
56
|
+
protected readonly fetchImpl: typeof fetch;
|
|
57
|
+
constructor(config: BaseClientConfig);
|
|
58
|
+
/**
|
|
59
|
+
* 发起加密请求并解密响应
|
|
60
|
+
*/
|
|
61
|
+
request<T = unknown>(method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', path: string, options?: RequestOptions & {
|
|
62
|
+
body?: unknown;
|
|
63
|
+
}): Promise<T>;
|
|
64
|
+
protected decryptResponseOnly(envelope: any, protocolKind: ProtocolKind): Promise<unknown>;
|
|
65
|
+
get<T = unknown>(path: string, options?: RequestOptions): Promise<T>;
|
|
66
|
+
post<T = unknown>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
67
|
+
put<T = unknown>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
68
|
+
delete<T = unknown>(path: string, options?: RequestOptions): Promise<T>;
|
|
69
|
+
patch<T = unknown>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { type BaseClientConfig, type RequestOptions, SecureClient };
|