@alibarbar/common 1.0.10 → 1.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.
Files changed (53) hide show
  1. package/dist/algorithm.cjs +1 -1
  2. package/dist/algorithm.js +1 -1
  3. package/dist/array.cjs +1 -1
  4. package/dist/array.js +1 -1
  5. package/dist/color.cjs +1 -1
  6. package/dist/color.js +1 -1
  7. package/dist/crypto.cjs +109 -1
  8. package/dist/crypto.d.mts +48 -1
  9. package/dist/crypto.d.ts +48 -1
  10. package/dist/crypto.js +104 -2
  11. package/dist/data-structure.cjs +1 -1
  12. package/dist/data-structure.js +1 -1
  13. package/dist/date.cjs +1 -1
  14. package/dist/date.js +1 -1
  15. package/dist/dom.cjs +1 -1
  16. package/dist/dom.js +1 -1
  17. package/dist/file.cjs +1 -1
  18. package/dist/file.js +1 -1
  19. package/dist/i18n.cjs +1 -1
  20. package/dist/i18n.js +1 -1
  21. package/dist/index.cjs +841 -430
  22. package/dist/index.d.mts +3 -3
  23. package/dist/index.d.ts +3 -3
  24. package/dist/index.js +832 -431
  25. package/dist/network.cjs +1 -1
  26. package/dist/network.js +1 -1
  27. package/dist/number.cjs +1 -1
  28. package/dist/number.js +1 -1
  29. package/dist/object.cjs +1 -1
  30. package/dist/object.js +1 -1
  31. package/dist/performance.cjs +1 -1
  32. package/dist/performance.js +1 -1
  33. package/dist/storage.cjs +481 -98
  34. package/dist/storage.d.mts +46 -1
  35. package/dist/storage.d.ts +46 -1
  36. package/dist/storage.js +478 -99
  37. package/dist/string.cjs +1 -1
  38. package/dist/string.js +1 -1
  39. package/dist/tracking.cjs +1 -1
  40. package/dist/tracking.js +1 -1
  41. package/dist/transform.cjs +1 -1
  42. package/dist/transform.js +1 -1
  43. package/dist/upload.cjs +2 -2
  44. package/dist/upload.d.mts +1 -1
  45. package/dist/upload.d.ts +1 -1
  46. package/dist/upload.js +2 -2
  47. package/dist/url.cjs +1 -1
  48. package/dist/url.js +1 -1
  49. package/dist/validation.cjs +1 -1
  50. package/dist/validation.js +1 -1
  51. package/package.json +1 -1
  52. /package/dist/{upload-DchqyDBQ.d.mts → index-DchqyDBQ.d.mts} +0 -0
  53. /package/dist/{upload-DchqyDBQ.d.ts → index-DchqyDBQ.d.ts} +0 -0
@@ -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密钥对
@@ -25,6 +58,18 @@ declare function setStorageKeyPair(keyPair: RSAKeyPair): void;
25
58
  * @returns 全局密钥对或null
26
59
  */
27
60
  declare function getStorageKeyPair(): RSAKeyPair | null;
61
+ /**
62
+ * 清除持久化的密钥(如果存在)
63
+ */
64
+ declare function clearPersistedKeys(): void;
65
+ /**
66
+ * 获取密钥使用计数
67
+ */
68
+ declare function getKeyUsageCount(): number;
69
+ /**
70
+ * 重置密钥使用计数
71
+ */
72
+ declare function resetKeyUsageCount(): void;
28
73
  /**
29
74
  * localStorage封装(支持过期时间和RSA加密)
30
75
  */
@@ -173,4 +218,4 @@ declare const storage: {
173
218
  clear(): void;
174
219
  };
175
220
 
176
- export { type StorageOptions, cookie, getStorageKeyPair, localStorage, sessionStorage, setStorageKeyPair, storage };
221
+ export { type StorageInitOptions, type StorageOptions, clearPersistedKeys, cookie, getKeyUsageCount, getStorageKeyPair, initializeStorageKeys, localStorage, resetKeyUsageCount, sessionStorage, setStorageKeyPair, storage };
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密钥对
@@ -25,6 +58,18 @@ declare function setStorageKeyPair(keyPair: RSAKeyPair): void;
25
58
  * @returns 全局密钥对或null
26
59
  */
27
60
  declare function getStorageKeyPair(): RSAKeyPair | null;
61
+ /**
62
+ * 清除持久化的密钥(如果存在)
63
+ */
64
+ declare function clearPersistedKeys(): void;
65
+ /**
66
+ * 获取密钥使用计数
67
+ */
68
+ declare function getKeyUsageCount(): number;
69
+ /**
70
+ * 重置密钥使用计数
71
+ */
72
+ declare function resetKeyUsageCount(): void;
28
73
  /**
29
74
  * localStorage封装(支持过期时间和RSA加密)
30
75
  */
@@ -173,4 +218,4 @@ declare const storage: {
173
218
  clear(): void;
174
219
  };
175
220
 
176
- export { type StorageOptions, cookie, getStorageKeyPair, localStorage, sessionStorage, setStorageKeyPair, storage };
221
+ export { type StorageInitOptions, type StorageOptions, clearPersistedKeys, cookie, getKeyUsageCount, getStorageKeyPair, initializeStorageKeys, localStorage, resetKeyUsageCount, sessionStorage, setStorageKeyPair, storage };