@digitaldefiance/node-ecies-lib 1.1.22 → 1.1.23

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 (212) hide show
  1. package/README.md +4 -0
  2. package/package.json +6 -5
  3. package/src/constants.d.ts +32 -0
  4. package/src/constants.d.ts.map +1 -0
  5. package/src/constants.js +137 -0
  6. package/src/constants.js.map +1 -0
  7. package/src/enumerations/index.d.ts +2 -0
  8. package/src/enumerations/index.d.ts.map +1 -0
  9. package/src/enumerations/index.js +5 -0
  10. package/src/enumerations/index.js.map +1 -0
  11. package/src/enumerations/pbkdf2-profile.d.ts +9 -0
  12. package/src/enumerations/pbkdf2-profile.d.ts.map +1 -0
  13. package/src/enumerations/pbkdf2-profile.js +13 -0
  14. package/src/enumerations/pbkdf2-profile.js.map +1 -0
  15. package/src/i18n/ecies-i18n-factory.d.ts +54 -0
  16. package/src/i18n/ecies-i18n-factory.d.ts.map +1 -0
  17. package/src/i18n/ecies-i18n-factory.js +333 -0
  18. package/src/i18n/ecies-i18n-factory.js.map +1 -0
  19. package/src/i18n/{index.ts → index.d.ts} +1 -0
  20. package/src/i18n/index.d.ts.map +1 -0
  21. package/src/i18n/index.js +5 -0
  22. package/src/i18n/index.js.map +1 -0
  23. package/src/{index.ts → index.d.ts} +1 -0
  24. package/src/index.d.ts.map +1 -0
  25. package/src/index.js +11 -0
  26. package/src/index.js.map +1 -0
  27. package/src/interfaces/authenticated-cipher.d.ts +10 -0
  28. package/src/interfaces/authenticated-cipher.d.ts.map +1 -0
  29. package/src/interfaces/authenticated-cipher.js +3 -0
  30. package/src/interfaces/authenticated-cipher.js.map +1 -0
  31. package/src/interfaces/authenticated-decipher.d.ts +9 -0
  32. package/src/interfaces/authenticated-decipher.d.ts.map +1 -0
  33. package/src/interfaces/authenticated-decipher.js +3 -0
  34. package/src/interfaces/authenticated-decipher.js.map +1 -0
  35. package/src/interfaces/checksum-config.d.ts +5 -0
  36. package/src/interfaces/checksum-config.d.ts.map +1 -0
  37. package/src/interfaces/checksum-config.js +3 -0
  38. package/src/interfaces/checksum-config.js.map +1 -0
  39. package/src/interfaces/checksum-consts.d.ts +11 -0
  40. package/src/interfaces/checksum-consts.d.ts.map +1 -0
  41. package/src/interfaces/checksum-consts.js +3 -0
  42. package/src/interfaces/checksum-consts.js.map +1 -0
  43. package/src/interfaces/constants.d.ts +43 -0
  44. package/src/interfaces/constants.d.ts.map +1 -0
  45. package/src/interfaces/constants.js +3 -0
  46. package/src/interfaces/constants.js.map +1 -0
  47. package/src/interfaces/ecies-consts.d.ts +88 -0
  48. package/src/interfaces/ecies-consts.d.ts.map +1 -0
  49. package/src/interfaces/ecies-consts.js +3 -0
  50. package/src/interfaces/ecies-consts.js.map +1 -0
  51. package/src/interfaces/encryption-consts.d.ts +11 -0
  52. package/src/interfaces/encryption-consts.d.ts.map +1 -0
  53. package/src/interfaces/encryption-consts.js +3 -0
  54. package/src/interfaces/encryption-consts.js.map +1 -0
  55. package/src/interfaces/{index.ts → index.d.ts} +1 -0
  56. package/src/interfaces/index.d.ts.map +1 -0
  57. package/src/interfaces/index.js +21 -0
  58. package/src/interfaces/index.js.map +1 -0
  59. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts +6 -0
  60. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts.map +1 -0
  61. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.js +3 -0
  62. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.js.map +1 -0
  63. package/src/interfaces/keyring-consts.d.ts +6 -0
  64. package/src/interfaces/keyring-consts.d.ts.map +1 -0
  65. package/src/interfaces/keyring-consts.js +3 -0
  66. package/src/interfaces/keyring-consts.js.map +1 -0
  67. package/src/interfaces/member-operational.d.ts +36 -0
  68. package/src/interfaces/member-operational.d.ts.map +1 -0
  69. package/src/interfaces/member-operational.js +3 -0
  70. package/src/interfaces/member-operational.js.map +1 -0
  71. package/src/interfaces/{member-with-mnemonic.ts → member-with-mnemonic.d.ts} +3 -3
  72. package/src/interfaces/member-with-mnemonic.d.ts.map +1 -0
  73. package/src/interfaces/member-with-mnemonic.js +3 -0
  74. package/src/interfaces/member-with-mnemonic.js.map +1 -0
  75. package/src/interfaces/{multi-encrypted-message.ts → multi-encrypted-message.d.ts} +5 -5
  76. package/src/interfaces/multi-encrypted-message.d.ts.map +1 -0
  77. package/src/interfaces/multi-encrypted-message.js +3 -0
  78. package/src/interfaces/multi-encrypted-message.js.map +1 -0
  79. package/src/interfaces/multi-encrypted-parsed-header.d.ts +24 -0
  80. package/src/interfaces/multi-encrypted-parsed-header.d.ts.map +1 -0
  81. package/src/interfaces/multi-encrypted-parsed-header.js +3 -0
  82. package/src/interfaces/multi-encrypted-parsed-header.js.map +1 -0
  83. package/src/interfaces/{pbkdf-profiles.ts → pbkdf-profiles.d.ts} +2 -2
  84. package/src/interfaces/pbkdf-profiles.d.ts.map +1 -0
  85. package/src/interfaces/pbkdf-profiles.js +3 -0
  86. package/src/interfaces/pbkdf-profiles.js.map +1 -0
  87. package/src/interfaces/pbkdf2-result.d.ts +6 -0
  88. package/src/interfaces/pbkdf2-result.d.ts.map +1 -0
  89. package/src/interfaces/pbkdf2-result.js +3 -0
  90. package/src/interfaces/pbkdf2-result.js.map +1 -0
  91. package/src/interfaces/signing-key-private-key-info.d.ts +11 -0
  92. package/src/interfaces/signing-key-private-key-info.d.ts.map +1 -0
  93. package/src/interfaces/signing-key-private-key-info.js +3 -0
  94. package/src/interfaces/signing-key-private-key-info.js.map +1 -0
  95. package/src/interfaces/{simple-keypair-buffer.ts → simple-keypair-buffer.d.ts} +3 -3
  96. package/src/interfaces/simple-keypair-buffer.d.ts.map +1 -0
  97. package/src/interfaces/simple-keypair-buffer.js +3 -0
  98. package/src/interfaces/simple-keypair-buffer.js.map +1 -0
  99. package/src/interfaces/{simple-keypair.ts → simple-keypair.d.ts} +3 -3
  100. package/src/interfaces/simple-keypair.d.ts.map +1 -0
  101. package/src/interfaces/simple-keypair.js +3 -0
  102. package/src/interfaces/simple-keypair.js.map +1 -0
  103. package/src/interfaces/simple-public-key-only-buffer.d.ts +4 -0
  104. package/src/interfaces/simple-public-key-only-buffer.d.ts.map +1 -0
  105. package/src/interfaces/simple-public-key-only-buffer.js +3 -0
  106. package/src/interfaces/simple-public-key-only-buffer.js.map +1 -0
  107. package/src/interfaces/simple-public-key-only.d.ts +4 -0
  108. package/src/interfaces/simple-public-key-only.d.ts.map +1 -0
  109. package/src/interfaces/simple-public-key-only.js +3 -0
  110. package/src/interfaces/simple-public-key-only.js.map +1 -0
  111. package/src/interfaces/single-encrypted-parsed-header.d.ts +35 -0
  112. package/src/interfaces/single-encrypted-parsed-header.d.ts.map +1 -0
  113. package/src/interfaces/single-encrypted-parsed-header.js +3 -0
  114. package/src/interfaces/single-encrypted-parsed-header.js.map +1 -0
  115. package/src/interfaces/{wallet-seed.ts → wallet-seed.d.ts} +3 -3
  116. package/src/interfaces/wallet-seed.d.ts.map +1 -0
  117. package/src/interfaces/wallet-seed.js +3 -0
  118. package/src/interfaces/wallet-seed.js.map +1 -0
  119. package/src/interfaces/wrapped-key-consts.d.ts +7 -0
  120. package/src/interfaces/wrapped-key-consts.d.ts.map +1 -0
  121. package/src/interfaces/wrapped-key-consts.js +3 -0
  122. package/src/interfaces/wrapped-key-consts.js.map +1 -0
  123. package/src/member.d.ts +74 -0
  124. package/src/member.d.ts.map +1 -0
  125. package/src/member.js +273 -0
  126. package/src/member.js.map +1 -0
  127. package/src/services/aes-gcm.d.ts +66 -0
  128. package/src/services/aes-gcm.d.ts.map +1 -0
  129. package/src/services/aes-gcm.js +115 -0
  130. package/src/services/aes-gcm.js.map +1 -0
  131. package/src/services/ecies/crypto-core.d.ts +83 -0
  132. package/src/services/ecies/crypto-core.d.ts.map +1 -0
  133. package/src/services/ecies/crypto-core.js +166 -0
  134. package/src/services/ecies/crypto-core.js.map +1 -0
  135. package/src/services/ecies/file.d.ts +30 -0
  136. package/src/services/ecies/file.d.ts.map +1 -0
  137. package/src/services/ecies/file.js +112 -0
  138. package/src/services/ecies/file.js.map +1 -0
  139. package/src/services/ecies/{index.ts → index.d.ts} +1 -0
  140. package/src/services/ecies/index.d.ts.map +1 -0
  141. package/src/services/ecies/index.js +11 -0
  142. package/src/services/ecies/index.js.map +1 -0
  143. package/src/services/ecies/multi-recipient.d.ts +82 -0
  144. package/src/services/ecies/multi-recipient.d.ts.map +1 -0
  145. package/src/services/ecies/multi-recipient.js +360 -0
  146. package/src/services/ecies/multi-recipient.js.map +1 -0
  147. package/src/services/ecies/service.d.ts +70 -0
  148. package/src/services/ecies/service.d.ts.map +1 -0
  149. package/src/services/ecies/service.js +167 -0
  150. package/src/services/ecies/service.js.map +1 -0
  151. package/src/services/ecies/signature.d.ts +38 -0
  152. package/src/services/ecies/signature.d.ts.map +1 -0
  153. package/src/services/ecies/signature.js +69 -0
  154. package/src/services/ecies/signature.js.map +1 -0
  155. package/src/services/ecies/single-recipient.d.ts +85 -0
  156. package/src/services/ecies/single-recipient.d.ts.map +1 -0
  157. package/src/services/ecies/single-recipient.js +399 -0
  158. package/src/services/ecies/single-recipient.js.map +1 -0
  159. package/src/services/ecies/utilities.d.ts +22 -0
  160. package/src/services/ecies/utilities.d.ts.map +1 -0
  161. package/src/services/ecies/utilities.js +75 -0
  162. package/src/services/ecies/utilities.js.map +1 -0
  163. package/src/services/index.d.ts +4 -0
  164. package/src/services/index.d.ts.map +1 -0
  165. package/src/services/index.js +7 -0
  166. package/src/services/index.js.map +1 -0
  167. package/src/services/pbkdf2.d.ts +106 -0
  168. package/src/services/pbkdf2.d.ts.map +1 -0
  169. package/src/services/pbkdf2.js +195 -0
  170. package/src/services/pbkdf2.js.map +1 -0
  171. package/src/{types.ts → types.d.ts} +9 -26
  172. package/src/types.d.ts.map +1 -0
  173. package/src/types.js +3 -0
  174. package/src/types.js.map +1 -0
  175. package/src/utils.d.ts +11 -0
  176. package/src/utils.d.ts.map +1 -0
  177. package/src/utils.js +82 -0
  178. package/src/utils.js.map +1 -0
  179. package/LICENSE +0 -21
  180. package/src/constants.ts +0 -182
  181. package/src/enumerations/index.ts +0 -1
  182. package/src/enumerations/pbkdf2-profile.ts +0 -8
  183. package/src/i18n/ecies-i18n-factory.ts +0 -435
  184. package/src/interfaces/authenticated-cipher.ts +0 -9
  185. package/src/interfaces/authenticated-decipher.ts +0 -8
  186. package/src/interfaces/checksum-config.ts +0 -4
  187. package/src/interfaces/checksum-consts.ts +0 -13
  188. package/src/interfaces/constants.ts +0 -43
  189. package/src/interfaces/ecies-consts.ts +0 -99
  190. package/src/interfaces/encryption-consts.ts +0 -10
  191. package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.ts +0 -7
  192. package/src/interfaces/keyring-consts.ts +0 -5
  193. package/src/interfaces/member-operational.ts +0 -52
  194. package/src/interfaces/multi-encrypted-parsed-header.ts +0 -24
  195. package/src/interfaces/pbkdf2-result.ts +0 -5
  196. package/src/interfaces/signing-key-private-key-info.ts +0 -12
  197. package/src/interfaces/simple-public-key-only-buffer.ts +0 -3
  198. package/src/interfaces/simple-public-key-only.ts +0 -3
  199. package/src/interfaces/single-encrypted-parsed-header.ts +0 -35
  200. package/src/interfaces/wrapped-key-consts.ts +0 -6
  201. package/src/member.ts +0 -463
  202. package/src/services/aes-gcm.ts +0 -160
  203. package/src/services/ecies/crypto-core.ts +0 -213
  204. package/src/services/ecies/file.ts +0 -174
  205. package/src/services/ecies/multi-recipient.ts +0 -583
  206. package/src/services/ecies/service.ts +0 -351
  207. package/src/services/ecies/signature.ts +0 -91
  208. package/src/services/ecies/single-recipient.ts +0 -676
  209. package/src/services/ecies/utilities.ts +0 -111
  210. package/src/services/index.ts +0 -3
  211. package/src/services/pbkdf2.ts +0 -307
  212. package/src/utils.ts +0 -104
@@ -0,0 +1,360 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EciesMultiRecipient = void 0;
4
+ const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
5
+ const crypto_1 = require("crypto");
6
+ const mongodb_1 = require("mongodb");
7
+ const constants_1 = require("../../constants");
8
+ const ecies_i18n_factory_1 = require("../../i18n/ecies-i18n-factory");
9
+ const single_recipient_1 = require("./single-recipient");
10
+ /**
11
+ * Multiple recipient encryption/decryption functions for ECIES
12
+ */
13
+ class EciesMultiRecipient {
14
+ cryptoCore;
15
+ singleRecipientCore;
16
+ engine;
17
+ constructor(cryptoCore, engine) {
18
+ this.cryptoCore = cryptoCore;
19
+ this.engine = engine || (0, ecies_i18n_factory_1.createEciesTranslationEngine)();
20
+ this.singleRecipientCore = new single_recipient_1.EciesSingleRecipientCore(cryptoCore.config, this.engine);
21
+ }
22
+ /**
23
+ * Get the size of the header for a given encryption type
24
+ * @param encryptionType The encryption type (single, simple, etc.)
25
+ * @param options Optional encryption options
26
+ * @param options.recipientCount The number of recipients
27
+ * @returns
28
+ */
29
+ getHeaderSize(recipientCount) {
30
+ return (this.cryptoCore.consts.MULTIPLE.FIXED_OVERHEAD_SIZE +
31
+ recipientCount * this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE);
32
+ }
33
+ /**
34
+ * Encrypt a message symmetric key with a public key
35
+ * @param receiverPublicKey The public key of the receiver
36
+ * @param messageSymmetricKey The message to encrypt
37
+ * @returns The encrypted message
38
+ */
39
+ encryptKey(receiverPublicKey, messageSymmetricKey) {
40
+ // Generate ephemeral ECDH key pair
41
+ const ecdh = (0, crypto_1.createECDH)(this.cryptoCore.config.curveName);
42
+ ecdh.generateKeys();
43
+ // Compute shared secret
44
+ let sharedSecret;
45
+ try {
46
+ // Make sure we normalize the receiver's public key
47
+ const normalizedReceiverPublicKey = this.cryptoCore.normalizePublicKey(receiverPublicKey);
48
+ // Ensure we're using the properly formatted public key (with 0x04 prefix)
49
+ // Our debugging shows only the full format with prefix works correctly
50
+ sharedSecret = ecdh.computeSecret(normalizedReceiverPublicKey);
51
+ }
52
+ catch (error) {
53
+ console.error('[ERROR][encrypt] Failed to compute shared secret:', error);
54
+ if (error instanceof Error) {
55
+ if ('code' in error &&
56
+ error.code === 'ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY') {
57
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidRecipientPublicKey, this.engine, undefined, undefined, {
58
+ nodeError: error.code,
59
+ });
60
+ }
61
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.SecretComputationFailed, this.engine, undefined, undefined, {
62
+ error: error.message,
63
+ });
64
+ }
65
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.SecretComputationFailed, this.engine);
66
+ }
67
+ // Get the ephemeral public key and ensure it has the 0x04 prefix
68
+ let ephemeralPublicKey = ecdh.getPublicKey();
69
+ if (ephemeralPublicKey.length === this.cryptoCore.consts.RAW_PUBLIC_KEY_LENGTH) {
70
+ ephemeralPublicKey = Buffer.concat([
71
+ Buffer.from([this.cryptoCore.consts.PUBLIC_KEY_MAGIC]),
72
+ ephemeralPublicKey,
73
+ ]);
74
+ }
75
+ // Get the key from the shared secret (always use first 32 bytes)
76
+ const symKey = sharedSecret.subarray(0, this.cryptoCore.consts.SYMMETRIC.KEY_SIZE);
77
+ const iv = (0, crypto_1.randomBytes)(this.cryptoCore.consts.IV_SIZE);
78
+ // Create cipher with the derived symmetric key
79
+ const cipher = (0, crypto_1.createCipheriv)(this.cryptoCore.consts.SYMMETRIC_ALGORITHM_CONFIGURATION, symKey, iv);
80
+ // Ensure auto padding is enabled
81
+ cipher.setAutoPadding(true);
82
+ // Encrypt the message
83
+ let encrypted = cipher.update(messageSymmetricKey);
84
+ encrypted = Buffer.concat([encrypted, cipher.final()]);
85
+ // Get and explicitly set the authentication tag to max tag length for consistency
86
+ const authTag = cipher.getAuthTag();
87
+ // Format:ephemeralPublicKey (65) | iv (16) | authTag (16) | encryptedData (this.cryptoCore.consts.SYMMETRIC.KEY_SIZE = 32)
88
+ return Buffer.concat([ephemeralPublicKey, iv, authTag, encrypted]);
89
+ }
90
+ /**
91
+ * Decrypts symmetric key encrypted with ECIES using a header
92
+ * @param privateKey The private key to decrypt the data
93
+ * @param encryptedKey The data to decrypt
94
+ * @returns The decrypted data buffer
95
+ */
96
+ decryptKey(privateKey, encryptedKey) {
97
+ if (encryptedKey.length !== this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE) {
98
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptedKeyLength, this.engine, undefined, undefined, {
99
+ expected: String(this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE),
100
+ actual: String(encryptedKey.length),
101
+ });
102
+ }
103
+ const ephemeralPublicKey = encryptedKey.subarray(0, this.cryptoCore.consts.PUBLIC_KEY_LENGTH);
104
+ const iv = encryptedKey.subarray(this.cryptoCore.consts.PUBLIC_KEY_LENGTH, this.cryptoCore.consts.PUBLIC_KEY_LENGTH + this.cryptoCore.consts.IV_SIZE);
105
+ const authTag = encryptedKey.subarray(this.cryptoCore.consts.PUBLIC_KEY_LENGTH + this.cryptoCore.consts.IV_SIZE, this.cryptoCore.consts.PUBLIC_KEY_LENGTH + this.cryptoCore.consts.IV_SIZE + this.cryptoCore.consts.AUTH_TAG_SIZE);
106
+ const encrypted = encryptedKey.subarray(this.cryptoCore.consts.PUBLIC_KEY_LENGTH + this.cryptoCore.consts.IV_SIZE + this.cryptoCore.consts.AUTH_TAG_SIZE, this.cryptoCore.consts.PUBLIC_KEY_LENGTH +
107
+ this.cryptoCore.consts.IV_SIZE +
108
+ this.cryptoCore.consts.AUTH_TAG_SIZE +
109
+ this.cryptoCore.consts.SYMMETRIC.KEY_SIZE);
110
+ // Normalize the public key (ensuring 0x04 prefix)
111
+ const normalizedKey = this.cryptoCore.normalizePublicKey(ephemeralPublicKey);
112
+ // Decrypt using components with the normalized key
113
+ const decrypted = this.singleRecipientCore.decryptWithComponents(privateKey, normalizedKey, iv, authTag, encrypted);
114
+ if (decrypted.length !== this.cryptoCore.consts.SYMMETRIC.KEY_SIZE) {
115
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength, this.engine, undefined, undefined, {
116
+ expected: String(this.cryptoCore.consts.SYMMETRIC.KEY_SIZE),
117
+ actual: String(decrypted.length),
118
+ });
119
+ }
120
+ return decrypted;
121
+ }
122
+ /**
123
+ * Encrypts a message for multiple recipients.
124
+ * @param recipients The recipients to encrypt the message for.
125
+ * @param message The message to encrypt.
126
+ * @param preamble Optional preamble to include in the encrypted message.
127
+ * @returns The encrypted message.
128
+ * @throws EciesError if the number of recipients is greater than 65535.
129
+ */
130
+ encryptMultiple(recipients, message, preamble) {
131
+ if (recipients.length > ecies_lib_1.Constants.UINT16_MAX) {
132
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.TooManyRecipients, this.engine);
133
+ }
134
+ const messageTypeBuffer = Buffer.alloc(1);
135
+ messageTypeBuffer.writeUint8(ecies_lib_1.EciesEncryptionTypeEnum.Multiple);
136
+ // Generate a random symmetric key
137
+ const symmetricKey = (0, crypto_1.randomBytes)(this.cryptoCore.consts.SYMMETRIC.KEY_SIZE);
138
+ const iv = (0, crypto_1.randomBytes)(this.cryptoCore.consts.IV_SIZE);
139
+ // Encrypt the message with the symmetric key
140
+ const cipher = (0, crypto_1.createCipheriv)(this.cryptoCore.consts.SYMMETRIC_ALGORITHM_CONFIGURATION, symmetricKey, iv);
141
+ const encrypted = cipher.update(message);
142
+ const final = cipher.final();
143
+ const authTag = cipher.getAuthTag();
144
+ const encryptedMessage = Buffer.concat([encrypted, final]);
145
+ const storedMessage = Buffer.concat([
146
+ preamble ?? Buffer.alloc(0),
147
+ iv,
148
+ authTag,
149
+ encryptedMessage,
150
+ ]);
151
+ const encryptionResults = recipients.map((member) => ({
152
+ id: member.id,
153
+ encryptedKey: this.encryptKey(member.publicKey, symmetricKey),
154
+ }));
155
+ const recipientIds = encryptionResults.map(({ id }) => id);
156
+ const recipientKeys = encryptionResults.map(({ encryptedKey }) => encryptedKey);
157
+ // Verify the encrypted message size (just the encrypted content)
158
+ if (encryptedMessage.length !== message.length) {
159
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.MessageLengthMismatch, this.engine);
160
+ }
161
+ const headerSize = this.calculateECIESMultipleRecipientOverhead(recipients.length, false, recipientKeys);
162
+ return {
163
+ dataLength: message.length,
164
+ recipientCount: recipients.length,
165
+ recipientIds,
166
+ recipientKeys,
167
+ encryptedMessage: storedMessage,
168
+ headerSize,
169
+ };
170
+ }
171
+ /**
172
+ * Decrypts a message encrypted with multiple ECIE for a recipient.
173
+ * @param encryptedData The encrypted data.
174
+ * @param recipient The recipient.
175
+ * @returns The decrypted message.
176
+ */
177
+ decryptMultipleECIEForRecipient(encryptedData, recipient) {
178
+ if (recipient.privateKey === undefined) {
179
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.PrivateKeyNotLoaded, this.engine);
180
+ }
181
+ // Find this recipient's encrypted key
182
+ const recipientIndex = encryptedData.recipientIds.findIndex((id) => id.equals(recipient.id));
183
+ if (recipientIndex === -1) {
184
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.RecipientNotFound, this.engine);
185
+ }
186
+ const encryptedKey = encryptedData.recipientKeys[recipientIndex];
187
+ // Decrypt the symmetric key using the detected encryption type
188
+ const symmetricKey = this.decryptKey(Buffer.from(recipient.privateKey.value), encryptedKey);
189
+ // Extract the IV and auth tag from the encrypted message
190
+ const iv = encryptedData.encryptedMessage.subarray(0, this.cryptoCore.consts.IV_SIZE);
191
+ const authTag = encryptedData.encryptedMessage.subarray(this.cryptoCore.consts.IV_SIZE, this.cryptoCore.consts.IV_SIZE + this.cryptoCore.consts.AUTH_TAG_SIZE);
192
+ // Extract the encrypted content (no CRC, AES-GCM provides authentication)
193
+ const encrypted = encryptedData.encryptedMessage.subarray(this.cryptoCore.consts.IV_SIZE + this.cryptoCore.consts.AUTH_TAG_SIZE);
194
+ // Decrypt the content with the symmetric key
195
+ const decipher = (0, crypto_1.createDecipheriv)(this.cryptoCore.consts.SYMMETRIC_ALGORITHM_CONFIGURATION, symmetricKey, iv);
196
+ decipher.setAuthTag(authTag);
197
+ const decrypted = decipher.update(encrypted);
198
+ const final = decipher.final();
199
+ const decryptedMessage = Buffer.concat([decrypted, final]);
200
+ // AES-GCM provides authentication via auth tag (no separate CRC needed)
201
+ // The decrypted message should match the original data length
202
+ if (decryptedMessage.length !== encryptedData.dataLength) {
203
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength, this.engine);
204
+ }
205
+ return decryptedMessage;
206
+ }
207
+ /**
208
+ * Calculate the overhead for a message encrypted for multiple recipients
209
+ * @param recipientCount number of recipients
210
+ * @param includeMessageOverhead whether to include the overhead for the encrypted message
211
+ * @param encryptedKeys optional array of encrypted keys to calculate actual size
212
+ * @returns the overhead size in bytes
213
+ */
214
+ calculateECIESMultipleRecipientOverhead(recipientCount, includeMessageOverhead, encryptedKeys) {
215
+ if (recipientCount < 2) {
216
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidRecipientCount, this.engine);
217
+ }
218
+ // Calculate encrypted keys size
219
+ let encryptedKeysSize;
220
+ if (encryptedKeys) {
221
+ encryptedKeysSize = encryptedKeys.reduce((total, key) => total + key.length, 0);
222
+ }
223
+ else {
224
+ // Default assumption: all keys use Simple encryption type (more efficient)
225
+ encryptedKeysSize = recipientCount * this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE;
226
+ }
227
+ const baseOverhead = this.cryptoCore.consts.MULTIPLE.DATA_LENGTH_SIZE +
228
+ this.cryptoCore.consts.MULTIPLE.RECIPIENT_COUNT_SIZE +
229
+ recipientCount * constants_1.Constants.OBJECT_ID_LENGTH + // recipient ids
230
+ encryptedKeysSize; // actual encrypted keys size
231
+ return includeMessageOverhead
232
+ ? baseOverhead + this.cryptoCore.consts.MULTIPLE.FIXED_OVERHEAD_SIZE
233
+ : baseOverhead;
234
+ }
235
+ /**
236
+ * Builds the header for a message encrypted for multiple recipients
237
+ * @param data The encrypted message data including recipients and encrypted keys
238
+ * @returns The header buffer for the message
239
+ * @throws EciesError if the number of recipients is greater than the maximum allowed
240
+ * @throws EciesError if the number of encrypted keys does not match the number of recipients
241
+ */
242
+ buildECIESMultipleRecipientHeader(data) {
243
+ if (data.recipientIds.length > this.cryptoCore.consts.MULTIPLE.MAX_RECIPIENTS) {
244
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.TooManyRecipients, this.engine);
245
+ }
246
+ else if (data.recipientIds.length !== data.recipientKeys.length) {
247
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.RecipientKeyCountMismatch, this.engine);
248
+ }
249
+ else if (data.dataLength < 0 ||
250
+ data.dataLength > this.cryptoCore.consts.MAX_RAW_DATA_SIZE) {
251
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.FileSizeTooLarge, this.engine);
252
+ }
253
+ // Create data length buffer
254
+ const dataLengthBuffer = Buffer.alloc(this.cryptoCore.consts.MULTIPLE.DATA_LENGTH_SIZE);
255
+ dataLengthBuffer.writeBigUInt64BE(BigInt(data.dataLength));
256
+ // Create recipient count buffer
257
+ const recipientCountBuffer = Buffer.alloc(this.cryptoCore.consts.MULTIPLE.RECIPIENT_COUNT_SIZE);
258
+ recipientCountBuffer.writeUInt16BE(data.recipientIds.length);
259
+ // Create recipients buffer
260
+ const recipientsBuffer = Buffer.alloc(data.recipientIds.length * constants_1.Constants.OBJECT_ID_LENGTH);
261
+ data.recipientIds.forEach((recipientId, index) => {
262
+ recipientsBuffer.set(Buffer.from(recipientId.toHexString(), 'hex'), index * constants_1.Constants.OBJECT_ID_LENGTH);
263
+ });
264
+ // Validate encrypted key lengths based on their encryption type
265
+ data.recipientKeys.forEach((encryptedKey) => {
266
+ if (encryptedKey.length === 0) {
267
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptedKeyLength, this.engine);
268
+ }
269
+ if (encryptedKey.length !== this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE) {
270
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptedKeyLength, this.engine, undefined, undefined, {
271
+ expected: String(this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE),
272
+ actual: String(encryptedKey.length),
273
+ });
274
+ }
275
+ });
276
+ // Create encrypted keys buffer with variable-length keys
277
+ const encryptedKeysBuffer = Buffer.concat(data.recipientKeys);
278
+ // Combine all buffers to form the header
279
+ return Buffer.concat([
280
+ dataLengthBuffer,
281
+ recipientCountBuffer,
282
+ recipientsBuffer,
283
+ encryptedKeysBuffer,
284
+ ]);
285
+ }
286
+ /**
287
+ * Parses a multi-encrypted header.
288
+ * @param data - The data to parse.
289
+ * @returns The parsed header.
290
+ */
291
+ parseMultiEncryptedHeader(data) {
292
+ // Ensure there's enough data to read headers
293
+ if (data.length < this.cryptoCore.consts.MULTIPLE.FIXED_OVERHEAD_SIZE) {
294
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength, this.engine);
295
+ }
296
+ let offset = 0;
297
+ // Read data length
298
+ const dataLength = Number(data.readBigUInt64BE(offset));
299
+ if (dataLength <= 0 || dataLength > this.cryptoCore.consts.MAX_RAW_DATA_SIZE) {
300
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength, this.engine);
301
+ }
302
+ offset += this.cryptoCore.consts.MULTIPLE.DATA_LENGTH_SIZE; // 8 bytes
303
+ // Read recipient count
304
+ const recipientCount = data.readUInt16BE(offset);
305
+ if (recipientCount <= 0 || recipientCount > this.cryptoCore.consts.MULTIPLE.MAX_RECIPIENTS) {
306
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidRecipientCount, this.engine);
307
+ }
308
+ offset += this.cryptoCore.consts.MULTIPLE.RECIPIENT_COUNT_SIZE; // 2 bytes
309
+ // Ensure there's enough data for all recipients
310
+ const requiredLength = this.calculateECIESMultipleRecipientOverhead(recipientCount, false);
311
+ if (data.length < requiredLength) {
312
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength, this.engine);
313
+ }
314
+ // Read recipient IDs
315
+ const recipientIds = [];
316
+ for (let i = 0; i < recipientCount; i++) {
317
+ recipientIds.push(new mongodb_1.ObjectId(data
318
+ .subarray(offset, offset + constants_1.Constants.OBJECT_ID_LENGTH)
319
+ .toString('hex')));
320
+ offset += constants_1.Constants.OBJECT_ID_LENGTH;
321
+ }
322
+ // Read encrypted keys with variable lengths based on encryption type
323
+ const recipientKeys = [];
324
+ for (let i = 0; i < recipientCount; i++) {
325
+ if (offset >= data.length) {
326
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength, this.engine);
327
+ }
328
+ if (offset + this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE > data.length) {
329
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength, this.engine, undefined, undefined, {
330
+ required: String(this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE),
331
+ available: String(data.length - offset),
332
+ });
333
+ }
334
+ recipientKeys.push(data.subarray(offset, offset + this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE));
335
+ offset += this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE;
336
+ }
337
+ return {
338
+ dataLength,
339
+ recipientCount,
340
+ recipientIds,
341
+ recipientKeys,
342
+ headerSize: offset,
343
+ };
344
+ }
345
+ /**
346
+ * Parses a multi-encrypted buffer into its components.
347
+ * @param data - The multi-encrypted buffer to parse.
348
+ * @returns The parsed multi-encrypted buffer.
349
+ */
350
+ parseMultiEncryptedBuffer(data) {
351
+ const header = this.parseMultiEncryptedHeader(data);
352
+ const encryptedMessage = data.subarray(header.headerSize);
353
+ return {
354
+ ...header,
355
+ encryptedMessage,
356
+ };
357
+ }
358
+ }
359
+ exports.EciesMultiRecipient = EciesMultiRecipient;
360
+ //# sourceMappingURL=multi-recipient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-recipient.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/services/ecies/multi-recipient.ts"],"names":[],"mappings":";;;AAAA,0DAMoC;AAGpC,mCAKgB;AAChB,qCAAmC;AAEnC,+CAA4C;AAC5C,sEAA6E;AAM7E,yDAA8D;AAE9D;;GAEG;AACH,MAAa,mBAAmB;IACX,UAAU,CAAkB;IAC5B,mBAAmB,CAA2B;IAC9C,MAAM,CAAqC;IAE9D,YACE,UAA2B,EAC3B,MAA2C;QAE3C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAA,iDAA4B,GAAE,CAAC;QACvD,IAAI,CAAC,mBAAmB,GAAG,IAAI,2CAAwB,CACrD,UAAU,CAAC,MAAM,EACjB,IAAI,CAAC,MAAM,CACZ,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACI,aAAa,CAAC,cAAsB;QACzC,OAAO,CACL,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB;YACnD,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CACpE,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACI,UAAU,CACf,iBAAyB,EACzB,mBAA2B;QAE3B,mCAAmC;QACnC,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC1D,IAAI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Config, IECIESConstants, SecureString } from '@digitaldefiance/ecies-lib';
2
+ import { Wallet } from '@ethereumjs/wallet';
3
+ import { Member } from '../../member';
4
+ import { CoreLanguageCode, PluginI18nEngine } from '@digitaldefiance/i18n-lib';
5
+ import { IWalletSeed } from '../../interfaces';
6
+ import { IMultiEncryptedMessage } from '../../interfaces/multi-encrypted-message';
7
+ import { IMultiEncryptedParsedHeader } from '../../interfaces/multi-encrypted-parsed-header';
8
+ import { ISingleEncryptedParsedHeader } from '../../interfaces/single-encrypted-parsed-header';
9
+ import { SignatureBuffer, SignatureString } from '../../types';
10
+ import { EciesCryptoCore } from './crypto-core';
11
+ import { EciesMultiRecipient } from './multi-recipient';
12
+ import { EciesSignature } from './signature';
13
+ import { EciesSingleRecipientCore } from './single-recipient';
14
+ import { EciesUtilities } from './utilities';
15
+ /**
16
+ * Unified ECIES service that integrates all the modular components
17
+ */
18
+ export declare class ECIESService {
19
+ protected readonly _config: IECIESConfig;
20
+ protected readonly cryptoCore: EciesCryptoCore;
21
+ protected readonly signature: EciesSignature;
22
+ protected readonly singleRecipient: EciesSingleRecipientCore;
23
+ protected readonly multiRecipient: EciesMultiRecipient;
24
+ protected readonly utilities: EciesUtilities;
25
+ protected readonly engine: PluginI18nEngine<CoreLanguageCode>;
26
+ constructor(engineOrConfig?: PluginI18nEngine<CoreLanguageCode> | Partial<IECIESConfig>, config?: Partial<IECIESConfig>, eciesParams?: IECIESConstants);
27
+ get core(): EciesCryptoCore;
28
+ get config(): IECIESConfig;
29
+ /**
30
+ * The name of the elliptic curve used for ECIES encryption/decryption
31
+ */
32
+ get curveName(): string;
33
+ generateNewMnemonic(): SecureString;
34
+ walletFromSeed(seed: Buffer): Wallet;
35
+ walletAndSeedFromMnemonic(mnemonic: SecureString): IWalletSeed;
36
+ walletToSimpleKeyPairBuffer(wallet: Wallet): import("../../interfaces").ISimpleKeyPairBuffer;
37
+ seedToSimpleKeyPairBuffer(seed: Buffer): import("../../interfaces").ISimpleKeyPairBuffer;
38
+ mnemonicToSimpleKeyPairBuffer(mnemonic: SecureString): import("../../interfaces").ISimpleKeyPairBuffer;
39
+ encryptSimpleOrSingle(encryptSimple: boolean, receiverPublicKey: Buffer, message: Buffer, preamble?: Buffer): Buffer;
40
+ parseSingleEncryptedHeader(encryptionType: EciesEncryptionTypeEnum, data: Buffer, preambleSize?: number, options?: {
41
+ dataLength?: number;
42
+ }): ISingleEncryptedParsedHeader;
43
+ decryptSimpleOrSingleWithHeader(decryptSimple: boolean, privateKey: Buffer, encryptedData: Buffer, preambleSize?: number, options?: {
44
+ dataLength?: number;
45
+ }): Buffer;
46
+ decryptSimpleOrSingleWithHeaderEx(encryptionType: EciesEncryptionTypeEnum, privateKey: Buffer, encryptedData: Buffer, preambleSize?: number, options?: {
47
+ dataLength?: number;
48
+ }): {
49
+ decrypted: Buffer;
50
+ consumedBytes: number;
51
+ };
52
+ decryptSingleWithComponents(privateKey: Buffer, ephemeralPublicKey: Buffer, iv: Buffer, authTag: Buffer, encrypted: Buffer): {
53
+ decrypted: Buffer;
54
+ ciphertextLength?: number;
55
+ };
56
+ signMessage(privateKey: Buffer, data: Buffer): SignatureBuffer;
57
+ verifyMessage(publicKey: Buffer, data: Buffer, signature: SignatureBuffer): boolean;
58
+ signatureStringToSignatureBuffer(signatureString: HexString): SignatureBuffer;
59
+ signatureBufferToSignatureString(signatureBuffer: SignatureBuffer): SignatureString;
60
+ encryptMultiple(recipients: Member[], message: Buffer): IMultiEncryptedMessage;
61
+ decryptMultipleECIEForRecipient(encryptedData: IMultiEncryptedMessage, recipient: Member): Buffer;
62
+ calculateECIESMultipleRecipientOverhead(recipientCount: number, includeMessageOverhead: boolean): number;
63
+ buildECIESMultipleRecipientHeader(data: IMultiEncryptedMessage): Buffer;
64
+ parseMultiEncryptedHeader(data: Buffer): IMultiEncryptedParsedHeader;
65
+ parseMultiEncryptedBuffer(data: Buffer): IMultiEncryptedMessage;
66
+ computeEncryptedLengthFromDataLength(dataLength: number, encryptionMode: EciesEncryptionType, recipientCount?: number): number;
67
+ computeDecryptedLengthFromEncryptedDataLength(encryptedDataLength: number, padding?: number): number;
68
+ encrypt(encryptionType: EciesEncryptionType, recipients: Member[], message: Buffer, preamble?: Buffer): Buffer;
69
+ }
70
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/services/ecies/service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EAGvB,SAAS,EACT,YAAY,EACZ,eAAe,EACf,YAAY,EACb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAO5C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE/E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAClF,OAAO,EAAE,2BAA2B,EAAE,MAAM,gDAAgD,CAAC;AAC7F,OAAO,EAAE,4BAA4B,EAAE,MAAM,iDAAiD,CAAC;AAC/F,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,qBAAa,YAAY;IACvB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IACzC,SAAS,CAAC,QAAQ,CAAC,UA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AAM,GAAG,sBAAsB;IAM/D,oCAAoC,CACzC,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,mBAAmB,EACnC,cAAc,CAAC,EAAE,MAAM,GACtB,MAAM;IAQF,6CAA6C,CAClD,mBAAmB,EAAE,MAAM,EAC3B,OAAO,CAAC,EAAE,MAAM,GACf,MAAM;IAOF,OAAO,CACZ,cAAc,EAAE,mBAAmB,EACnC,UAAU,EAAE,MAAM,EAAE,EACpB,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM;CAoCV"}
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ECIESService = void 0;
4
+ const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
5
+ const ecies_i18n_factory_1 = require("../../i18n/ecies-i18n-factory");
6
+ const constants_1 = require("../../constants");
7
+ const crypto_core_1 = require("./crypto-core");
8
+ const multi_recipient_1 = require("./multi-recipient");
9
+ const signature_1 = require("./signature");
10
+ const single_recipient_1 = require("./single-recipient");
11
+ const utilities_1 = require("./utilities");
12
+ /**
13
+ * Unified ECIES service that integrates all the modular components
14
+ */
15
+ class ECIESService {
16
+ _config;
17
+ cryptoCore;
18
+ signature;
19
+ singleRecipient;
20
+ multiRecipient;
21
+ utilities;
22
+ engine;
23
+ constructor(engineOrConfig, config, eciesParams = constants_1.Constants.ECIES) {
24
+ // Determine if first parameter is engine or config
25
+ let engine;
26
+ let actualConfig;
27
+ if (engineOrConfig && 'translate' in engineOrConfig) {
28
+ // First parameter is an engine
29
+ engine = engineOrConfig;
30
+ actualConfig = config || {};
31
+ }
32
+ else {
33
+ // First parameter is config or undefined
34
+ engine = (0, ecies_i18n_factory_1.createEciesTranslationEngine)();
35
+ actualConfig = engineOrConfig || {};
36
+ }
37
+ const eciesConsts = eciesParams;
38
+ this._config = {
39
+ ...config,
40
+ curveName: eciesConsts.CURVE_NAME,
41
+ primaryKeyDerivationPath: eciesConsts.PRIMARY_KEY_DERIVATION_PATH,
42
+ mnemonicStrength: eciesConsts.MNEMONIC_STRENGTH,
43
+ symmetricAlgorithm: eciesConsts.SYMMETRIC.ALGORITHM,
44
+ symmetricKeyBits: eciesConsts.SYMMETRIC.KEY_BITS,
45
+ symmetricKeyMode: eciesConsts.SYMMETRIC.MODE,
46
+ ...actualConfig,
47
+ };
48
+ // Initialize all components
49
+ this.engine = engine;
50
+ this.cryptoCore = new crypto_core_1.EciesCryptoCore(this._config, eciesParams);
51
+ this.signature = new signature_1.EciesSignature(this.cryptoCore);
52
+ this.singleRecipient = new single_recipient_1.EciesSingleRecipientCore(this._config, engine);
53
+ this.multiRecipient = new multi_recipient_1.EciesMultiRecipient(this.cryptoCore, engine);
54
+ this.utilities = new utilities_1.EciesUtilities();
55
+ }
56
+ get core() {
57
+ return this.cryptoCore;
58
+ }
59
+ get config() {
60
+ return this._config;
61
+ }
62
+ /**
63
+ * The name of the elliptic curve used for ECIES encryption/decryption
64
+ */
65
+ get curveName() {
66
+ return this._config.curveName;
67
+ }
68
+ // === Key Management Methods ===
69
+ generateNewMnemonic() {
70
+ return this.cryptoCore.generateNewMnemonic();
71
+ }
72
+ walletFromSeed(seed) {
73
+ return this.cryptoCore.walletFromSeed(seed);
74
+ }
75
+ walletAndSeedFromMnemonic(mnemonic) {
76
+ return this.cryptoCore.walletAndSeedFromMnemonic(mnemonic);
77
+ }
78
+ walletToSimpleKeyPairBuffer(wallet) {
79
+ return this.cryptoCore.walletToSimpleKeyPairBuffer(wallet);
80
+ }
81
+ seedToSimpleKeyPairBuffer(seed) {
82
+ return this.cryptoCore.seedToSimpleKeyPairBuffer(seed);
83
+ }
84
+ mnemonicToSimpleKeyPairBuffer(mnemonic) {
85
+ return this.cryptoCore.mnemonicToSimpleKeyPairBuffer(mnemonic);
86
+ }
87
+ // === Core Encryption/Decryption Methods ===
88
+ encryptSimpleOrSingle(encryptSimple, receiverPublicKey, message, preamble = Buffer.alloc(0)) {
89
+ return this.singleRecipient.encrypt(encryptSimple, receiverPublicKey, message, preamble);
90
+ }
91
+ parseSingleEncryptedHeader(encryptionType, data, preambleSize = 0, options) {
92
+ const { header } = this.singleRecipient.parseEncryptedMessage(encryptionType, data, preambleSize, options);
93
+ return header;
94
+ }
95
+ decryptSimpleOrSingleWithHeader(decryptSimple, privateKey, encryptedData, preambleSize = 0, options) {
96
+ return this.singleRecipient.decryptWithHeader(decryptSimple
97
+ ? ecies_lib_1.EciesEncryptionTypeEnum.Simple
98
+ : ecies_lib_1.EciesEncryptionTypeEnum.Single, privateKey, encryptedData, preambleSize, options);
99
+ }
100
+ decryptSimpleOrSingleWithHeaderEx(encryptionType, privateKey, encryptedData, preambleSize = 0, options) {
101
+ return this.singleRecipient.decryptWithHeaderEx(encryptionType, privateKey, encryptedData, preambleSize, options);
102
+ }
103
+ decryptSingleWithComponents(privateKey, ephemeralPublicKey, iv, authTag, encrypted) {
104
+ const decrypted = this.singleRecipient.decryptWithComponents(privateKey, ephemeralPublicKey, iv, authTag, encrypted);
105
+ // Return an object with a 'decrypted' property for compatibility with existing code
106
+ return { decrypted, ciphertextLength: encrypted.length };
107
+ }
108
+ // === Signature Methods ===
109
+ signMessage(privateKey, data) {
110
+ return this.signature.signMessage(privateKey, data);
111
+ }
112
+ verifyMessage(publicKey, data, signature) {
113
+ return this.signature.verifyMessage(publicKey, data, signature);
114
+ }
115
+ signatureStringToSignatureBuffer(signatureString) {
116
+ return this.signature.signatureStringToSignatureBuffer(signatureString);
117
+ }
118
+ signatureBufferToSignatureString(signatureBuffer) {
119
+ return this.signature.signatureBufferToSignatureString(signatureBuffer);
120
+ }
121
+ // === Multi-Recipient Methods ===
122
+ encryptMultiple(recipients, message) {
123
+ return this.multiRecipient.encryptMultiple(recipients, message);
124
+ }
125
+ decryptMultipleECIEForRecipient(encryptedData, recipient) {
126
+ return this.multiRecipient.decryptMultipleECIEForRecipient(encryptedData, recipient);
127
+ }
128
+ calculateECIESMultipleRecipientOverhead(recipientCount, includeMessageOverhead) {
129
+ return this.multiRecipient.calculateECIESMultipleRecipientOverhead(recipientCount, includeMessageOverhead);
130
+ }
131
+ buildECIESMultipleRecipientHeader(data) {
132
+ return this.multiRecipient.buildECIESMultipleRecipientHeader(data);
133
+ }
134
+ parseMultiEncryptedHeader(data) {
135
+ return this.multiRecipient.parseMultiEncryptedHeader(data);
136
+ }
137
+ parseMultiEncryptedBuffer(data) {
138
+ return this.multiRecipient.parseMultiEncryptedBuffer(data);
139
+ }
140
+ // === Utility Methods ===
141
+ computeEncryptedLengthFromDataLength(dataLength, encryptionMode, recipientCount) {
142
+ return this.utilities.computeEncryptedLengthFromDataLength(dataLength, encryptionMode, recipientCount);
143
+ }
144
+ computeDecryptedLengthFromEncryptedDataLength(encryptedDataLength, padding) {
145
+ return this.utilities.computeDecryptedLengthFromEncryptedDataLength(encryptedDataLength, padding);
146
+ }
147
+ encrypt(encryptionType, recipients, message, preamble) {
148
+ if ((encryptionType === 'simple' || encryptionType === 'single') &&
149
+ recipients.length === 1) {
150
+ return this.singleRecipient.encrypt(encryptionType === 'simple', recipients[0].publicKey, message, preamble);
151
+ }
152
+ else if (encryptionType === 'multiple' && recipients.length > 1) {
153
+ const result = this.multiRecipient.encryptMultiple(recipients, message, preamble);
154
+ return result.encryptedMessage;
155
+ }
156
+ else {
157
+ const pluginEngine = (0, ecies_i18n_factory_1.getEciesPluginI18nEngine)();
158
+ throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptionType, this.engine, undefined, undefined, {
159
+ error: pluginEngine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_InvalidEncryptionTypeOrNumberOfRecipients),
160
+ encryptionType: encryptionType,
161
+ recipients: String(recipients.length),
162
+ });
163
+ }
164
+ }
165
+ }
166
+ exports.ECIESService = ECIESService;
167
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../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