@digitaldefiance/node-ecies-lib 1.1.21 → 1.1.22

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 (211) hide show
  1. package/README.md +4 -0
  2. package/package.json +14 -35
  3. package/src/constants.ts +182 -0
  4. package/src/enumerations/index.ts +1 -0
  5. package/src/enumerations/pbkdf2-profile.ts +8 -0
  6. package/src/i18n/ecies-i18n-factory.ts +435 -0
  7. package/{dist/i18n/index.d.ts → src/i18n/index.ts} +0 -1
  8. package/{dist/index.d.ts → src/index.ts} +0 -1
  9. package/src/interfaces/authenticated-cipher.ts +9 -0
  10. package/src/interfaces/authenticated-decipher.ts +8 -0
  11. package/src/interfaces/checksum-config.ts +4 -0
  12. package/src/interfaces/checksum-consts.ts +13 -0
  13. package/src/interfaces/constants.ts +43 -0
  14. package/src/interfaces/ecies-consts.ts +99 -0
  15. package/src/interfaces/encryption-consts.ts +10 -0
  16. package/{dist/interfaces/index.d.ts → src/interfaces/index.ts} +0 -1
  17. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.ts +7 -0
  18. package/src/interfaces/keyring-consts.ts +5 -0
  19. package/src/interfaces/member-operational.ts +52 -0
  20. package/{dist/interfaces/member-with-mnemonic.d.ts → src/interfaces/member-with-mnemonic.ts} +3 -3
  21. package/{dist/interfaces/multi-encrypted-message.d.ts → src/interfaces/multi-encrypted-message.ts} +5 -5
  22. package/src/interfaces/multi-encrypted-parsed-header.ts +24 -0
  23. package/{dist/interfaces/pbkdf-profiles.d.ts → src/interfaces/pbkdf-profiles.ts} +2 -2
  24. package/src/interfaces/pbkdf2-result.ts +5 -0
  25. package/src/interfaces/signing-key-private-key-info.ts +12 -0
  26. package/{dist/interfaces/simple-keypair-buffer.d.ts → src/interfaces/simple-keypair-buffer.ts} +3 -3
  27. package/{dist/interfaces/simple-keypair.d.ts → src/interfaces/simple-keypair.ts} +3 -3
  28. package/src/interfaces/simple-public-key-only-buffer.ts +3 -0
  29. package/src/interfaces/simple-public-key-only.ts +3 -0
  30. package/src/interfaces/single-encrypted-parsed-header.ts +35 -0
  31. package/{dist/interfaces/wallet-seed.d.ts → src/interfaces/wallet-seed.ts} +3 -3
  32. package/src/interfaces/wrapped-key-consts.ts +6 -0
  33. package/src/member.ts +463 -0
  34. package/src/services/aes-gcm.ts +160 -0
  35. package/src/services/ecies/crypto-core.ts +213 -0
  36. package/src/services/ecies/file.ts +174 -0
  37. package/{dist/services/ecies/index.d.ts → src/services/ecies/index.ts} +0 -1
  38. package/src/services/ecies/multi-recipient.ts +583 -0
  39. package/src/services/ecies/service.ts +351 -0
  40. package/src/services/ecies/signature.ts +91 -0
  41. package/src/services/ecies/single-recipient.ts +676 -0
  42. package/src/services/ecies/utilities.ts +111 -0
  43. package/src/services/index.ts +3 -0
  44. package/src/services/pbkdf2.ts +307 -0
  45. package/{dist/types.d.ts → src/types.ts} +26 -9
  46. package/src/utils.ts +104 -0
  47. package/dist/constants.d.ts +0 -32
  48. package/dist/constants.d.ts.map +0 -1
  49. package/dist/constants.js +0 -137
  50. package/dist/constants.js.map +0 -1
  51. package/dist/enumerations/index.d.ts +0 -2
  52. package/dist/enumerations/index.d.ts.map +0 -1
  53. package/dist/enumerations/index.js +0 -18
  54. package/dist/enumerations/index.js.map +0 -1
  55. package/dist/enumerations/pbkdf2-profile.d.ts +0 -9
  56. package/dist/enumerations/pbkdf2-profile.d.ts.map +0 -1
  57. package/dist/enumerations/pbkdf2-profile.js +0 -13
  58. package/dist/enumerations/pbkdf2-profile.js.map +0 -1
  59. package/dist/i18n/ecies-i18n-factory.d.ts +0 -54
  60. package/dist/i18n/ecies-i18n-factory.d.ts.map +0 -1
  61. package/dist/i18n/ecies-i18n-factory.js +0 -333
  62. package/dist/i18n/ecies-i18n-factory.js.map +0 -1
  63. package/dist/i18n/index.d.ts.map +0 -1
  64. package/dist/i18n/index.js +0 -18
  65. package/dist/i18n/index.js.map +0 -1
  66. package/dist/index.d.ts.map +0 -1
  67. package/dist/index.js +0 -24
  68. package/dist/index.js.map +0 -1
  69. package/dist/interfaces/authenticated-cipher.d.ts +0 -10
  70. package/dist/interfaces/authenticated-cipher.d.ts.map +0 -1
  71. package/dist/interfaces/authenticated-cipher.js +0 -3
  72. package/dist/interfaces/authenticated-cipher.js.map +0 -1
  73. package/dist/interfaces/authenticated-decipher.d.ts +0 -9
  74. package/dist/interfaces/authenticated-decipher.d.ts.map +0 -1
  75. package/dist/interfaces/authenticated-decipher.js +0 -3
  76. package/dist/interfaces/authenticated-decipher.js.map +0 -1
  77. package/dist/interfaces/checksum-config.d.ts +0 -5
  78. package/dist/interfaces/checksum-config.d.ts.map +0 -1
  79. package/dist/interfaces/checksum-config.js +0 -3
  80. package/dist/interfaces/checksum-config.js.map +0 -1
  81. package/dist/interfaces/checksum-consts.d.ts +0 -11
  82. package/dist/interfaces/checksum-consts.d.ts.map +0 -1
  83. package/dist/interfaces/checksum-consts.js +0 -3
  84. package/dist/interfaces/checksum-consts.js.map +0 -1
  85. package/dist/interfaces/constants.d.ts +0 -43
  86. package/dist/interfaces/constants.d.ts.map +0 -1
  87. package/dist/interfaces/constants.js +0 -3
  88. package/dist/interfaces/constants.js.map +0 -1
  89. package/dist/interfaces/ecies-consts.d.ts +0 -88
  90. package/dist/interfaces/ecies-consts.d.ts.map +0 -1
  91. package/dist/interfaces/ecies-consts.js +0 -3
  92. package/dist/interfaces/ecies-consts.js.map +0 -1
  93. package/dist/interfaces/encryption-consts.d.ts +0 -11
  94. package/dist/interfaces/encryption-consts.d.ts.map +0 -1
  95. package/dist/interfaces/encryption-consts.js +0 -3
  96. package/dist/interfaces/encryption-consts.js.map +0 -1
  97. package/dist/interfaces/index.d.ts.map +0 -1
  98. package/dist/interfaces/index.js +0 -34
  99. package/dist/interfaces/index.js.map +0 -1
  100. package/dist/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts +0 -6
  101. package/dist/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts.map +0 -1
  102. package/dist/interfaces/keypair-buffer-with-un-encrypted-private-key.js +0 -3
  103. package/dist/interfaces/keypair-buffer-with-un-encrypted-private-key.js.map +0 -1
  104. package/dist/interfaces/keyring-consts.d.ts +0 -6
  105. package/dist/interfaces/keyring-consts.d.ts.map +0 -1
  106. package/dist/interfaces/keyring-consts.js +0 -3
  107. package/dist/interfaces/keyring-consts.js.map +0 -1
  108. package/dist/interfaces/member-operational.d.ts +0 -36
  109. package/dist/interfaces/member-operational.d.ts.map +0 -1
  110. package/dist/interfaces/member-operational.js +0 -3
  111. package/dist/interfaces/member-operational.js.map +0 -1
  112. package/dist/interfaces/member-with-mnemonic.d.ts.map +0 -1
  113. package/dist/interfaces/member-with-mnemonic.js +0 -3
  114. package/dist/interfaces/member-with-mnemonic.js.map +0 -1
  115. package/dist/interfaces/multi-encrypted-message.d.ts.map +0 -1
  116. package/dist/interfaces/multi-encrypted-message.js +0 -3
  117. package/dist/interfaces/multi-encrypted-message.js.map +0 -1
  118. package/dist/interfaces/multi-encrypted-parsed-header.d.ts +0 -24
  119. package/dist/interfaces/multi-encrypted-parsed-header.d.ts.map +0 -1
  120. package/dist/interfaces/multi-encrypted-parsed-header.js +0 -3
  121. package/dist/interfaces/multi-encrypted-parsed-header.js.map +0 -1
  122. package/dist/interfaces/pbkdf-profiles.d.ts.map +0 -1
  123. package/dist/interfaces/pbkdf-profiles.js +0 -3
  124. package/dist/interfaces/pbkdf-profiles.js.map +0 -1
  125. package/dist/interfaces/pbkdf2-result.d.ts +0 -6
  126. package/dist/interfaces/pbkdf2-result.d.ts.map +0 -1
  127. package/dist/interfaces/pbkdf2-result.js +0 -3
  128. package/dist/interfaces/pbkdf2-result.js.map +0 -1
  129. package/dist/interfaces/signing-key-private-key-info.d.ts +0 -11
  130. package/dist/interfaces/signing-key-private-key-info.d.ts.map +0 -1
  131. package/dist/interfaces/signing-key-private-key-info.js +0 -3
  132. package/dist/interfaces/signing-key-private-key-info.js.map +0 -1
  133. package/dist/interfaces/simple-keypair-buffer.d.ts.map +0 -1
  134. package/dist/interfaces/simple-keypair-buffer.js +0 -3
  135. package/dist/interfaces/simple-keypair-buffer.js.map +0 -1
  136. package/dist/interfaces/simple-keypair.d.ts.map +0 -1
  137. package/dist/interfaces/simple-keypair.js +0 -3
  138. package/dist/interfaces/simple-keypair.js.map +0 -1
  139. package/dist/interfaces/simple-public-key-only-buffer.d.ts +0 -4
  140. package/dist/interfaces/simple-public-key-only-buffer.d.ts.map +0 -1
  141. package/dist/interfaces/simple-public-key-only-buffer.js +0 -3
  142. package/dist/interfaces/simple-public-key-only-buffer.js.map +0 -1
  143. package/dist/interfaces/simple-public-key-only.d.ts +0 -4
  144. package/dist/interfaces/simple-public-key-only.d.ts.map +0 -1
  145. package/dist/interfaces/simple-public-key-only.js +0 -3
  146. package/dist/interfaces/simple-public-key-only.js.map +0 -1
  147. package/dist/interfaces/single-encrypted-parsed-header.d.ts +0 -35
  148. package/dist/interfaces/single-encrypted-parsed-header.d.ts.map +0 -1
  149. package/dist/interfaces/single-encrypted-parsed-header.js +0 -3
  150. package/dist/interfaces/single-encrypted-parsed-header.js.map +0 -1
  151. package/dist/interfaces/wallet-seed.d.ts.map +0 -1
  152. package/dist/interfaces/wallet-seed.js +0 -3
  153. package/dist/interfaces/wallet-seed.js.map +0 -1
  154. package/dist/interfaces/wrapped-key-consts.d.ts +0 -7
  155. package/dist/interfaces/wrapped-key-consts.d.ts.map +0 -1
  156. package/dist/interfaces/wrapped-key-consts.js +0 -3
  157. package/dist/interfaces/wrapped-key-consts.js.map +0 -1
  158. package/dist/member.d.ts +0 -74
  159. package/dist/member.d.ts.map +0 -1
  160. package/dist/member.js +0 -273
  161. package/dist/member.js.map +0 -1
  162. package/dist/services/aes-gcm.d.ts +0 -66
  163. package/dist/services/aes-gcm.d.ts.map +0 -1
  164. package/dist/services/aes-gcm.js +0 -115
  165. package/dist/services/aes-gcm.js.map +0 -1
  166. package/dist/services/ecies/crypto-core.d.ts +0 -83
  167. package/dist/services/ecies/crypto-core.d.ts.map +0 -1
  168. package/dist/services/ecies/crypto-core.js +0 -166
  169. package/dist/services/ecies/crypto-core.js.map +0 -1
  170. package/dist/services/ecies/file.d.ts +0 -30
  171. package/dist/services/ecies/file.d.ts.map +0 -1
  172. package/dist/services/ecies/file.js +0 -144
  173. package/dist/services/ecies/file.js.map +0 -1
  174. package/dist/services/ecies/index.d.ts.map +0 -1
  175. package/dist/services/ecies/index.js +0 -24
  176. package/dist/services/ecies/index.js.map +0 -1
  177. package/dist/services/ecies/multi-recipient.d.ts +0 -82
  178. package/dist/services/ecies/multi-recipient.d.ts.map +0 -1
  179. package/dist/services/ecies/multi-recipient.js +0 -360
  180. package/dist/services/ecies/multi-recipient.js.map +0 -1
  181. package/dist/services/ecies/service.d.ts +0 -70
  182. package/dist/services/ecies/service.d.ts.map +0 -1
  183. package/dist/services/ecies/service.js +0 -167
  184. package/dist/services/ecies/service.js.map +0 -1
  185. package/dist/services/ecies/signature.d.ts +0 -38
  186. package/dist/services/ecies/signature.d.ts.map +0 -1
  187. package/dist/services/ecies/signature.js +0 -69
  188. package/dist/services/ecies/signature.js.map +0 -1
  189. package/dist/services/ecies/single-recipient.d.ts +0 -85
  190. package/dist/services/ecies/single-recipient.d.ts.map +0 -1
  191. package/dist/services/ecies/single-recipient.js +0 -399
  192. package/dist/services/ecies/single-recipient.js.map +0 -1
  193. package/dist/services/ecies/utilities.d.ts +0 -22
  194. package/dist/services/ecies/utilities.d.ts.map +0 -1
  195. package/dist/services/ecies/utilities.js +0 -75
  196. package/dist/services/ecies/utilities.js.map +0 -1
  197. package/dist/services/index.d.ts +0 -4
  198. package/dist/services/index.d.ts.map +0 -1
  199. package/dist/services/index.js +0 -20
  200. package/dist/services/index.js.map +0 -1
  201. package/dist/services/pbkdf2.d.ts +0 -106
  202. package/dist/services/pbkdf2.d.ts.map +0 -1
  203. package/dist/services/pbkdf2.js +0 -195
  204. package/dist/services/pbkdf2.js.map +0 -1
  205. package/dist/types.d.ts.map +0 -1
  206. package/dist/types.js +0 -3
  207. package/dist/types.js.map +0 -1
  208. package/dist/utils.d.ts +0 -11
  209. package/dist/utils.d.ts.map +0 -1
  210. package/dist/utils.js +0 -82
  211. package/dist/utils.js.map +0 -1
@@ -1,106 +0,0 @@
1
- import { PluginI18nEngine, CoreLanguageCode } from '@digitaldefiance/i18n-lib';
2
- import { IPbkdf2Config, IPBkdf2Consts, Pbkdf2ErrorType } from '@digitaldefiance/ecies-lib';
3
- import { IConstants } from '../interfaces/constants';
4
- import { Pbkdf2ProfileEnum } from '../enumerations/pbkdf2-profile';
5
- import { IPbkdf2Result } from '../interfaces/pbkdf2-result';
6
- import { IECIESConsts } from '../interfaces/ecies-consts';
7
- /**
8
- * Custom PBKDF2 error class that works with the plugin i18n system
9
- */
10
- export declare class NodePbkdf2Error extends Error {
11
- readonly type: Pbkdf2ErrorType;
12
- constructor(message: string, type: Pbkdf2ErrorType);
13
- }
14
- /**
15
- * Service for handling PBKDF2 (Password-Based Key Derivation Function 2) operations.
16
- * This service provides functionality for:
17
- * - Generating secure key derivation configurations
18
- * - Deriving cryptographic keys from passwords
19
- * - Managing salt and iteration parameters
20
- * - Both synchronous and asynchronous key derivation
21
- */
22
- export declare class Pbkdf2Service<TLanguage extends CoreLanguageCode = CoreLanguageCode> {
23
- protected readonly engine: PluginI18nEngine<TLanguage>;
24
- protected readonly profiles: Record<string, IPbkdf2Config>;
25
- protected readonly eciesConsts: IECIESConsts;
26
- protected readonly pbkdf2Consts: IPBkdf2Consts;
27
- constructor(engine: PluginI18nEngine<TLanguage>, profiles?: Record<string, IPbkdf2Config>, eciesParams?: IECIESConsts, pbkdf2Params?: IPBkdf2Consts);
28
- /**
29
- * Register a new PBKDF2 profile
30
- * @param profileName The name of the profile
31
- * @param config The configuration for the profile
32
- */
33
- registerProfile(profileName: string, config: IPbkdf2Config): void;
34
- /**
35
- * Get all registered profile names
36
- * @returns Array of profile names
37
- */
38
- getRegisteredProfiles(): string[];
39
- /**
40
- * Check if a profile is registered
41
- * @param profileName The name of the profile to check
42
- * @returns True if the profile exists
43
- */
44
- hasProfile(profileName: string): boolean;
45
- /**
46
- * Create a Pbkdf2Service instance from IConstants (for backward compatibility)
47
- * @param constants The constants object
48
- * @returns A new Pbkdf2Service instance
49
- */
50
- static fromConstants(constants: IConstants): Pbkdf2Service;
51
- /**
52
- * Get a predefined configuration profile for common use cases
53
- * @param profile The name of the profile to use
54
- * @returns Configuration object for the specified profile
55
- */
56
- getProfileConfig(profile: string): IPbkdf2Config;
57
- /**
58
- * Generate an options object for pbkdf2
59
- * @param iterations Optional number of iterations (defaults to Pbkdf2IterationsPerSecond)
60
- * @param saltBytes Optional salt size in bytes (defaults to PBKDF2.SALT_BYTES)
61
- * @param hashBytes Optional hash size in bytes (defaults to ECIES.SYMMETRIC.KEY_SIZE)
62
- * @param algorithm Optional hash algorithm (defaults to PBKDF2.ALGORITHM)
63
- * @returns Configuration object for PBKDF2
64
- */
65
- getConfig(iterations?: number, saltBytes?: number, hashBytes?: number, algorithm?: string): IPbkdf2Config;
66
- /**
67
- * Given a password, use pbkdf2 to generate an appropriately sized key for AES encryption
68
- * @param password The password to derive a key from
69
- * @param salt Optional salt (will be randomly generated if not provided)
70
- * @param iterations Optional number of iterations
71
- * @param saltBytes Optional salt size in bytes
72
- * @param keySize Optional key size in bytes
73
- * @param algorithm Optional hash algorithm
74
- * @returns Object containing the derived key, salt, and iteration count
75
- */
76
- deriveKeyFromPassword(password: Buffer, salt?: Buffer, iterations?: number, saltBytes?: number, keySize?: number, algorithm?: string): IPbkdf2Result;
77
- /**
78
- * Async version of deriveKeyFromPassword that uses libuv threadpool via crypto.pbkdf2
79
- * to avoid blocking the event loop during password verification.
80
- * @param password The password to derive a key from
81
- * @param salt Optional salt (will be randomly generated if not provided)
82
- * @param iterations Optional number of iterations
83
- * @param saltBytes Optional salt size in bytes
84
- * @param keySize Optional key size in bytes
85
- * @param algorithm Optional hash algorithm
86
- * @returns Promise resolving to object containing the derived key, salt, and iteration count
87
- */
88
- deriveKeyFromPasswordAsync(password: Buffer, salt?: Buffer, iterations?: number, saltBytes?: number, keySize?: number, algorithm?: string): Promise<IPbkdf2Result>;
89
- /**
90
- * Derive a key using a predefined configuration profile
91
- * @param password The password to derive a key from
92
- * @param profile The configuration profile to use
93
- * @param salt Optional salt (will be randomly generated if not provided)
94
- * @returns Object containing the derived key, salt, and iteration count
95
- */
96
- deriveKeyFromPasswordWithProfile(password: Buffer, profile: Pbkdf2ProfileEnum, salt?: Buffer): IPbkdf2Result;
97
- /**
98
- * Async version of deriveKeyFromPasswordWithProfile
99
- * @param password The password to derive a key from
100
- * @param profile The configuration profile to use
101
- * @param salt Optional salt (will be randomly generated if not provided)
102
- * @returns Promise resolving to object containing the derived key, salt, and iteration count
103
- */
104
- deriveKeyFromPasswordWithProfileAsync(password: Buffer, profile: Pbkdf2ProfileEnum, salt?: Buffer): Promise<IPbkdf2Result>;
105
- }
106
- //# sourceMappingURL=pbkdf2.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pbkdf2.d.ts","sourceRoot":"","sources":["../../src/services/pbkdf2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE/E,OAAO,EACL,aAAa,EACb,aAAa,EACb,eAAe,EAChB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG1D;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;aACK,IAAI,EAAE,eAAe;gBAAtD,OAAO,EAAE,MAAM,EAAkB,IAAI,EAAE,eAAe;CAInE;AAED;;;;;;;GAOG;AACH,qBAAa,aAAa,CAAC,SAAS,SAAS,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AAM,EAChB,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,CAAC;IAuCzB;;;;;;OAMG;IACI,gCAAgC,CACrC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,iBAAiB,EAC1B,IAAI,CAAC,EAAE,MAAM,GACZ,aAAa;IAYhB;;;;;;OAMG;IACU,qCAAqC,CAChD,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,iBAAiB,EAC1B,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,aAAa,CAAC;CAW1B"}
@@ -1,195 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Pbkdf2Service = exports.NodePbkdf2Error = void 0;
4
- const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
5
- const crypto_1 = require("crypto");
6
- const util_1 = require("util");
7
- const ecies_i18n_factory_1 = require("../i18n/ecies-i18n-factory");
8
- const constants_1 = require("../constants");
9
- /**
10
- * Custom PBKDF2 error class that works with the plugin i18n system
11
- */
12
- class NodePbkdf2Error extends Error {
13
- type;
14
- constructor(message, type) {
15
- super(message);
16
- this.type = type;
17
- this.name = 'NodePbkdf2Error';
18
- }
19
- }
20
- exports.NodePbkdf2Error = NodePbkdf2Error;
21
- /**
22
- * Service for handling PBKDF2 (Password-Based Key Derivation Function 2) operations.
23
- * This service provides functionality for:
24
- * - Generating secure key derivation configurations
25
- * - Deriving cryptographic keys from passwords
26
- * - Managing salt and iteration parameters
27
- * - Both synchronous and asynchronous key derivation
28
- */
29
- class Pbkdf2Service {
30
- engine;
31
- profiles;
32
- eciesConsts;
33
- pbkdf2Consts;
34
- constructor(engine, profiles, eciesParams = constants_1.Constants.ECIES, pbkdf2Params = constants_1.Constants.PBKDF2) {
35
- this.engine = engine;
36
- this.profiles = profiles ? { ...profiles } : {};
37
- const runtimeDefaults = (0, constants_1.getNodeRuntimeConfiguration)();
38
- this.eciesConsts = eciesParams ?? runtimeDefaults.ECIES;
39
- this.pbkdf2Consts =
40
- pbkdf2Params ?? runtimeDefaults.PBKDF2;
41
- }
42
- /**
43
- * Register a new PBKDF2 profile
44
- * @param profileName The name of the profile
45
- * @param config The configuration for the profile
46
- */
47
- registerProfile(profileName, config) {
48
- this.profiles[profileName] = { ...config };
49
- }
50
- /**
51
- * Get all registered profile names
52
- * @returns Array of profile names
53
- */
54
- getRegisteredProfiles() {
55
- return Object.keys(this.profiles);
56
- }
57
- /**
58
- * Check if a profile is registered
59
- * @param profileName The name of the profile to check
60
- * @returns True if the profile exists
61
- */
62
- hasProfile(profileName) {
63
- return profileName in this.profiles;
64
- }
65
- /**
66
- * Create a Pbkdf2Service instance from IConstants (for backward compatibility)
67
- * @param constants The constants object
68
- * @returns A new Pbkdf2Service instance
69
- */
70
- static fromConstants(constants) {
71
- const engine = (0, ecies_i18n_factory_1.getEciesPluginI18nEngine)();
72
- const runtimeDefaults = (0, constants_1.getNodeRuntimeConfiguration)();
73
- return new Pbkdf2Service(engine, constants.PBKDF2_PROFILES, runtimeDefaults.ECIES, constants.PBKDF2);
74
- }
75
- /**
76
- * Get a predefined configuration profile for common use cases
77
- * @param profile The name of the profile to use
78
- * @returns Configuration object for the specified profile
79
- */
80
- getProfileConfig(profile) {
81
- const profileConfig = this.profiles[profile];
82
- if (!profileConfig) {
83
- throw new NodePbkdf2Error((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Pbkdf2_InvalidSaltLength), ecies_lib_1.Pbkdf2ErrorType.InvalidProfile);
84
- }
85
- return {
86
- hashBytes: profileConfig.hashBytes,
87
- saltBytes: profileConfig.saltBytes,
88
- iterations: profileConfig.iterations,
89
- algorithm: profileConfig.algorithm,
90
- };
91
- }
92
- /**
93
- * Generate an options object for pbkdf2
94
- * @param iterations Optional number of iterations (defaults to Pbkdf2IterationsPerSecond)
95
- * @param saltBytes Optional salt size in bytes (defaults to PBKDF2.SALT_BYTES)
96
- * @param hashBytes Optional hash size in bytes (defaults to ECIES.SYMMETRIC.KEY_SIZE)
97
- * @param algorithm Optional hash algorithm (defaults to PBKDF2.ALGORITHM)
98
- * @returns Configuration object for PBKDF2
99
- */
100
- getConfig(iterations, saltBytes, hashBytes, algorithm) {
101
- // larger numbers mean better security, less
102
- return {
103
- // size of the generated hash
104
- hashBytes: hashBytes ?? this.eciesConsts.SYMMETRIC.KEY_SIZE,
105
- // larger salt means hashed passwords are more resistant to rainbow table, but
106
- // you get diminishing returns pretty fast
107
- saltBytes: saltBytes ?? this.pbkdf2Consts.SALT_BYTES,
108
- // more iterations means an attacker has to take longer to brute force an
109
- // individual password, so larger is better. however, larger also means longer
110
- // to hash the password. tune so that hashing the password takes about a
111
- // second
112
- iterations: iterations ?? this.pbkdf2Consts.ITERATIONS_PER_SECOND,
113
- // hash algorithm
114
- algorithm: algorithm ?? this.pbkdf2Consts.ALGORITHM,
115
- };
116
- }
117
- /**
118
- * Given a password, use pbkdf2 to generate an appropriately sized key for AES encryption
119
- * @param password The password to derive a key from
120
- * @param salt Optional salt (will be randomly generated if not provided)
121
- * @param iterations Optional number of iterations
122
- * @param saltBytes Optional salt size in bytes
123
- * @param keySize Optional key size in bytes
124
- * @param algorithm Optional hash algorithm
125
- * @returns Object containing the derived key, salt, and iteration count
126
- */
127
- deriveKeyFromPassword(password, salt, iterations, saltBytes, keySize, algorithm) {
128
- const config = this.getConfig(iterations, saltBytes, keySize, algorithm);
129
- const saltBytes_ = salt ?? (0, crypto_1.randomBytes)(config.saltBytes);
130
- if (saltBytes_.length !== config.saltBytes) {
131
- throw new NodePbkdf2Error((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Pbkdf2_InvalidSaltLength), ecies_lib_1.Pbkdf2ErrorType.InvalidSaltLength);
132
- }
133
- const hashBytes = (0, crypto_1.pbkdf2Sync)(password, saltBytes_, config.iterations, config.hashBytes, config.algorithm);
134
- if (hashBytes.length !== config.hashBytes) {
135
- throw new NodePbkdf2Error((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Pbkdf2_InvalidHashLength), ecies_lib_1.Pbkdf2ErrorType.InvalidHashLength);
136
- }
137
- return {
138
- salt: saltBytes_,
139
- hash: hashBytes,
140
- iterations: config.iterations,
141
- };
142
- }
143
- /**
144
- * Async version of deriveKeyFromPassword that uses libuv threadpool via crypto.pbkdf2
145
- * to avoid blocking the event loop during password verification.
146
- * @param password The password to derive a key from
147
- * @param salt Optional salt (will be randomly generated if not provided)
148
- * @param iterations Optional number of iterations
149
- * @param saltBytes Optional salt size in bytes
150
- * @param keySize Optional key size in bytes
151
- * @param algorithm Optional hash algorithm
152
- * @returns Promise resolving to object containing the derived key, salt, and iteration count
153
- */
154
- async deriveKeyFromPasswordAsync(password, salt, iterations, saltBytes, keySize, algorithm) {
155
- const config = this.getConfig(iterations, saltBytes, keySize, algorithm);
156
- const saltBytes_ = salt ?? (0, crypto_1.randomBytes)(config.saltBytes);
157
- if (saltBytes_.length !== config.saltBytes) {
158
- throw new NodePbkdf2Error((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Pbkdf2_InvalidSaltLength), ecies_lib_1.Pbkdf2ErrorType.InvalidSaltLength);
159
- }
160
- const pbkdf2 = (0, util_1.promisify)(crypto_1.pbkdf2);
161
- const hashBytes = (await pbkdf2(password, saltBytes_, config.iterations, config.hashBytes, config.algorithm));
162
- if (hashBytes.length !== config.hashBytes) {
163
- throw new NodePbkdf2Error((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Pbkdf2_InvalidHashLength), ecies_lib_1.Pbkdf2ErrorType.InvalidHashLength);
164
- }
165
- return {
166
- salt: saltBytes_,
167
- hash: hashBytes,
168
- iterations: config.iterations,
169
- };
170
- }
171
- /**
172
- * Derive a key using a predefined configuration profile
173
- * @param password The password to derive a key from
174
- * @param profile The configuration profile to use
175
- * @param salt Optional salt (will be randomly generated if not provided)
176
- * @returns Object containing the derived key, salt, and iteration count
177
- */
178
- deriveKeyFromPasswordWithProfile(password, profile, salt) {
179
- const config = this.getProfileConfig(profile);
180
- return this.deriveKeyFromPassword(password, salt, config.iterations, config.saltBytes, config.hashBytes, config.algorithm);
181
- }
182
- /**
183
- * Async version of deriveKeyFromPasswordWithProfile
184
- * @param password The password to derive a key from
185
- * @param profile The configuration profile to use
186
- * @param salt Optional salt (will be randomly generated if not provided)
187
- * @returns Promise resolving to object containing the derived key, salt, and iteration count
188
- */
189
- async deriveKeyFromPasswordWithProfileAsync(password, profile, salt) {
190
- const config = this.getProfileConfig(profile);
191
- return this.deriveKeyFromPasswordAsync(password, salt, config.iterations, config.saltBytes, config.hashBytes, config.algorithm);
192
- }
193
- }
194
- exports.Pbkdf2Service = Pbkdf2Service;
195
- //# sourceMappingURL=pbkdf2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pbkdf2.js","sourceRoot":"","sources":["../../src/services/pbkdf2.ts"],"names":[],"mappings":";;;AAEA,0DAIoC;AACpC,mCAAwE;AACxE,+BAAiC;AAGjC,mEAAyI;AAGzI,4CAAsE;AAEtE;;GAEG;AACH,MAAa,eAAgB,SAAQ,KAAK;IACK;IAA7C,YAAY,OAAe,EAAkB,IAAqB;QAChE,KAAK,CAAC,OAAO,CAAC,CAAC;QAD4B,SAAI,GAAJ,IAAI,CAAiB;QAEhE,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC;AAED;;;;;;;GAOG;AACH,MAAa,aAAa;IACL,MAAM,CAA8B;IACpC,QAAQ,CAAgC;IACxC,WAAW,CAAe;IAC1B,YAAY,CAAgB;IAE/C,YACE,MAAmC,EACnC,QAAwC,EACxC,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ingURL=types.js.map
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/dist/utils.d.ts DELETED
@@ -1,11 +0,0 @@
1
- /**
2
- * Encodes the length of the data in the buffer
3
- * @param buffer The buffer to encode
4
- * @returns The encoded buffer
5
- */
6
- export declare function lengthEncodeData(buffer: Buffer): Buffer;
7
- export declare function decodeLengthEncodedData(buffer: Buffer): {
8
- data: Buffer;
9
- totalLength: number;
10
- };
11
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAuBA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAuBvD;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB,CA+CA"}
package/dist/utils.js DELETED
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lengthEncodeData = lengthEncodeData;
4
- exports.decodeLengthEncodedData = decodeLengthEncodedData;
5
- const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
6
- const ecies_i18n_factory_1 = require("./i18n/ecies-i18n-factory");
7
- /**
8
- * Custom error class for length encoding errors
9
- */
10
- class LengthEncodingError extends Error {
11
- constructor(message) {
12
- super(message);
13
- this.name = 'LengthEncodingError';
14
- }
15
- }
16
- /**
17
- * Encodes the length of the data in the buffer
18
- * @param buffer The buffer to encode
19
- * @returns The encoded buffer
20
- */
21
- function lengthEncodeData(buffer) {
22
- const lengthType = (0, ecies_lib_1.getLengthEncodingTypeForLength)(buffer.length);
23
- const lengthTypeSize = (0, ecies_lib_1.getLengthForLengthType)(lengthType);
24
- const result = Buffer.alloc(1 + lengthTypeSize + buffer.length);
25
- result.writeUInt8(lengthType, 0);
26
- switch (lengthType) {
27
- case ecies_lib_1.LengthEncodingType.UInt8:
28
- result.writeUInt8(buffer.length, 1);
29
- break;
30
- case ecies_lib_1.LengthEncodingType.UInt16:
31
- result.writeUInt16BE(buffer.length, 1);
32
- break;
33
- case ecies_lib_1.LengthEncodingType.UInt32:
34
- result.writeUInt32BE(buffer.length, 1);
35
- break;
36
- case ecies_lib_1.LengthEncodingType.UInt64:
37
- result.writeBigUInt64BE(BigInt(buffer.length), 1);
38
- break;
39
- }
40
- buffer.copy(result, 1 + lengthTypeSize);
41
- return result;
42
- }
43
- function decodeLengthEncodedData(buffer) {
44
- const pluginEngine = (0, ecies_i18n_factory_1.getEciesPluginI18nEngine)();
45
- if (buffer.length < 1) {
46
- throw new RangeError(pluginEngine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_BufferIsTooShort));
47
- }
48
- const lengthType = (0, ecies_lib_1.getLengthEncodingTypeFromValue)(buffer.readUint8(0));
49
- const lengthTypeSize = (0, ecies_lib_1.getLengthForLengthType)(lengthType);
50
- if (buffer.length < 1 + lengthTypeSize) {
51
- throw new RangeError(pluginEngine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_BufferIsTooShortToReadFullLengthValue));
52
- }
53
- let length;
54
- switch (lengthType) {
55
- case ecies_lib_1.LengthEncodingType.UInt8:
56
- length = buffer.readUint8(1);
57
- break;
58
- case ecies_lib_1.LengthEncodingType.UInt16:
59
- length = buffer.readUint16BE(1);
60
- break;
61
- case ecies_lib_1.LengthEncodingType.UInt32:
62
- length = buffer.readUint32BE(1);
63
- break;
64
- case ecies_lib_1.LengthEncodingType.UInt64:
65
- length = buffer.readBigUInt64BE(1);
66
- if (Number(length) > Number.MAX_SAFE_INTEGER) {
67
- throw new RangeError(pluginEngine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_LengthExceedsMaximumSafeInteger));
68
- }
69
- break;
70
- default:
71
- throw new LengthEncodingError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_LengthError_LengthIsInvalidType));
72
- }
73
- const totalLength = 1 + lengthTypeSize + Number(length);
74
- if (totalLength > buffer.length) {
75
- throw new RangeError(pluginEngine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_BufferIsTooShortForDeclaredDataLength));
76
- }
77
- return {
78
- data: buffer.subarray(1 + lengthTypeSize, totalLength),
79
- totalLength,
80
- };
81
- }
82
- //# sourceMappingURL=utils.js.map
package/dist/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AA4BA,4CAuBC;AAED,0DAkDC;AAvGD,0DAKoC;AACpC,kEAKmC;AAEnC;;GAEG;AACH,MAAM,mBAAoB,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,MAAc;IAC7C,MAAM,UAAU,GAAuB,IAAA,0CAA8B,EACnE,MAAM,CAAC,MAAM,CACd,CAAC;IACF,MAAM,cAAc,GAAW,IAAA,kCAAsB,EAAC,UAAU,CAAC,CAAC;IAClE,MAAM,MAAM,GAAW,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IACxE,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IACjC,QAAQ,UAAU,EAAE,CAAC;QACnB,KAAK,8BAAkB,CAAC,KAAK;YAC3B,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAA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