@digitaldefiance/node-ecies-lib 1.0.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 (182) hide show
  1. package/LICENSE +21 -0
  2. package/dist/constants.d.ts +29 -0
  3. package/dist/constants.d.ts.map +1 -0
  4. package/dist/constants.js +129 -0
  5. package/dist/constants.js.map +1 -0
  6. package/dist/enumerations/index.d.ts +2 -0
  7. package/dist/enumerations/index.d.ts.map +1 -0
  8. package/dist/enumerations/index.js +2 -0
  9. package/dist/enumerations/index.js.map +1 -0
  10. package/dist/enumerations/pbkdf2-profile.d.ts +8 -0
  11. package/dist/enumerations/pbkdf2-profile.d.ts.map +1 -0
  12. package/dist/enumerations/pbkdf2-profile.js +9 -0
  13. package/dist/enumerations/pbkdf2-profile.js.map +1 -0
  14. package/dist/index.d.ts +6 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +6 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/interfaces/authenticated-cipher.d.ts +10 -0
  19. package/dist/interfaces/authenticated-cipher.d.ts.map +1 -0
  20. package/dist/interfaces/authenticated-cipher.js +2 -0
  21. package/dist/interfaces/authenticated-cipher.js.map +1 -0
  22. package/dist/interfaces/authenticated-decipher.d.ts +9 -0
  23. package/dist/interfaces/authenticated-decipher.d.ts.map +1 -0
  24. package/dist/interfaces/authenticated-decipher.js +2 -0
  25. package/dist/interfaces/authenticated-decipher.js.map +1 -0
  26. package/dist/interfaces/checksum-config.d.ts +5 -0
  27. package/dist/interfaces/checksum-config.d.ts.map +1 -0
  28. package/dist/interfaces/checksum-config.js +2 -0
  29. package/dist/interfaces/checksum-config.js.map +1 -0
  30. package/dist/interfaces/checksum-consts.d.ts +11 -0
  31. package/dist/interfaces/checksum-consts.d.ts.map +1 -0
  32. package/dist/interfaces/checksum-consts.js +2 -0
  33. package/dist/interfaces/checksum-consts.js.map +1 -0
  34. package/dist/interfaces/constants.d.ts +42 -0
  35. package/dist/interfaces/constants.d.ts.map +1 -0
  36. package/dist/interfaces/constants.js +2 -0
  37. package/dist/interfaces/constants.js.map +1 -0
  38. package/dist/interfaces/ecies-consts.d.ts +88 -0
  39. package/dist/interfaces/ecies-consts.d.ts.map +1 -0
  40. package/dist/interfaces/ecies-consts.js +2 -0
  41. package/dist/interfaces/ecies-consts.js.map +1 -0
  42. package/dist/interfaces/encryption-consts.d.ts +11 -0
  43. package/dist/interfaces/encryption-consts.d.ts.map +1 -0
  44. package/dist/interfaces/encryption-consts.js +2 -0
  45. package/dist/interfaces/encryption-consts.js.map +1 -0
  46. package/dist/interfaces/fec-consts.d.ts +5 -0
  47. package/dist/interfaces/fec-consts.d.ts.map +1 -0
  48. package/dist/interfaces/fec-consts.js +2 -0
  49. package/dist/interfaces/fec-consts.js.map +1 -0
  50. package/dist/interfaces/index.d.ts +18 -0
  51. package/dist/interfaces/index.d.ts.map +1 -0
  52. package/dist/interfaces/index.js +18 -0
  53. package/dist/interfaces/index.js.map +1 -0
  54. package/dist/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts +6 -0
  55. package/dist/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts.map +1 -0
  56. package/dist/interfaces/keypair-buffer-with-un-encrypted-private-key.js +2 -0
  57. package/dist/interfaces/keypair-buffer-with-un-encrypted-private-key.js.map +1 -0
  58. package/dist/interfaces/keyring-consts.d.ts +6 -0
  59. package/dist/interfaces/keyring-consts.d.ts.map +1 -0
  60. package/dist/interfaces/keyring-consts.js +2 -0
  61. package/dist/interfaces/keyring-consts.js.map +1 -0
  62. package/dist/interfaces/member-operational.d.ts +36 -0
  63. package/dist/interfaces/member-operational.d.ts.map +1 -0
  64. package/dist/interfaces/member-operational.js +2 -0
  65. package/dist/interfaces/member-operational.js.map +1 -0
  66. package/dist/interfaces/member-with-mnemonic.d.ts +7 -0
  67. package/dist/interfaces/member-with-mnemonic.d.ts.map +1 -0
  68. package/dist/interfaces/member-with-mnemonic.js +2 -0
  69. package/dist/interfaces/member-with-mnemonic.js.map +1 -0
  70. package/dist/interfaces/multi-encrypted-message.d.ts +8 -0
  71. package/dist/interfaces/multi-encrypted-message.d.ts.map +1 -0
  72. package/dist/interfaces/multi-encrypted-message.js +2 -0
  73. package/dist/interfaces/multi-encrypted-message.js.map +1 -0
  74. package/dist/interfaces/multi-encrypted-parsed-header.d.ts +24 -0
  75. package/dist/interfaces/multi-encrypted-parsed-header.d.ts.map +1 -0
  76. package/dist/interfaces/multi-encrypted-parsed-header.js +2 -0
  77. package/dist/interfaces/multi-encrypted-parsed-header.js.map +1 -0
  78. package/dist/interfaces/pbkdf-profiles.d.ts +6 -0
  79. package/dist/interfaces/pbkdf-profiles.d.ts.map +1 -0
  80. package/dist/interfaces/pbkdf-profiles.js +2 -0
  81. package/dist/interfaces/pbkdf-profiles.js.map +1 -0
  82. package/dist/interfaces/signing-key-private-key-info.d.ts +11 -0
  83. package/dist/interfaces/signing-key-private-key-info.d.ts.map +1 -0
  84. package/dist/interfaces/signing-key-private-key-info.js +2 -0
  85. package/dist/interfaces/signing-key-private-key-info.js.map +1 -0
  86. package/dist/interfaces/simple-keypair-buffer.d.ts +6 -0
  87. package/dist/interfaces/simple-keypair-buffer.d.ts.map +1 -0
  88. package/dist/interfaces/simple-keypair-buffer.js +2 -0
  89. package/dist/interfaces/simple-keypair-buffer.js.map +1 -0
  90. package/dist/interfaces/simple-keypair.d.ts +6 -0
  91. package/dist/interfaces/simple-keypair.d.ts.map +1 -0
  92. package/dist/interfaces/simple-keypair.js +2 -0
  93. package/dist/interfaces/simple-keypair.js.map +1 -0
  94. package/dist/interfaces/simple-public-key-only-buffer.d.ts +4 -0
  95. package/dist/interfaces/simple-public-key-only-buffer.d.ts.map +1 -0
  96. package/dist/interfaces/simple-public-key-only-buffer.js +2 -0
  97. package/dist/interfaces/simple-public-key-only-buffer.js.map +1 -0
  98. package/dist/interfaces/simple-public-key-only.d.ts +4 -0
  99. package/dist/interfaces/simple-public-key-only.d.ts.map +1 -0
  100. package/dist/interfaces/simple-public-key-only.js +2 -0
  101. package/dist/interfaces/simple-public-key-only.js.map +1 -0
  102. package/dist/interfaces/single-encrypted-parsed-header.d.ts +35 -0
  103. package/dist/interfaces/single-encrypted-parsed-header.d.ts.map +1 -0
  104. package/dist/interfaces/single-encrypted-parsed-header.js +2 -0
  105. package/dist/interfaces/single-encrypted-parsed-header.js.map +1 -0
  106. package/dist/interfaces/wallet-seed.d.ts +7 -0
  107. package/dist/interfaces/wallet-seed.d.ts.map +1 -0
  108. package/dist/interfaces/wallet-seed.js +2 -0
  109. package/dist/interfaces/wallet-seed.js.map +1 -0
  110. package/dist/interfaces/wrapped-key-consts.d.ts +7 -0
  111. package/dist/interfaces/wrapped-key-consts.d.ts.map +1 -0
  112. package/dist/interfaces/wrapped-key-consts.js +2 -0
  113. package/dist/interfaces/wrapped-key-consts.js.map +1 -0
  114. package/dist/member.d.ts +67 -0
  115. package/dist/member.d.ts.map +1 -0
  116. package/dist/member.js +256 -0
  117. package/dist/member.js.map +1 -0
  118. package/dist/services/ecies/crypto-core.d.ts +55 -0
  119. package/dist/services/ecies/crypto-core.d.ts.map +1 -0
  120. package/dist/services/ecies/crypto-core.debug.d.ts +13 -0
  121. package/dist/services/ecies/crypto-core.debug.d.ts.map +1 -0
  122. package/dist/services/ecies/crypto-core.debug.js +91 -0
  123. package/dist/services/ecies/crypto-core.debug.js.map +1 -0
  124. package/dist/services/ecies/crypto-core.js +115 -0
  125. package/dist/services/ecies/crypto-core.js.map +1 -0
  126. package/dist/services/ecies/debug-aes-gcm.d.ts +2 -0
  127. package/dist/services/ecies/debug-aes-gcm.d.ts.map +1 -0
  128. package/dist/services/ecies/debug-aes-gcm.js +106 -0
  129. package/dist/services/ecies/debug-aes-gcm.js.map +1 -0
  130. package/dist/services/ecies/debug-ecdh.d.ts +2 -0
  131. package/dist/services/ecies/debug-ecdh.d.ts.map +1 -0
  132. package/dist/services/ecies/debug-ecdh.js +123 -0
  133. package/dist/services/ecies/debug-ecdh.js.map +1 -0
  134. package/dist/services/ecies/debug-ecies-burnbag.d.ts +2 -0
  135. package/dist/services/ecies/debug-ecies-burnbag.d.ts.map +1 -0
  136. package/dist/services/ecies/debug-ecies-burnbag.js +134 -0
  137. package/dist/services/ecies/debug-ecies-burnbag.js.map +1 -0
  138. package/dist/services/ecies/debug-ecies.d.ts +2 -0
  139. package/dist/services/ecies/debug-ecies.d.ts.map +1 -0
  140. package/dist/services/ecies/debug-ecies.js +110 -0
  141. package/dist/services/ecies/debug-ecies.js.map +1 -0
  142. package/dist/services/ecies/debug-test.d.ts +2 -0
  143. package/dist/services/ecies/debug-test.d.ts.map +1 -0
  144. package/dist/services/ecies/debug-test.js +57 -0
  145. package/dist/services/ecies/debug-test.js.map +1 -0
  146. package/dist/services/ecies/file.d.ts +15 -0
  147. package/dist/services/ecies/file.d.ts.map +1 -0
  148. package/dist/services/ecies/file.js +104 -0
  149. package/dist/services/ecies/file.js.map +1 -0
  150. package/dist/services/ecies/index.d.ts +8 -0
  151. package/dist/services/ecies/index.d.ts.map +1 -0
  152. package/dist/services/ecies/index.js +8 -0
  153. package/dist/services/ecies/index.js.map +1 -0
  154. package/dist/services/ecies/multi-recipient.d.ts +83 -0
  155. package/dist/services/ecies/multi-recipient.d.ts.map +1 -0
  156. package/dist/services/ecies/multi-recipient.js +355 -0
  157. package/dist/services/ecies/multi-recipient.js.map +1 -0
  158. package/dist/services/ecies/service.d.ts +70 -0
  159. package/dist/services/ecies/service.d.ts.map +1 -0
  160. package/dist/services/ecies/service.js +145 -0
  161. package/dist/services/ecies/service.js.map +1 -0
  162. package/dist/services/ecies/signature.d.ts +38 -0
  163. package/dist/services/ecies/signature.d.ts.map +1 -0
  164. package/dist/services/ecies/signature.js +64 -0
  165. package/dist/services/ecies/signature.js.map +1 -0
  166. package/dist/services/ecies/single-recipient.d.ts +85 -0
  167. package/dist/services/ecies/single-recipient.d.ts.map +1 -0
  168. package/dist/services/ecies/single-recipient.js +390 -0
  169. package/dist/services/ecies/single-recipient.js.map +1 -0
  170. package/dist/services/ecies/utilities.d.ts +22 -0
  171. package/dist/services/ecies/utilities.d.ts.map +1 -0
  172. package/dist/services/ecies/utilities.js +65 -0
  173. package/dist/services/ecies/utilities.js.map +1 -0
  174. package/dist/services/index.d.ts +2 -0
  175. package/dist/services/index.d.ts.map +1 -0
  176. package/dist/services/index.js +2 -0
  177. package/dist/services/index.js.map +1 -0
  178. package/dist/types.d.ts +25 -0
  179. package/dist/types.d.ts.map +1 -0
  180. package/dist/types.js +2 -0
  181. package/dist/types.js.map +1 -0
  182. package/package.json +64 -0
@@ -0,0 +1,390 @@
1
+ import { ECIES, EciesEncryptionTypeEnum, EciesEncryptionTypeMap, ECIESError, ECIESErrorTypeEnum, encryptionTypeEnumToType, encryptionTypeToString, ensureEciesEncryptionTypeEnum, UINT32_MAX, UINT64_SIZE, } from '@digitaldefiance/ecies-lib';
2
+ import { createCipheriv, createDecipheriv, createECDH, randomBytes, } from 'crypto';
3
+ import { EciesCryptoCore } from './crypto-core';
4
+ export class EciesSingleRecipientCore {
5
+ cryptoCore;
6
+ config;
7
+ engine;
8
+ constructor(config, engine) {
9
+ this.config = config;
10
+ this.cryptoCore = new EciesCryptoCore(config);
11
+ this.engine = engine;
12
+ }
13
+ /**
14
+ * Get the size of the header for a given encryption type
15
+ * @param encryptionType The encryption type (single, simple, etc.)
16
+ * @returns
17
+ */
18
+ getHeaderSize(encryptionType) {
19
+ switch (encryptionType) {
20
+ case 'simple':
21
+ return ECIES.SIMPLE.FIXED_OVERHEAD_SIZE;
22
+ case 'single':
23
+ return ECIES.SINGLE.FIXED_OVERHEAD_SIZE;
24
+ default:
25
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidEncryptionType, this.engine);
26
+ }
27
+ }
28
+ /**
29
+ * Encrypt a message with a public key
30
+ * @param encryptSimple Whether to simple encrypt (without crc, length)
31
+ * @param receiverPublicKey The public key of the receiver
32
+ * @param message The message to encrypt
33
+ * @param preamble Optional preamble to prepend to the encrypted message
34
+ * @param options Optional encryption options
35
+ * @param options.recipientCount The number of recipients for multiple encryption mode
36
+ * @returns The encrypted message
37
+ */
38
+ encrypt(encryptSimple, receiverPublicKey, message, preamble = Buffer.alloc(0)) {
39
+ const encryptionType = encryptSimple
40
+ ? 'simple'
41
+ : 'single';
42
+ const encryptionTypeBuffer = Buffer.alloc(1);
43
+ encryptionTypeBuffer.writeUint8(EciesEncryptionTypeMap[encryptionType]);
44
+ if (message.length > ECIES.MAX_RAW_DATA_SIZE) {
45
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidDataLength, this.engine, undefined, undefined, {
46
+ error: 'Message length exceeds maximum allowed size',
47
+ maxLength: String(UINT32_MAX),
48
+ messageLength: String(message.length),
49
+ });
50
+ }
51
+ // Generate ephemeral ECDH key pair
52
+ const ecdh = createECDH(this.config.curveName);
53
+ ecdh.generateKeys();
54
+ // Compute shared secret
55
+ let sharedSecret;
56
+ try {
57
+ // Make sure we normalize the receiver's public key
58
+ const normalizedReceiverPublicKey = this.cryptoCore.normalizePublicKey(receiverPublicKey);
59
+ // Ensure we're using the properly formatted public key (with 0x04 prefix)
60
+ // Our debugging shows only the full format with prefix works correctly
61
+ sharedSecret = ecdh.computeSecret(normalizedReceiverPublicKey);
62
+ }
63
+ catch (error) {
64
+ console.error('[ERROR][encrypt] Failed to compute shared secret:', error);
65
+ if (error instanceof Error) {
66
+ if ('code' in error &&
67
+ error.code === 'ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY') {
68
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidRecipientPublicKey, this.engine, undefined, undefined, {
69
+ nodeError: error.code,
70
+ });
71
+ }
72
+ throw new ECIESError(ECIESErrorTypeEnum.SecretComputationFailed, this.engine, undefined, undefined, {
73
+ error: error.message,
74
+ });
75
+ }
76
+ throw new ECIESError(ECIESErrorTypeEnum.SecretComputationFailed, this.engine);
77
+ }
78
+ // Get the ephemeral public key and ensure it has the 0x04 prefix
79
+ let ephemeralPublicKey = ecdh.getPublicKey();
80
+ if (ephemeralPublicKey.length === ECIES.RAW_PUBLIC_KEY_LENGTH) {
81
+ ephemeralPublicKey = Buffer.concat([
82
+ Buffer.from([ECIES.PUBLIC_KEY_MAGIC]),
83
+ ephemeralPublicKey,
84
+ ]);
85
+ }
86
+ // Generate random IV
87
+ const iv = randomBytes(ECIES.IV_SIZE);
88
+ // Get the key from the shared secret (always use first 32 bytes)
89
+ const symKey = sharedSecret.subarray(0, ECIES.SYMMETRIC.KEY_SIZE);
90
+ // Create cipher with the derived symmetric key
91
+ const cipher = createCipheriv(ECIES.SYMMETRIC_ALGORITHM_CONFIGURATION, symKey, iv);
92
+ // Ensure auto padding is enabled
93
+ cipher.setAutoPadding(true);
94
+ // Encrypt the message
95
+ let encrypted = cipher.update(message);
96
+ encrypted = Buffer.concat([encrypted, cipher.final()]);
97
+ // Get and explicitly set the authentication tag to max tag length for consistency
98
+ const authTag = cipher.getAuthTag();
99
+ // Add a length prefix to the encrypted data to ensure we can extract the exact number of bytes during decryption
100
+ const lengthBuffer = encryptionType === 'simple' ? Buffer.alloc(0) : Buffer.alloc(UINT64_SIZE);
101
+ if (encryptionType === 'single') {
102
+ lengthBuffer.writeBigUInt64BE(BigInt(encrypted.length));
103
+ }
104
+ // Format: [optional preamble] | type (1) | ephemeralPublicKey (65) | iv (16) | authTag (16) | length (8) | encryptedData
105
+ return Buffer.concat([
106
+ preamble,
107
+ encryptionTypeBuffer,
108
+ ephemeralPublicKey,
109
+ iv,
110
+ authTag,
111
+ lengthBuffer,
112
+ encrypted,
113
+ ]);
114
+ }
115
+ /**
116
+ * Parse the header from encrypted data
117
+ * @param encryptionType The type of encryption (single, simple, etc.) or undefined if not known
118
+ * @param data The encrypted data
119
+ * @param preambleSize The size of the preamble, if any
120
+ * @param options Optional parsing options
121
+ * @param options.dataLength The expected length of the data
122
+ * @returns The parsed header components
123
+ */
124
+ parseEncryptedMessage(encryptionType, data, preambleSize = 0, options) {
125
+ // read the encryption type from the first byte after the preamble
126
+ const actualEncryptionTypeEnum = ensureEciesEncryptionTypeEnum(data.readUInt8(preambleSize));
127
+ // if a type is provided, ensure it matches the actual type
128
+ if (encryptionType !== undefined &&
129
+ actualEncryptionTypeEnum !== encryptionType) {
130
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidEncryptionType, this.engine, undefined, undefined, {
131
+ expected: encryptionTypeToString(encryptionType),
132
+ actual: encryptionTypeToString(actualEncryptionTypeEnum),
133
+ });
134
+ }
135
+ if (actualEncryptionTypeEnum === EciesEncryptionTypeEnum.Multiple) {
136
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidEncryptionType, this.engine, undefined, undefined, {
137
+ expected: 'single or simple',
138
+ actual: encryptionTypeToString(actualEncryptionTypeEnum),
139
+ });
140
+ }
141
+ const includeLengthAndCrc = actualEncryptionTypeEnum === EciesEncryptionTypeEnum.Single;
142
+ // check for impossible message
143
+ if (data.length <
144
+ (includeLengthAndCrc
145
+ ? ECIES.SINGLE.FIXED_OVERHEAD_SIZE
146
+ : ECIES.SIMPLE.FIXED_OVERHEAD_SIZE)) {
147
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidEncryptedDataLength, this.engine, undefined, undefined, {
148
+ required: String(ECIES.SINGLE.FIXED_OVERHEAD_SIZE),
149
+ actual: String(data.length),
150
+ });
151
+ }
152
+ let offset = 0;
153
+ const preamble = data.subarray(0, preambleSize);
154
+ offset += preambleSize;
155
+ // skip the already-read encryption type
156
+ offset += 1;
157
+ // Extract components from the header
158
+ const ephemeralPublicKey = data.subarray(offset, offset + ECIES.PUBLIC_KEY_LENGTH);
159
+ offset += ECIES.PUBLIC_KEY_LENGTH;
160
+ // Make sure we normalize the ephemeral public key
161
+ const normalizedKey = this.cryptoCore.normalizePublicKey(ephemeralPublicKey);
162
+ const iv = data.subarray(offset, offset + ECIES.IV_SIZE);
163
+ offset += ECIES.IV_SIZE;
164
+ const authTag = data.subarray(offset, offset + ECIES.AUTH_TAG_SIZE);
165
+ offset += ECIES.AUTH_TAG_SIZE;
166
+ // Extract the length prefix (4 bytes) after the header components
167
+ const dataLengthBuffer = includeLengthAndCrc
168
+ ? data.subarray(offset, offset + ECIES.SINGLE.DATA_LENGTH_SIZE)
169
+ : Buffer.alloc(0);
170
+ if (includeLengthAndCrc) {
171
+ offset += ECIES.SINGLE.DATA_LENGTH_SIZE;
172
+ }
173
+ const dataLength = includeLengthAndCrc
174
+ ? Number(dataLengthBuffer.readBigUInt64BE(0))
175
+ : options?.dataLength ?? -1;
176
+ if (includeLengthAndCrc &&
177
+ options?.dataLength !== undefined &&
178
+ dataLength !== options.dataLength) {
179
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidEncryptedDataLength, this.engine, undefined, undefined, {
180
+ error: 'Encrypted data length mismatch',
181
+ expected: String(dataLength),
182
+ actual: String(options.dataLength),
183
+ });
184
+ }
185
+ // No CRC in Single encryption (AES-GCM provides authentication)
186
+ const encryptedData = dataLength > 0
187
+ ? data.subarray(offset, offset + dataLength)
188
+ : data.subarray(offset);
189
+ if (includeLengthAndCrc) {
190
+ offset += dataLength;
191
+ }
192
+ if (includeLengthAndCrc && encryptedData.length !== dataLength) {
193
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidEncryptedDataLength, this.engine, undefined, undefined, {
194
+ expected: String(dataLength),
195
+ actual: String(encryptedData.length),
196
+ });
197
+ }
198
+ const remainder = includeLengthAndCrc
199
+ ? data.subarray(offset)
200
+ : Buffer.alloc(0);
201
+ // No CRC validation needed (AES-GCM provides authentication)
202
+ // Validate all header components have the correct lengths
203
+ if (normalizedKey.length !== ECIES.PUBLIC_KEY_LENGTH) {
204
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidEphemeralPublicKey, this.engine, undefined, undefined, {
205
+ error: 'Ephemeral public key has incorrect length after normalization',
206
+ expected: String(ECIES.PUBLIC_KEY_LENGTH),
207
+ actual: String(normalizedKey.length),
208
+ });
209
+ }
210
+ if (iv.length !== ECIES.IV_SIZE) {
211
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidIVLength, this.engine, undefined, undefined, {
212
+ expected: String(ECIES.IV_SIZE),
213
+ actual: String(iv.length),
214
+ });
215
+ }
216
+ if (authTag.length !== ECIES.AUTH_TAG_SIZE) {
217
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidAuthTagLength, this.engine, undefined, undefined, {
218
+ expected: String(ECIES.AUTH_TAG_SIZE),
219
+ actual: String(authTag.length),
220
+ });
221
+ }
222
+ return {
223
+ header: {
224
+ encryptionType: actualEncryptionTypeEnum,
225
+ ephemeralPublicKey: normalizedKey,
226
+ iv,
227
+ authTag,
228
+ dataLength,
229
+ headerSize: includeLengthAndCrc
230
+ ? ECIES.SINGLE.FIXED_OVERHEAD_SIZE
231
+ : ECIES.SINGLE.FIXED_OVERHEAD_SIZE,
232
+ },
233
+ data: encryptedData,
234
+ remainder,
235
+ };
236
+ }
237
+ /**
238
+ * Decrypts data encrypted with ECIES using a header
239
+ * This method maintains backward compatibility with the original implementation
240
+ * by returning just the Buffer. For detailed information, use decryptSingleWithHeaderEx
241
+ * @param encryptionType The type of encryption (single, simple, etc.)
242
+ * @param privateKey The private key to decrypt the data
243
+ * @param encryptedData The data to decrypt
244
+ * @param preambleSize The size of the preamble, if any
245
+ * @param options Optional decryption options
246
+ * @param options.dataLength The expected length of the data
247
+ * @returns The decrypted data buffer
248
+ */
249
+ decryptWithHeader(encryptionType, privateKey, encryptedData, preambleSize = 0, options) {
250
+ const readEncryptionType = encryptedData.readUInt8(preambleSize);
251
+ const actualEncryptionTypeEnum = ensureEciesEncryptionTypeEnum(readEncryptionType);
252
+ if (encryptionType !== undefined &&
253
+ actualEncryptionTypeEnum !== encryptionType) {
254
+ const expectedType = encryptionTypeEnumToType(encryptionType);
255
+ const actualEncryptionType = encryptionTypeEnumToType(actualEncryptionTypeEnum);
256
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidEncryptionType, this.engine, undefined, undefined, {
257
+ expected: expectedType,
258
+ actual: actualEncryptionType,
259
+ });
260
+ }
261
+ try {
262
+ // Call the extended version and return only the decrypted buffer for backward compatibility
263
+ const result = this.decryptWithHeaderEx(actualEncryptionTypeEnum, privateKey, encryptedData, preambleSize, options);
264
+ return result.decrypted;
265
+ }
266
+ catch (error) {
267
+ if (error instanceof ECIESError) {
268
+ throw error;
269
+ }
270
+ throw new ECIESError(ECIESErrorTypeEnum.DecryptionFailed, this.engine, undefined, undefined, {
271
+ error: error instanceof Error ? error.message : String(error),
272
+ });
273
+ }
274
+ }
275
+ /**
276
+ * Extended version of decryptSingleWithHeader that provides more detailed information
277
+ * @param encryptionType The type of encryption (single, simple, etc.)
278
+ * @param privateKey The private key to decrypt the data
279
+ * @param encryptedData The data to decrypt
280
+ * @param preambleSize The size of the preamble, if any
281
+ * @param options Optional decryption options
282
+ * @param options.dataLength The expected length of the data
283
+ * @returns The decrypted data and the number of bytes consumed from the input buffer
284
+ */
285
+ decryptWithHeaderEx(encryptionType, privateKey, encryptedData, preambleSize = 0, options) {
286
+ try {
287
+ const { data, header } = this.parseEncryptedMessage(encryptionType, encryptedData, preambleSize, options);
288
+ // Normalize the public key (ensuring 0x04 prefix)
289
+ const normalizedKey = this.cryptoCore.normalizePublicKey(header.ephemeralPublicKey);
290
+ // Decrypt using components with the normalized key
291
+ const decrypted = this.decryptWithComponents(privateKey, normalizedKey, header.iv, header.authTag, data);
292
+ return {
293
+ decrypted,
294
+ consumedBytes: header.dataLength + header.headerSize,
295
+ };
296
+ }
297
+ catch (error) {
298
+ if (error instanceof ECIESError) {
299
+ throw error;
300
+ }
301
+ throw new ECIESError(ECIESErrorTypeEnum.DecryptionFailed, this.engine, undefined, undefined, {
302
+ error: error instanceof Error ? error.message : String(error),
303
+ });
304
+ }
305
+ }
306
+ /**
307
+ * Decrypts data encrypted with ECIES using components
308
+ * @param privateKey The private key to decrypt the data
309
+ * @param ephemeralPublicKey The ephemeral public key used to encrypt the data
310
+ * @param iv The initialization vector used to encrypt the data
311
+ * @param authTag The authentication tag used to encrypt the data
312
+ * @param encrypted The encrypted data
313
+ * @returns The decrypted data
314
+ */
315
+ decryptWithComponents(privateKey, ephemeralPublicKey, iv, authTag, encrypted) {
316
+ try {
317
+ // Ensure the ephemeral public key has the correct format
318
+ const normalizedEphemeralKey = this.cryptoCore.normalizePublicKey(ephemeralPublicKey);
319
+ // Set up ECDH with the private key
320
+ const ecdh = createECDH(this.config.curveName);
321
+ ecdh.setPrivateKey(privateKey);
322
+ // Based on our ECDH test, we need to consistently use the full key with 0x04 prefix
323
+ // Our debugging showed the raw keys without prefix always fail
324
+ let sharedSecret;
325
+ try {
326
+ sharedSecret = ecdh.computeSecret(normalizedEphemeralKey);
327
+ }
328
+ catch (err) {
329
+ console.error('[ERROR][decrypt] Failed to compute shared secret:', err);
330
+ throw new ECIESError(ECIESErrorTypeEnum.DecryptionFailed, this.engine, undefined, undefined, {
331
+ originalError: err instanceof Error ? err.message : String(err),
332
+ stage: 'shared_secret_computation',
333
+ });
334
+ }
335
+ // Get the key from the shared secret (always use first 32 bytes)
336
+ const symKey = sharedSecret.subarray(0, ECIES.SYMMETRIC.KEY_SIZE);
337
+ // Create decipher with shared secret-derived key
338
+ const decipher = createDecipheriv(ECIES.SYMMETRIC_ALGORITHM_CONFIGURATION, symKey, iv);
339
+ // Validate the tag and IV
340
+ if (authTag.length !== ECIES.AUTH_TAG_SIZE) {
341
+ throw new ECIESError(ECIESErrorTypeEnum.DecryptionFailed, this.engine, undefined, undefined, {
342
+ expected: String(ECIES.AUTH_TAG_SIZE),
343
+ actual: String(authTag.length),
344
+ stage: 'auth_tag_validation',
345
+ });
346
+ }
347
+ if (iv.length !== ECIES.IV_SIZE) {
348
+ throw new ECIESError(ECIESErrorTypeEnum.DecryptionFailed, this.engine, undefined, undefined, {
349
+ expected: String(ECIES.IV_SIZE),
350
+ actual: String(iv.length),
351
+ stage: 'iv_validation',
352
+ });
353
+ }
354
+ // Set the authentication tag for GCM mode
355
+ decipher.setAuthTag(authTag);
356
+ // Decrypt the data
357
+ try {
358
+ // Handle edge case where encrypted data might be empty or malformed
359
+ if (encrypted.length === 0) {
360
+ throw new Error('Encrypted data is empty');
361
+ }
362
+ const firstPart = decipher.update(encrypted);
363
+ const finalPart = decipher.final();
364
+ const result = Buffer.concat([firstPart, finalPart]);
365
+ return result;
366
+ }
367
+ catch (err) {
368
+ throw new ECIESError(ECIESErrorTypeEnum.DecryptionFailed, this.engine, undefined, undefined, {
369
+ error: err instanceof Error ? err.message : String(err),
370
+ stage: 'decipher_operation',
371
+ });
372
+ }
373
+ }
374
+ catch (error) {
375
+ if (error instanceof ECIESError) {
376
+ throw error;
377
+ }
378
+ // Wrap non-EciesError in an EciesError
379
+ throw new ECIESError(ECIESErrorTypeEnum.DecryptionFailed, this.engine, undefined, undefined, {
380
+ error: error instanceof Error ? error.message : String(error),
381
+ privateKeyLength: String(privateKey.length),
382
+ ephemeralPublicKeyLength: String(ephemeralPublicKey.length),
383
+ ivLength: String(iv.length),
384
+ authTagLength: String(authTag.length),
385
+ encryptedLength: String(encrypted.length),
386
+ });
387
+ }
388
+ }
389
+ }
390
+ //# sourceMappingURL=single-recipient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"single-recipient.js","sourceRoot":"","sources":["../../../src/services/ecies/single-recipient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAEL,uBAAuB,EACvB,sBAAsB,EACtB,UAAU,EACV,kBAAkB,EAElB,wBAAwB,EACxB,sBAAsB,EACtB,6BAA6B,EAE7B,UAAU,EACV,WAAW,GACZ,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,WAAW,GACZ,MAAM,QAAQ,CAAC;AAIhB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,OAAO,wBAAwB;IAChB,UAAU,CAAkB;IAC5B,MAAM,CAAe;IACrB,MAAM,CAAiD;IAE1E,YACE,MAAoB,EACpB,MAAsD;QAEtD,IAAI,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AAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC7D,gBAAgB,EAAE,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC;gBAC3C,wBAAwB,EAAE,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC;gBAC3D,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC;gBAC3B,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;gBACrC,eAAe,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;aAC1C,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ import { EciesEncryptionType } from '@digitaldefiance/ecies-lib';
2
+ /**
3
+ * Utility functions for ECIES operations
4
+ */
5
+ export declare class EciesUtilities {
6
+ /**
7
+ * Computes the encrypted length from the data length.
8
+ * @param dataLength - The length of the data.
9
+ * @param encryptionMode - The encryption mode (simple, single, multiple).
10
+ * @param recipientCount - The number of recipients for multiple encryption mode.
11
+ * @returns The encrypted length details.
12
+ */
13
+ computeEncryptedLengthFromDataLength(dataLength: number, encryptionMode: EciesEncryptionType, recipientCount?: number): number;
14
+ /**
15
+ * Computes the decrypted length from the encrypted data length.
16
+ * @param encryptedDataLength - The length of the encrypted data.
17
+ * @param padding - Optional padding value.
18
+ * @returns The decrypted length.
19
+ */
20
+ computeDecryptedLengthFromEncryptedDataLength(encryptedDataLength: number, padding?: number): number;
21
+ }
22
+ //# sourceMappingURL=utilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../../src/services/ecies/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,mBAAmB,EAKpB,MAAM,4BAA4B,CAAC;AAGpC;;GAEG;AACH,qBAAa,cAAc;IACzB;;;;;;OAMG;IACI,oCAAoC,CACzC,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,mBAAmB,EACnC,cAAc,CAAC,EAAE,MAAM,GACtB,MAAM;IA0CT;;;;;OAKG;IACI,6CAA6C,CAClD,mBAAmB,EAAE,MAAM,EAC3B,OAAO,CAAC,EAAE,MAAM,GACf,MAAM;CA6BV"}
@@ -0,0 +1,65 @@
1
+ import { Constants as AppConstants, ECIES, ECIESError, ECIESErrorTypeEnum, getEciesI18nEngine, } from '@digitaldefiance/ecies-lib';
2
+ import { ECIESService } from './service';
3
+ /**
4
+ * Utility functions for ECIES operations
5
+ */
6
+ export class EciesUtilities {
7
+ /**
8
+ * Computes the encrypted length from the data length.
9
+ * @param dataLength - The length of the data.
10
+ * @param encryptionMode - The encryption mode (simple, single, multiple).
11
+ * @param recipientCount - The number of recipients for multiple encryption mode.
12
+ * @returns The encrypted length details.
13
+ */
14
+ computeEncryptedLengthFromDataLength(dataLength, encryptionMode, recipientCount) {
15
+ if (dataLength < 0) {
16
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidDataLength, getEciesI18nEngine());
17
+ }
18
+ const config = {
19
+ curveName: AppConstants.ECIES.CURVE_NAME,
20
+ primaryKeyDerivationPath: AppConstants.ECIES.PRIMARY_KEY_DERIVATION_PATH,
21
+ mnemonicStrength: AppConstants.ECIES.MNEMONIC_STRENGTH,
22
+ symmetricAlgorithm: AppConstants.ECIES.SYMMETRIC_ALGORITHM_CONFIGURATION,
23
+ symmetricKeyBits: AppConstants.ECIES.SYMMETRIC.KEY_BITS,
24
+ symmetricKeyMode: AppConstants.ECIES.SYMMETRIC.MODE,
25
+ };
26
+ const eciesService = new ECIESService(getEciesI18nEngine(), config);
27
+ switch (encryptionMode) {
28
+ case 'simple':
29
+ // type (1) + public key (65) + IV (16) + auth tag (16) = 98
30
+ return dataLength + ECIES.SIMPLE.FIXED_OVERHEAD_SIZE;
31
+ case 'single':
32
+ // type (1) + public key (65) + IV (16) + auth tag (16) + data length (4) + crc16 (2) = 104
33
+ return dataLength + ECIES.SINGLE.FIXED_OVERHEAD_SIZE;
34
+ case 'multiple':
35
+ return (dataLength +
36
+ eciesService.calculateECIESMultipleRecipientOverhead(recipientCount ?? 1, true));
37
+ default:
38
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidEncryptionType, getEciesI18nEngine());
39
+ }
40
+ }
41
+ /**
42
+ * Computes the decrypted length from the encrypted data length.
43
+ * @param encryptedDataLength - The length of the encrypted data.
44
+ * @param padding - Optional padding value.
45
+ * @returns The decrypted length.
46
+ */
47
+ computeDecryptedLengthFromEncryptedDataLength(encryptedDataLength, padding) {
48
+ if (encryptedDataLength < 0) {
49
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidEncryptedDataLength, getEciesI18nEngine());
50
+ }
51
+ const overhead = ECIES.SINGLE.FIXED_OVERHEAD_SIZE;
52
+ const actualPadding = padding !== undefined ? padding : 0;
53
+ const decryptedLength = encryptedDataLength - overhead - actualPadding;
54
+ if (decryptedLength < 0) {
55
+ throw new ECIESError(ECIESErrorTypeEnum.InvalidEncryptedDataLength, getEciesI18nEngine(), undefined, undefined, {
56
+ encryptedDataLength: String(encryptedDataLength),
57
+ overhead: String(overhead),
58
+ padding: String(actualPadding),
59
+ computedLength: String(decryptedLength),
60
+ });
61
+ }
62
+ return decryptedLength;
63
+ }
64
+ }
65
+ //# sourceMappingURL=utilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../../../src/services/ecies/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,IAAI,YAAY,EACzB,KAAK,EAEL,UAAU,EACV,kBAAkB,EAClB,kBAAkB,GAEnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,cAAc;IACzB;;;;;;OAMG;IACI,oCAAoC,CACzC,UAAkB,EAClB,cAAmC,EACnC,cAAuB;QAEvB,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;YACnB,MAAM,IAAI,UAAU,CAClB,kBA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,CAAC;QAClD,MAAM,aAAa,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAE1D,MAAM,eAAe,GAAG,mBAAmB,GAAG,QAAQ,GAAG,aAAa,CAAC;QACvE,IAAI,eAAe,GAAG,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,UAAU,CAClB,kBAAkB,CAAC,0BAA0B,EAC7C,kBAAkB,EAAE,EACpB,SAAS,EACT,SAAS,EACT;gBACE,mBAAmB,EAAE,MAAM,CAAC,mBAAmB,CAAC;gBAChD,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;gBAC1B,OAAO,EAAE,MAAM,CAAC,aAAa,CAAC;gBAC9B,cAAc,EAAE,MAAM,CAAC,eAAe,CAAC;aACxC,CACF,CAAC;QACJ,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export * from './ecies';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './ecies';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { HexString } from '@digitaldefiance/ecies-lib';
2
+ import { Brand } from 'ts-brand';
3
+ import { IKeyPairBufferWithUnEncryptedPrivateKey } from './interfaces/keypair-buffer-with-un-encrypted-private-key';
4
+ import { ISigningKeyPrivateKeyInfo } from './interfaces/signing-key-private-key-info';
5
+ import { ISimpleKeyPairBuffer } from './interfaces/simple-keypair-buffer';
6
+ import { ISimplePublicKeyOnly } from './interfaces/simple-public-key-only';
7
+ import { ISimplePublicKeyOnlyBuffer } from './interfaces/simple-public-key-only-buffer';
8
+ export type KeyPairBufferWithUnEncryptedPrivateKey = Brand<IKeyPairBufferWithUnEncryptedPrivateKey, 'KeyPairBufferWithUnEncryptedPrivateKey'>;
9
+ export type SigningKeyPrivateKeyInfo = Brand<ISigningKeyPrivateKeyInfo, 'SigningKeyPrivateKeyInfo'>;
10
+ export type SimpleKeyPair = Brand<SimplePublicKeyOnly, 'SimpleKeyPair'>;
11
+ export type SimplePublicKeyOnly = Brand<ISimplePublicKeyOnly, 'SimplePublicKeyOnly'>;
12
+ export type SimpleKeyPairBuffer = Brand<ISimpleKeyPairBuffer, 'SimpleKeyPairBuffer'>;
13
+ export type SimplePublicKeyOnlyBuffer = Brand<ISimplePublicKeyOnlyBuffer, 'SimplePublicKeyOnlyBuffer'>;
14
+ export type SignatureString = Brand<HexString, 'SignatureString'>;
15
+ export type SignatureBuffer = Buffer & Brand<Buffer, 'SignatureBuffer'>;
16
+ export type ChecksumBuffer = Buffer & Brand<Buffer, 'Sha3Checksum', 'ChecksumBuffer'>;
17
+ export type ChecksumString = Brand<HexString, 'Sha3Checksum', 'ChecksumString'>;
18
+ /**
19
+ * Extended Buffer type for data
20
+ */
21
+ export type DataBuffer = Buffer & {
22
+ toBuffer(): Buffer;
23
+ toHex(): string;
24
+ };
25
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,uCAAuC,EAAE,MAAM,2DAA2D,CAAC;AACpH,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AAExF,MAAM,MAAM,sCAAsC,GAAG,KAAK,CACxD,uCAAuC,EACvC,wCAAwC,CACzC,CAAC;AACF,MAAM,MAAM,wBAAwB,GAAG,KAAK,CAC1C,yBAAyB,EACzB,0BAA0B,CAC3B,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAC;AACxE,MAAM,MAAM,mBAAmB,GAAG,KAAK,CACrC,oBAAoB,EACpB,qBAAqB,CACtB,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG,KAAK,CACrC,oBAAoB,EACpB,qBAAqB,CACtB,CAAC;AACF,MAAM,MAAM,yBAAyB,GAAG,KAAK,CAC3C,0BAA0B,EAC1B,2BAA2B,CAC5B,CAAC;AACF,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;AAClE,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AACxE,MAAM,MAAM,cAAc,GAAG,MAAM,GACjC,KAAK,CAAC,MAAM,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAC;AAClD,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,SAAS,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IAChC,QAAQ,IAAI,MAAM,CAAC;IACnB,KAAK,IAAI,MAAM,CAAC;CACjB,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@digitaldefiance/node-ecies-lib",
3
+ "version": "1.0.0",
4
+ "description": "Digital Defiance Node ECIES Library",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "yarn tsc",
9
+ "test": "node --experimental-vm-modules node_modules/.bin/jest",
10
+ "lint": "eslint src/**/*.ts",
11
+ "lint:fix": "eslint src/**/*.ts --fix",
12
+ "prettier:check": "prettier --check 'src/**/*.{ts,tsx}'",
13
+ "prettier:fix": "prettier --write 'src/**/*.{ts,tsx}'",
14
+ "format": "yarn prettier:fix && yarn lint:fix",
15
+ "prepublishOnly": "yarn build",
16
+ "publish:public": "npm publish --access public"
17
+ },
18
+ "devDependencies": {
19
+ "@babel/core": "^7.28.4",
20
+ "@babel/preset-env": "^7.28.3",
21
+ "@babel/preset-typescript": "^7.27.1",
22
+ "@types/babel__core": "^7",
23
+ "@types/babel__preset-env": "^7",
24
+ "@types/jest": "^29.0.0",
25
+ "@typescript-eslint/eslint-plugin": "^8.31.1",
26
+ "@typescript-eslint/parser": "^8.31.1",
27
+ "babel-jest": "^30.1.2",
28
+ "eslint": "^9.8.0",
29
+ "eslint-config-prettier": "^10.1.2",
30
+ "eslint-plugin-import": "^2.32.0",
31
+ "eslint-plugin-prettier": "^5.3.1",
32
+ "jest": "^29.0.0",
33
+ "jest-resolver-enhanced": "^1.1.0",
34
+ "jest-util": "^30.0.5",
35
+ "prettier": "^2.6.2",
36
+ "prettier-plugin-organize-imports": "^4.1.0",
37
+ "ts-jest": "^29.0.0",
38
+ "typescript": "^5.9.2"
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "README.md"
43
+ ],
44
+ "keywords": [
45
+ "ecies",
46
+ "encryption",
47
+ "decryption",
48
+ "typescript"
49
+ ],
50
+ "author": "Digital Defiance",
51
+ "license": "MIT",
52
+ "type": "module",
53
+ "packageManager": "yarn@4.10.3",
54
+ "dependencies": {
55
+ "@digitaldefiance/ecies-lib": "^1.0.18",
56
+ "@digitaldefiance/i18n-lib": "^1.0.33",
57
+ "@ethereumjs/wallet": "^10.0.0",
58
+ "@noble/curves": "^2.0.1",
59
+ "@noble/hashes": "^2.0.1",
60
+ "@scure/bip32": "^2.0.0",
61
+ "bson": "^6.10.4",
62
+ "ts-brand": "^0.2.0"
63
+ }
64
+ }