@alibarbar/common 1.0.10 → 1.1.1
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/dist/algorithm.cjs +1 -1
- package/dist/algorithm.js +1 -1
- package/dist/array.cjs +1 -1
- package/dist/array.js +1 -1
- package/dist/color.cjs +1 -1
- package/dist/color.js +1 -1
- package/dist/crypto.cjs +109 -1
- package/dist/crypto.d.mts +48 -1
- package/dist/crypto.d.ts +48 -1
- package/dist/crypto.js +104 -2
- package/dist/data-structure.cjs +1 -1
- package/dist/data-structure.js +1 -1
- package/dist/date.cjs +1 -1
- package/dist/date.js +1 -1
- package/dist/dom.cjs +1 -1
- package/dist/dom.js +1 -1
- package/dist/file.cjs +1 -1
- package/dist/file.js +1 -1
- package/dist/i18n.cjs +1 -1
- package/dist/i18n.js +1 -1
- package/dist/index.cjs +848 -415
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +838 -413
- package/dist/network.cjs +1 -1
- package/dist/network.js +1 -1
- package/dist/number.cjs +1 -1
- package/dist/number.js +1 -1
- package/dist/object.cjs +1 -1
- package/dist/object.js +1 -1
- package/dist/performance.cjs +1 -1
- package/dist/performance.js +1 -1
- package/dist/storage.cjs +509 -104
- package/dist/storage.d.mts +50 -73
- package/dist/storage.d.ts +50 -73
- package/dist/storage.js +505 -102
- package/dist/string.cjs +1 -1
- package/dist/string.js +1 -1
- package/dist/tracking.cjs +1 -1
- package/dist/tracking.js +1 -1
- package/dist/transform.cjs +1 -1
- package/dist/transform.js +1 -1
- package/dist/upload.cjs +2 -2
- package/dist/upload.d.mts +1 -1
- package/dist/upload.d.ts +1 -1
- package/dist/upload.js +2 -2
- package/dist/url.cjs +1 -1
- package/dist/url.js +1 -1
- package/dist/validation.cjs +1 -1
- package/dist/validation.js +1 -1
- package/package.json +3 -1
- /package/dist/{upload-DchqyDBQ.d.mts → index-DchqyDBQ.d.mts} +0 -0
- /package/dist/{upload-DchqyDBQ.d.ts → index-DchqyDBQ.d.ts} +0 -0
package/dist/storage.d.mts
CHANGED
|
@@ -15,6 +15,39 @@ interface StorageOptions {
|
|
|
15
15
|
/** 是否启用加密,默认为 true */
|
|
16
16
|
encrypt?: boolean;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* 存储初始化配置
|
|
20
|
+
*/
|
|
21
|
+
interface StorageInitOptions {
|
|
22
|
+
/** 是否自动生成密钥对(如果未设置),默认为 true */
|
|
23
|
+
autoGenerateKeys?: boolean;
|
|
24
|
+
/** 是否持久化密钥到 localStorage,默认为 false */
|
|
25
|
+
persistKeys?: boolean;
|
|
26
|
+
/** 密钥存储键名(用于持久化),如果未提供将自动生成随机键名 */
|
|
27
|
+
keyStorageKey?: string;
|
|
28
|
+
/** 用于加密持久化私钥的密码(如果提供,将使用 PBKDF2 + AES-GCM 加密) */
|
|
29
|
+
keyEncryptionPassword?: string;
|
|
30
|
+
/** PBKDF2 迭代次数,默认为 100000 */
|
|
31
|
+
pbkdf2Iterations?: number;
|
|
32
|
+
/** RSA密钥长度,默认为 2048 */
|
|
33
|
+
keyModulusLength?: number;
|
|
34
|
+
/** 是否启用HMAC数据完整性校验,默认为 true */
|
|
35
|
+
enableHMAC?: boolean;
|
|
36
|
+
/** 是否启用时间戳验证(防重放攻击),默认为 true */
|
|
37
|
+
enableTimestampValidation?: boolean;
|
|
38
|
+
/** 时间戳有效期(毫秒),默认 7 天,0 表示不验证 */
|
|
39
|
+
timestampMaxAge?: number;
|
|
40
|
+
/** 是否为生产环境(影响日志输出),默认为 false */
|
|
41
|
+
isProduction?: boolean;
|
|
42
|
+
/** 是否强制重新初始化(即使已经初始化过),默认为 false */
|
|
43
|
+
forceReinitialize?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 初始化存储密钥对
|
|
47
|
+
* @param options - 初始化选项
|
|
48
|
+
* @returns Promise<void>
|
|
49
|
+
*/
|
|
50
|
+
declare function initializeStorageKeys(options?: StorageInitOptions): Promise<void>;
|
|
18
51
|
/**
|
|
19
52
|
* 设置全局RSA密钥对
|
|
20
53
|
* @param keyPair - RSA密钥对
|
|
@@ -26,79 +59,17 @@ declare function setStorageKeyPair(keyPair: RSAKeyPair): void;
|
|
|
26
59
|
*/
|
|
27
60
|
declare function getStorageKeyPair(): RSAKeyPair | null;
|
|
28
61
|
/**
|
|
29
|
-
*
|
|
62
|
+
* 清除持久化的密钥(如果存在)
|
|
30
63
|
*/
|
|
31
|
-
declare
|
|
32
|
-
/**
|
|
33
|
-
* 设置值
|
|
34
|
-
* @param key - 键
|
|
35
|
-
* @param value - 值
|
|
36
|
-
* @param options - 选项(过期时间、密钥等)
|
|
37
|
-
* @returns Promise<void>
|
|
38
|
-
*/
|
|
39
|
-
set<T>(key: string, value: T, options?: {
|
|
40
|
-
expiry?: number;
|
|
41
|
-
publicKey?: CryptoKey;
|
|
42
|
-
}): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* 获取值
|
|
45
|
-
* @param key - 键
|
|
46
|
-
* @param options - 选项(默认值、私钥等)
|
|
47
|
-
* @returns Promise<T | undefined> 值或默认值
|
|
48
|
-
*/
|
|
49
|
-
get<T>(key: string, options?: {
|
|
50
|
-
defaultValue?: T;
|
|
51
|
-
privateKey?: CryptoKey;
|
|
52
|
-
}): Promise<T | undefined>;
|
|
53
|
-
/**
|
|
54
|
-
* 移除值
|
|
55
|
-
* @param key - 键
|
|
56
|
-
*/
|
|
57
|
-
remove(key: string): void;
|
|
58
|
-
/**
|
|
59
|
-
* 清空所有值
|
|
60
|
-
*/
|
|
61
|
-
clear(): void;
|
|
62
|
-
/**
|
|
63
|
-
* 获取所有键
|
|
64
|
-
* @returns 键数组
|
|
65
|
-
*/
|
|
66
|
-
keys(): string[];
|
|
67
|
-
};
|
|
64
|
+
declare function clearPersistedKeys(): void;
|
|
68
65
|
/**
|
|
69
|
-
*
|
|
66
|
+
* 获取密钥使用计数
|
|
70
67
|
*/
|
|
71
|
-
declare
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
* @param options - 选项(公钥等)
|
|
77
|
-
* @returns Promise<void>
|
|
78
|
-
*/
|
|
79
|
-
set<T>(key: string, value: T, options?: {
|
|
80
|
-
publicKey?: CryptoKey;
|
|
81
|
-
}): Promise<void>;
|
|
82
|
-
/**
|
|
83
|
-
* 获取值
|
|
84
|
-
* @param key - 键
|
|
85
|
-
* @param options - 选项(默认值、私钥等)
|
|
86
|
-
* @returns Promise<T | undefined> 值或默认值
|
|
87
|
-
*/
|
|
88
|
-
get<T>(key: string, options?: {
|
|
89
|
-
defaultValue?: T;
|
|
90
|
-
privateKey?: CryptoKey;
|
|
91
|
-
}): Promise<T | undefined>;
|
|
92
|
-
/**
|
|
93
|
-
* 移除值
|
|
94
|
-
* @param key - 键
|
|
95
|
-
*/
|
|
96
|
-
remove(key: string): void;
|
|
97
|
-
/**
|
|
98
|
-
* 清空所有值
|
|
99
|
-
*/
|
|
100
|
-
clear(): void;
|
|
101
|
-
};
|
|
68
|
+
declare function getKeyUsageCount(): number;
|
|
69
|
+
/**
|
|
70
|
+
* 重置密钥使用计数
|
|
71
|
+
*/
|
|
72
|
+
declare function resetKeyUsageCount(): void;
|
|
102
73
|
/**
|
|
103
74
|
* Cookie操作封装
|
|
104
75
|
*/
|
|
@@ -138,9 +109,10 @@ declare const cookie: {
|
|
|
138
109
|
getAll(): Record<string, string>;
|
|
139
110
|
};
|
|
140
111
|
/**
|
|
141
|
-
*
|
|
112
|
+
* 统一安全存储接口(自动选择存储方式,支持RSA加密)
|
|
113
|
+
* 这是推荐的主要导出接口
|
|
142
114
|
*/
|
|
143
|
-
declare const
|
|
115
|
+
declare const secureStorage: {
|
|
144
116
|
/**
|
|
145
117
|
* 设置值(优先使用localStorage,失败则使用sessionStorage)
|
|
146
118
|
* @param key - 键
|
|
@@ -171,6 +143,11 @@ declare const storage: {
|
|
|
171
143
|
* 清空所有值
|
|
172
144
|
*/
|
|
173
145
|
clear(): void;
|
|
146
|
+
/**
|
|
147
|
+
* 获取所有键名
|
|
148
|
+
* @returns 键名数组
|
|
149
|
+
*/
|
|
150
|
+
keys(): string[];
|
|
174
151
|
};
|
|
175
152
|
|
|
176
|
-
export { type StorageOptions, cookie, getStorageKeyPair,
|
|
153
|
+
export { type StorageInitOptions, type StorageOptions, clearPersistedKeys, cookie, getKeyUsageCount, getStorageKeyPair, initializeStorageKeys, resetKeyUsageCount, secureStorage, setStorageKeyPair };
|
package/dist/storage.d.ts
CHANGED
|
@@ -15,6 +15,39 @@ interface StorageOptions {
|
|
|
15
15
|
/** 是否启用加密,默认为 true */
|
|
16
16
|
encrypt?: boolean;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* 存储初始化配置
|
|
20
|
+
*/
|
|
21
|
+
interface StorageInitOptions {
|
|
22
|
+
/** 是否自动生成密钥对(如果未设置),默认为 true */
|
|
23
|
+
autoGenerateKeys?: boolean;
|
|
24
|
+
/** 是否持久化密钥到 localStorage,默认为 false */
|
|
25
|
+
persistKeys?: boolean;
|
|
26
|
+
/** 密钥存储键名(用于持久化),如果未提供将自动生成随机键名 */
|
|
27
|
+
keyStorageKey?: string;
|
|
28
|
+
/** 用于加密持久化私钥的密码(如果提供,将使用 PBKDF2 + AES-GCM 加密) */
|
|
29
|
+
keyEncryptionPassword?: string;
|
|
30
|
+
/** PBKDF2 迭代次数,默认为 100000 */
|
|
31
|
+
pbkdf2Iterations?: number;
|
|
32
|
+
/** RSA密钥长度,默认为 2048 */
|
|
33
|
+
keyModulusLength?: number;
|
|
34
|
+
/** 是否启用HMAC数据完整性校验,默认为 true */
|
|
35
|
+
enableHMAC?: boolean;
|
|
36
|
+
/** 是否启用时间戳验证(防重放攻击),默认为 true */
|
|
37
|
+
enableTimestampValidation?: boolean;
|
|
38
|
+
/** 时间戳有效期(毫秒),默认 7 天,0 表示不验证 */
|
|
39
|
+
timestampMaxAge?: number;
|
|
40
|
+
/** 是否为生产环境(影响日志输出),默认为 false */
|
|
41
|
+
isProduction?: boolean;
|
|
42
|
+
/** 是否强制重新初始化(即使已经初始化过),默认为 false */
|
|
43
|
+
forceReinitialize?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 初始化存储密钥对
|
|
47
|
+
* @param options - 初始化选项
|
|
48
|
+
* @returns Promise<void>
|
|
49
|
+
*/
|
|
50
|
+
declare function initializeStorageKeys(options?: StorageInitOptions): Promise<void>;
|
|
18
51
|
/**
|
|
19
52
|
* 设置全局RSA密钥对
|
|
20
53
|
* @param keyPair - RSA密钥对
|
|
@@ -26,79 +59,17 @@ declare function setStorageKeyPair(keyPair: RSAKeyPair): void;
|
|
|
26
59
|
*/
|
|
27
60
|
declare function getStorageKeyPair(): RSAKeyPair | null;
|
|
28
61
|
/**
|
|
29
|
-
*
|
|
62
|
+
* 清除持久化的密钥(如果存在)
|
|
30
63
|
*/
|
|
31
|
-
declare
|
|
32
|
-
/**
|
|
33
|
-
* 设置值
|
|
34
|
-
* @param key - 键
|
|
35
|
-
* @param value - 值
|
|
36
|
-
* @param options - 选项(过期时间、密钥等)
|
|
37
|
-
* @returns Promise<void>
|
|
38
|
-
*/
|
|
39
|
-
set<T>(key: string, value: T, options?: {
|
|
40
|
-
expiry?: number;
|
|
41
|
-
publicKey?: CryptoKey;
|
|
42
|
-
}): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* 获取值
|
|
45
|
-
* @param key - 键
|
|
46
|
-
* @param options - 选项(默认值、私钥等)
|
|
47
|
-
* @returns Promise<T | undefined> 值或默认值
|
|
48
|
-
*/
|
|
49
|
-
get<T>(key: string, options?: {
|
|
50
|
-
defaultValue?: T;
|
|
51
|
-
privateKey?: CryptoKey;
|
|
52
|
-
}): Promise<T | undefined>;
|
|
53
|
-
/**
|
|
54
|
-
* 移除值
|
|
55
|
-
* @param key - 键
|
|
56
|
-
*/
|
|
57
|
-
remove(key: string): void;
|
|
58
|
-
/**
|
|
59
|
-
* 清空所有值
|
|
60
|
-
*/
|
|
61
|
-
clear(): void;
|
|
62
|
-
/**
|
|
63
|
-
* 获取所有键
|
|
64
|
-
* @returns 键数组
|
|
65
|
-
*/
|
|
66
|
-
keys(): string[];
|
|
67
|
-
};
|
|
64
|
+
declare function clearPersistedKeys(): void;
|
|
68
65
|
/**
|
|
69
|
-
*
|
|
66
|
+
* 获取密钥使用计数
|
|
70
67
|
*/
|
|
71
|
-
declare
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
* @param options - 选项(公钥等)
|
|
77
|
-
* @returns Promise<void>
|
|
78
|
-
*/
|
|
79
|
-
set<T>(key: string, value: T, options?: {
|
|
80
|
-
publicKey?: CryptoKey;
|
|
81
|
-
}): Promise<void>;
|
|
82
|
-
/**
|
|
83
|
-
* 获取值
|
|
84
|
-
* @param key - 键
|
|
85
|
-
* @param options - 选项(默认值、私钥等)
|
|
86
|
-
* @returns Promise<T | undefined> 值或默认值
|
|
87
|
-
*/
|
|
88
|
-
get<T>(key: string, options?: {
|
|
89
|
-
defaultValue?: T;
|
|
90
|
-
privateKey?: CryptoKey;
|
|
91
|
-
}): Promise<T | undefined>;
|
|
92
|
-
/**
|
|
93
|
-
* 移除值
|
|
94
|
-
* @param key - 键
|
|
95
|
-
*/
|
|
96
|
-
remove(key: string): void;
|
|
97
|
-
/**
|
|
98
|
-
* 清空所有值
|
|
99
|
-
*/
|
|
100
|
-
clear(): void;
|
|
101
|
-
};
|
|
68
|
+
declare function getKeyUsageCount(): number;
|
|
69
|
+
/**
|
|
70
|
+
* 重置密钥使用计数
|
|
71
|
+
*/
|
|
72
|
+
declare function resetKeyUsageCount(): void;
|
|
102
73
|
/**
|
|
103
74
|
* Cookie操作封装
|
|
104
75
|
*/
|
|
@@ -138,9 +109,10 @@ declare const cookie: {
|
|
|
138
109
|
getAll(): Record<string, string>;
|
|
139
110
|
};
|
|
140
111
|
/**
|
|
141
|
-
*
|
|
112
|
+
* 统一安全存储接口(自动选择存储方式,支持RSA加密)
|
|
113
|
+
* 这是推荐的主要导出接口
|
|
142
114
|
*/
|
|
143
|
-
declare const
|
|
115
|
+
declare const secureStorage: {
|
|
144
116
|
/**
|
|
145
117
|
* 设置值(优先使用localStorage,失败则使用sessionStorage)
|
|
146
118
|
* @param key - 键
|
|
@@ -171,6 +143,11 @@ declare const storage: {
|
|
|
171
143
|
* 清空所有值
|
|
172
144
|
*/
|
|
173
145
|
clear(): void;
|
|
146
|
+
/**
|
|
147
|
+
* 获取所有键名
|
|
148
|
+
* @returns 键名数组
|
|
149
|
+
*/
|
|
150
|
+
keys(): string[];
|
|
174
151
|
};
|
|
175
152
|
|
|
176
|
-
export { type StorageOptions, cookie, getStorageKeyPair,
|
|
153
|
+
export { type StorageInitOptions, type StorageOptions, clearPersistedKeys, cookie, getKeyUsageCount, getStorageKeyPair, initializeStorageKeys, resetKeyUsageCount, secureStorage, setStorageKeyPair };
|