@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,399 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EciesSingleRecipientCore = void 0;
4
- const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
5
- const crypto_1 = require("crypto");
6
- const ecies_i18n_factory_1 = require("../../i18n/ecies-i18n-factory");
7
- const crypto_core_1 = require("./crypto-core");
8
- class EciesSingleRecipientCore {
9
- cryptoCore;
10
- config;
11
- engine;
12
- constructor(config, engine) {
13
- this.config = config;
14
- this.cryptoCore = new crypto_core_1.EciesCryptoCore(config);
15
- this.engine = engine || (0, ecies_i18n_factory_1.createEciesTranslationEngine)();
16
- }
17
- /**
18
- * Get the size of the header for a given encryption type
19
- * @param encryptionType The encryption type (single, simple, etc.)
20
- * @returns
21
- */
22
- getHeaderSize(encryptionType) {
23
- switch (encryptionType) {
24
- case 'simple':
25
- return this.cryptoCore.consts.SIMPLE.FIXED_OVERHEAD_SIZE;
26
- case 'single':
27
- return this.cryptoCore.consts.SINGLE.FIXED_OVERHEAD_SIZE;
28
- default:
29
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptionType, this.engine);
30
- }
31
- }
32
- /**
33
- * Encrypt a message with a public key
34
- * @param encryptSimple Whether to simple encrypt (without crc, length)
35
- * @param receiverPublicKey The public key of the receiver
36
- * @param message The message to encrypt
37
- * @param preamble Optional preamble to prepend to the encrypted message
38
- * @param options Optional encryption options
39
- * @param options.recipientCount The number of recipients for multiple encryption mode
40
- * @returns The encrypted message
41
- */
42
- encrypt(encryptSimple, receiverPublicKey, message, preamble = Buffer.alloc(0)) {
43
- const encryptionType = encryptSimple
44
- ? 'simple'
45
- : 'single';
46
- const encryptionTypeBuffer = Buffer.alloc(1);
47
- encryptionTypeBuffer.writeUint8(ecies_lib_1.EciesEncryptionTypeMap[encryptionType]);
48
- if (message.length > this.cryptoCore.consts.MAX_RAW_DATA_SIZE) {
49
- const pluginEngine = (0, ecies_i18n_factory_1.getEciesPluginI18nEngine)();
50
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength, this.engine, undefined, undefined, {
51
- error: pluginEngine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_MessageLengthExceedsMaximumAllowedSize),
52
- maxLength: String(ecies_lib_1.UINT32_MAX),
53
- messageLength: String(message.length),
54
- });
55
- }
56
- // Generate ephemeral ECDH key pair
57
- const ecdh = (0, crypto_1.createECDH)(this.config.curveName);
58
- ecdh.generateKeys();
59
- // Compute shared secret
60
- let sharedSecret;
61
- try {
62
- // Make sure we normalize the receiver's public key
63
- const normalizedReceiverPublicKey = this.cryptoCore.normalizePublicKey(receiverPublicKey);
64
- // Ensure we're using the properly formatted public key (with 0x04 prefix)
65
- // Our debugging shows only the full format with prefix works correctly
66
- sharedSecret = ecdh.computeSecret(normalizedReceiverPublicKey);
67
- }
68
- catch (error) {
69
- console.error('[ERROR][encrypt] Failed to compute shared secret:', error);
70
- if (error instanceof Error) {
71
- if ('code' in error &&
72
- error.code === 'ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY') {
73
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidRecipientPublicKey, this.engine, undefined, undefined, {
74
- nodeError: error.code,
75
- });
76
- }
77
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.SecretComputationFailed, this.engine, undefined, undefined, {
78
- error: error.message,
79
- });
80
- }
81
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.SecretComputationFailed, this.engine);
82
- }
83
- // Get the ephemeral public key and ensure it has the 0x04 prefix
84
- let ephemeralPublicKey = ecdh.getPublicKey();
85
- if (ephemeralPublicKey.length === this.cryptoCore.consts.RAW_PUBLIC_KEY_LENGTH) {
86
- ephemeralPublicKey = Buffer.concat([
87
- Buffer.from([this.cryptoCore.consts.PUBLIC_KEY_MAGIC]),
88
- ephemeralPublicKey,
89
- ]);
90
- }
91
- // Generate random IV
92
- const iv = (0, crypto_1.randomBytes)(this.cryptoCore.consts.IV_SIZE);
93
- // Get the key from the shared secret (always use first 32 bytes)
94
- const symKey = sharedSecret.subarray(0, this.cryptoCore.consts.SYMMETRIC.KEY_SIZE);
95
- // Create cipher with the derived symmetric key
96
- const cipher = (0, crypto_1.createCipheriv)(this.cryptoCore.consts.SYMMETRIC_ALGORITHM_CONFIGURATION, symKey, iv);
97
- // Ensure auto padding is enabled
98
- cipher.setAutoPadding(true);
99
- // Encrypt the message
100
- let encrypted = cipher.update(message);
101
- encrypted = Buffer.concat([encrypted, cipher.final()]);
102
- // Get and explicitly set the authentication tag to max tag length for consistency
103
- const authTag = cipher.getAuthTag();
104
- // Add a length prefix to the encrypted data to ensure we can extract the exact number of bytes during decryption
105
- const lengthBuffer = encryptionType === 'simple' ? Buffer.alloc(0) : Buffer.alloc(ecies_lib_1.UINT64_SIZE);
106
- if (encryptionType === 'single') {
107
- lengthBuffer.writeBigUInt64BE(BigInt(encrypted.length));
108
- }
109
- // Format: [optional preamble] | type (1) | ephemeralPublicKey (65) | iv (16) | authTag (16) | length (8) | encryptedData
110
- return Buffer.concat([
111
- preamble,
112
- encryptionTypeBuffer,
113
- ephemeralPublicKey,
114
- iv,
115
- authTag,
116
- lengthBuffer,
117
- encrypted,
118
- ]);
119
- }
120
- /**
121
- * Parse the header from encrypted data
122
- * @param encryptionType The type of encryption (single, simple, etc.) or undefined if not known
123
- * @param data The encrypted data
124
- * @param preambleSize The size of the preamble, if any
125
- * @param options Optional parsing options
126
- * @param options.dataLength The expected length of the data
127
- * @returns The parsed header components
128
- */
129
- parseEncryptedMessage(encryptionType, data, preambleSize = 0, options) {
130
- // read the encryption type from the first byte after the preamble
131
- const actualEncryptionTypeEnum = (0, ecies_lib_1.ensureEciesEncryptionTypeEnum)(data.readUInt8(preambleSize));
132
- // if a type is provided, ensure it matches the actual type
133
- if (encryptionType !== undefined &&
134
- actualEncryptionTypeEnum !== encryptionType) {
135
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptionType, this.engine, undefined, undefined, {
136
- expected: (0, ecies_lib_1.encryptionTypeToString)(encryptionType),
137
- actual: (0, ecies_lib_1.encryptionTypeToString)(actualEncryptionTypeEnum),
138
- });
139
- }
140
- if (actualEncryptionTypeEnum === ecies_lib_1.EciesEncryptionTypeEnum.Multiple) {
141
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptionType, this.engine, undefined, undefined, {
142
- expected: 'single or simple',
143
- actual: (0, ecies_lib_1.encryptionTypeToString)(actualEncryptionTypeEnum),
144
- });
145
- }
146
- const includeLengthAndCrc = actualEncryptionTypeEnum === ecies_lib_1.EciesEncryptionTypeEnum.Single;
147
- // check for impossible message
148
- if (data.length <
149
- (includeLengthAndCrc
150
- ? this.cryptoCore.consts.SINGLE.FIXED_OVERHEAD_SIZE
151
- : this.cryptoCore.consts.SIMPLE.FIXED_OVERHEAD_SIZE)) {
152
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptedDataLength, this.engine, undefined, undefined, {
153
- required: String(this.cryptoCore.consts.SINGLE.FIXED_OVERHEAD_SIZE),
154
- actual: String(data.length),
155
- });
156
- }
157
- let offset = 0;
158
- const preamble = data.subarray(0, preambleSize);
159
- offset += preambleSize;
160
- // skip the already-read encryption type
161
- offset += 1;
162
- // Extract components from the header
163
- const ephemeralPublicKey = data.subarray(offset, offset + this.cryptoCore.consts.PUBLIC_KEY_LENGTH);
164
- offset += this.cryptoCore.consts.PUBLIC_KEY_LENGTH;
165
- // Make sure we normalize the ephemeral public key
166
- const normalizedKey = this.cryptoCore.normalizePublicKey(ephemeralPublicKey);
167
- const iv = data.subarray(offset, offset + this.cryptoCore.consts.IV_SIZE);
168
- offset += this.cryptoCore.consts.IV_SIZE;
169
- const authTag = data.subarray(offset, offset + this.cryptoCore.consts.AUTH_TAG_SIZE);
170
- offset += this.cryptoCore.consts.AUTH_TAG_SIZE;
171
- // Extract the length prefix (4 bytes) after the header components
172
- const dataLengthBuffer = includeLengthAndCrc
173
- ? data.subarray(offset, offset + this.cryptoCore.consts.SINGLE.DATA_LENGTH_SIZE)
174
- : Buffer.alloc(0);
175
- if (includeLengthAndCrc) {
176
- offset += this.cryptoCore.consts.SINGLE.DATA_LENGTH_SIZE;
177
- }
178
- const dataLength = includeLengthAndCrc
179
- ? Number(dataLengthBuffer.readBigUInt64BE(0))
180
- : options?.dataLength ?? -1;
181
- if (includeLengthAndCrc &&
182
- options?.dataLength !== undefined &&
183
- dataLength !== options.dataLength) {
184
- const pluginEngine = (0, ecies_i18n_factory_1.getEciesPluginI18nEngine)();
185
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptedDataLength, this.engine, undefined, undefined, {
186
- error: pluginEngine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_EncryptedDataLengthMismatch),
187
- expected: String(dataLength),
188
- actual: String(options.dataLength),
189
- });
190
- }
191
- // No CRC in Single encryption (AES-GCM provides authentication)
192
- const encryptedData = dataLength > 0
193
- ? data.subarray(offset, offset + dataLength)
194
- : data.subarray(offset);
195
- if (includeLengthAndCrc) {
196
- offset += dataLength;
197
- }
198
- if (includeLengthAndCrc && encryptedData.length !== dataLength) {
199
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptedDataLength, this.engine, undefined, undefined, {
200
- expected: String(dataLength),
201
- actual: String(encryptedData.length),
202
- });
203
- }
204
- const remainder = includeLengthAndCrc
205
- ? data.subarray(offset)
206
- : Buffer.alloc(0);
207
- // No CRC validation needed (AES-GCM provides authentication)
208
- // Validate all header components have the correct lengths
209
- if (normalizedKey.length !== this.cryptoCore.consts.PUBLIC_KEY_LENGTH) {
210
- const pluginEngine = (0, ecies_i18n_factory_1.getEciesPluginI18nEngine)();
211
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEphemeralPublicKey, this.engine, undefined, undefined, {
212
- error: pluginEngine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_EphemeralPublicKeyLengthMismatch),
213
- expected: String(this.cryptoCore.consts.PUBLIC_KEY_LENGTH),
214
- actual: String(normalizedKey.length),
215
- });
216
- }
217
- if (iv.length !== this.cryptoCore.consts.IV_SIZE) {
218
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidIVLength, this.engine, undefined, undefined, {
219
- expected: String(this.cryptoCore.consts.IV_SIZE),
220
- actual: String(iv.length),
221
- });
222
- }
223
- if (authTag.length !== this.cryptoCore.consts.AUTH_TAG_SIZE) {
224
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidAuthTagLength, this.engine, undefined, undefined, {
225
- expected: String(this.cryptoCore.consts.AUTH_TAG_SIZE),
226
- actual: String(authTag.length),
227
- });
228
- }
229
- return {
230
- header: {
231
- encryptionType: actualEncryptionTypeEnum,
232
- ephemeralPublicKey: normalizedKey,
233
- iv,
234
- authTag,
235
- dataLength,
236
- headerSize: includeLengthAndCrc
237
- ? this.cryptoCore.consts.SINGLE.FIXED_OVERHEAD_SIZE
238
- : this.cryptoCore.consts.SINGLE.FIXED_OVERHEAD_SIZE,
239
- },
240
- data: encryptedData,
241
- remainder,
242
- };
243
- }
244
- /**
245
- * Decrypts data encrypted with ECIES using a header
246
- * This method maintains backward compatibility with the original implementation
247
- * by returning just the Buffer. For detailed information, use decryptSingleWithHeaderEx
248
- * @param encryptionType The type of encryption (single, simple, etc.)
249
- * @param privateKey The private key to decrypt the data
250
- * @param encryptedData The data to decrypt
251
- * @param preambleSize The size of the preamble, if any
252
- * @param options Optional decryption options
253
- * @param options.dataLength The expected length of the data
254
- * @returns The decrypted data buffer
255
- */
256
- decryptWithHeader(encryptionType, privateKey, encryptedData, preambleSize = 0, options) {
257
- const readEncryptionType = encryptedData.readUInt8(preambleSize);
258
- const actualEncryptionTypeEnum = (0, ecies_lib_1.ensureEciesEncryptionTypeEnum)(readEncryptionType);
259
- if (encryptionType !== undefined &&
260
- actualEncryptionTypeEnum !== encryptionType) {
261
- const expectedType = (0, ecies_lib_1.encryptionTypeEnumToType)(encryptionType);
262
- const actualEncryptionType = (0, ecies_lib_1.encryptionTypeEnumToType)(actualEncryptionTypeEnum);
263
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptionType, this.engine, undefined, undefined, {
264
- expected: expectedType,
265
- actual: actualEncryptionType,
266
- });
267
- }
268
- try {
269
- // Call the extended version and return only the decrypted buffer for backward compatibility
270
- const result = this.decryptWithHeaderEx(actualEncryptionTypeEnum, privateKey, encryptedData, preambleSize, options);
271
- return result.decrypted;
272
- }
273
- catch (error) {
274
- if (error instanceof ecies_lib_1.ECIESError) {
275
- throw error;
276
- }
277
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.DecryptionFailed, this.engine, undefined, undefined, {
278
- error: error instanceof Error ? error.message : String(error),
279
- });
280
- }
281
- }
282
- /**
283
- * Extended version of decryptSingleWithHeader that provides more detailed information
284
- * @param encryptionType The type of encryption (single, simple, etc.)
285
- * @param privateKey The private key to decrypt the data
286
- * @param encryptedData The data to decrypt
287
- * @param preambleSize The size of the preamble, if any
288
- * @param options Optional decryption options
289
- * @param options.dataLength The expected length of the data
290
- * @returns The decrypted data and the number of bytes consumed from the input buffer
291
- */
292
- decryptWithHeaderEx(encryptionType, privateKey, encryptedData, preambleSize = 0, options) {
293
- try {
294
- const { data, header } = this.parseEncryptedMessage(encryptionType, encryptedData, preambleSize, options);
295
- // Normalize the public key (ensuring 0x04 prefix)
296
- const normalizedKey = this.cryptoCore.normalizePublicKey(header.ephemeralPublicKey);
297
- // Decrypt using components with the normalized key
298
- const decrypted = this.decryptWithComponents(privateKey, normalizedKey, header.iv, header.authTag, data);
299
- return {
300
- decrypted,
301
- consumedBytes: header.dataLength + header.headerSize,
302
- };
303
- }
304
- catch (error) {
305
- if (error instanceof ecies_lib_1.ECIESError) {
306
- throw error;
307
- }
308
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.DecryptionFailed, this.engine, undefined, undefined, {
309
- error: error instanceof Error ? error.message : String(error),
310
- });
311
- }
312
- }
313
- /**
314
- * Decrypts data encrypted with ECIES using components
315
- * @param privateKey The private key to decrypt the data
316
- * @param ephemeralPublicKey The ephemeral public key used to encrypt the data
317
- * @param iv The initialization vector used to encrypt the data
318
- * @param authTag The authentication tag used to encrypt the data
319
- * @param encrypted The encrypted data
320
- * @returns The decrypted data
321
- */
322
- decryptWithComponents(privateKey, ephemeralPublicKey, iv, authTag, encrypted) {
323
- try {
324
- // Ensure the ephemeral public key has the correct format
325
- const normalizedEphemeralKey = this.cryptoCore.normalizePublicKey(ephemeralPublicKey);
326
- // Set up ECDH with the private key
327
- const ecdh = (0, crypto_1.createECDH)(this.config.curveName);
328
- ecdh.setPrivateKey(privateKey);
329
- // Based on our ECDH test, we need to consistently use the full key with 0x04 prefix
330
- // Our debugging showed the raw keys without prefix always fail
331
- let sharedSecret;
332
- try {
333
- sharedSecret = ecdh.computeSecret(normalizedEphemeralKey);
334
- }
335
- catch (err) {
336
- console.error('[ERROR][decrypt] Failed to compute shared secret:', err);
337
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.DecryptionFailed, this.engine, undefined, undefined, {
338
- originalError: err instanceof Error ? err.message : String(err),
339
- stage: 'shared_secret_computation',
340
- });
341
- }
342
- // Get the key from the shared secret (always use first 32 bytes)
343
- const symKey = sharedSecret.subarray(0, this.cryptoCore.consts.SYMMETRIC.KEY_SIZE);
344
- // Create decipher with shared secret-derived key
345
- const decipher = (0, crypto_1.createDecipheriv)(this.cryptoCore.consts.SYMMETRIC_ALGORITHM_CONFIGURATION, symKey, iv);
346
- // Validate the tag and IV
347
- if (authTag.length !== this.cryptoCore.consts.AUTH_TAG_SIZE) {
348
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.DecryptionFailed, this.engine, undefined, undefined, {
349
- expected: String(this.cryptoCore.consts.AUTH_TAG_SIZE),
350
- actual: String(authTag.length),
351
- stage: 'auth_tag_validation',
352
- });
353
- }
354
- if (iv.length !== this.cryptoCore.consts.IV_SIZE) {
355
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.DecryptionFailed, this.engine, undefined, undefined, {
356
- expected: String(this.cryptoCore.consts.IV_SIZE),
357
- actual: String(iv.length),
358
- stage: 'iv_validation',
359
- });
360
- }
361
- // Set the authentication tag for GCM mode
362
- decipher.setAuthTag(authTag);
363
- // Decrypt the data
364
- try {
365
- // Handle edge case where encrypted data might be empty or malformed
366
- const pluginEngine = (0, ecies_i18n_factory_1.getEciesPluginI18nEngine)();
367
- if (encrypted.length === 0) {
368
- throw new Error(pluginEngine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_EncryptedDataIsEmpty));
369
- }
370
- const firstPart = decipher.update(encrypted);
371
- const finalPart = decipher.final();
372
- const result = Buffer.concat([firstPart, finalPart]);
373
- return result;
374
- }
375
- catch (err) {
376
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.DecryptionFailed, this.engine, undefined, undefined, {
377
- error: err instanceof Error ? err.message : String(err),
378
- stage: 'decipher_operation',
379
- });
380
- }
381
- }
382
- catch (error) {
383
- if (error instanceof ecies_lib_1.ECIESError) {
384
- throw error;
385
- }
386
- // Wrap non-EciesError in an EciesError
387
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.DecryptionFailed, this.engine, undefined, undefined, {
388
- error: error instanceof Error ? error.message : String(error),
389
- privateKeyLength: String(privateKey.length),
390
- ephemeralPublicKeyLength: String(ephemeralPublicKey.length),
391
- ivLength: String(iv.length),
392
- authTagLength: String(authTag.length),
393
- encryptedLength: String(encrypted.length),
394
- });
395
- }
396
- }
397
- }
398
- exports.EciesSingleRecipientCore = EciesSingleRecipientCore;
399
- //# sourceMappingURL=single-recipient.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"single-recipient.js","sourceRoot":"","sources":["../../../src/services/ecies/single-recipient.ts"],"names":[],"mappings":";;;AAAA,0DAaoC;AAGpC,mCAKgB;AAChB,sEAAiJ;AAIjJ,+CAAgD;AAEhD,MAAa,wBAAwB;IAChB,UAAU,CAAkB;IAC5B,MAAM,CAAe;IACrB,MAAM,CAAqC;IAE9D,YAAY,MAAoB,EAAE,MAA2C;QAC3E,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,IAAI,6BAAe,CAAC,MAAM,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAA,iDAA4B,GAAE,CAAC;IACzD,CAAC;IAED;;;;OAIG;IACI,aAAa,CAAC,cAAmC;QACtD,QAAQ,cAAc,EAAE,CAAC;YACvB,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC;YAC3D,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC;YAC3D;gBACE,MAAM,IAAI,sBAAU,CAClB,8BAAkB,CAAC,qBAAqB,EACxC,IAAI,CAAC,MAAM,CACZ,CAAC;QACN,CAAC;IACH,CAAC;IAED;;;;;;;;;OASG;IACI,OAAO,CACZ,aAAsB,EACtB,iBAAyB,EACzB,OAAe,EACf,W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/**
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../../src/services/ecies/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAIpB,MAAM,4BAA4B,CAAC;AAKpC;;GAEG;AACH,qBAAa,cAAc;IACzB;;;;;;OAMG;IACI,oCAAoC,CACzC,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,mBAAmB,EACnC,cAAc,CAAC,EAAE,MAAM,GACtB,MAAM;IA8CT;;;;;OAKG;IACI,6CAA6C,CAClD,mBAAmB,EAAE,MAAM,EAC3B,OAAO,CAAC,EAAE,MAAM,GACf,MAAM;CA8BV"}
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EciesUtilities = void 0;
4
- const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
5
- const ecies_i18n_factory_1 = require("../../i18n/ecies-i18n-factory");
6
- const service_1 = require("./service");
7
- const constants_1 = require("../../constants");
8
- /**
9
- * Utility functions for ECIES operations
10
- */
11
- class EciesUtilities {
12
- /**
13
- * Computes the encrypted length from the data length.
14
- * @param dataLength - The length of the data.
15
- * @param encryptionMode - The encryption mode (simple, single, multiple).
16
- * @param recipientCount - The number of recipients for multiple encryption mode.
17
- * @returns The encrypted length details.
18
- */
19
- computeEncryptedLengthFromDataLength(dataLength, encryptionMode, recipientCount) {
20
- if (dataLength < 0) {
21
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength, (0, ecies_i18n_factory_1.createEciesTranslationEngine)());
22
- }
23
- const runtimeDefaults = (0, constants_1.getNodeRuntimeConfiguration)();
24
- const eciesDefaults = runtimeDefaults.ECIES;
25
- const config = {
26
- curveName: eciesDefaults.CURVE_NAME,
27
- primaryKeyDerivationPath: eciesDefaults.PRIMARY_KEY_DERIVATION_PATH,
28
- mnemonicStrength: eciesDefaults.MNEMONIC_STRENGTH,
29
- symmetricAlgorithm: eciesDefaults.SYMMETRIC_ALGORITHM_CONFIGURATION,
30
- symmetricKeyBits: eciesDefaults.SYMMETRIC.KEY_BITS,
31
- symmetricKeyMode: eciesDefaults.SYMMETRIC.MODE,
32
- };
33
- const engine = (0, ecies_i18n_factory_1.createEciesTranslationEngine)();
34
- const eciesService = new service_1.ECIESService(engine, config, eciesDefaults);
35
- switch (encryptionMode) {
36
- case 'simple':
37
- // type (1) + public key (65) + IV (16) + auth tag (16) = 98
38
- return dataLength + eciesDefaults.SIMPLE.FIXED_OVERHEAD_SIZE;
39
- case 'single':
40
- // type (1) + public key (65) + IV (16) + auth tag (16) + data length (4) + crc16 (2) = 104
41
- return dataLength + eciesDefaults.SINGLE.FIXED_OVERHEAD_SIZE;
42
- case 'multiple':
43
- return (dataLength +
44
- eciesService.calculateECIESMultipleRecipientOverhead(recipientCount ?? 1, true));
45
- default:
46
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptionType, (0, ecies_i18n_factory_1.createEciesTranslationEngine)());
47
- }
48
- }
49
- /**
50
- * Computes the decrypted length from the encrypted data length.
51
- * @param encryptedDataLength - The length of the encrypted data.
52
- * @param padding - Optional padding value.
53
- * @returns The decrypted length.
54
- */
55
- computeDecryptedLengthFromEncryptedDataLength(encryptedDataLength, padding) {
56
- if (encryptedDataLength < 0) {
57
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptedDataLength, (0, ecies_i18n_factory_1.createEciesTranslationEngine)());
58
- }
59
- const { ECIES: eciesDefaults } = (0, constants_1.getNodeRuntimeConfiguration)();
60
- const overhead = eciesDefaults.SINGLE.FIXED_OVERHEAD_SIZE;
61
- const actualPadding = padding !== undefined ? padding : 0;
62
- const decryptedLength = encryptedDataLength - overhead - actualPadding;
63
- if (decryptedLength < 0) {
64
- throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptedDataLength, (0, ecies_i18n_factory_1.createEciesTranslationEngine)(), undefined, undefined, {
65
- encryptedDataLength: String(encryptedDataLength),
66
- overhead: String(overhead),
67
- padding: String(actualPadding),
68
- computedLength: String(decryptedLength),
69
- });
70
- }
71
- return decryptedLength;
72
- }
73
- }
74
- exports.EciesUtilities = EciesUtilities;
75
- //# sourceMappingURL=utilities.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../../../src/services/ecies/utilities.ts"],"names":[],"mappings":";;;AAAA,0DAKoC;AACpC,sEAA6E;AAC7E,uCAAyC;AACzC,+CAA8D;AAE9D;;GAEG;AACH,MAAa,cAAc;IACzB;;;;;;OAMG;IACI,oCAAoC,CACzC,UAAkB,EAClB,cAAmC,EACnC,cAAuB;QAEvB,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;YACnB,MAAM,IAAI,sBAAU,CAClB,8BAAkB,CAAC,iBAAiB,EACpC,IAAA,iDAA4B,GAAE,CAC/B,CAAC;QACJ,CAAC;QACD,MAAM,eAAe,GAAG,IAAA,uCAA2B,GAAE,CAAC;QACtD,MAAM,aAAa,GAAG,eAAe,CAAC,KAAK,CAAC;QAC5C,MAAM,MAAM,GAAiB;YAC3B,SAAS,EAAE,aAAa,CAAC,UAAU;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AS,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,sBAAU,CAClB,8BAAkB,CAAC,0BAA0B,EAC7C,IAAA,iDAA4B,GAAE,EAC9B,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;AAjGD,wCAiGC"}
@@ -1,4 +0,0 @@
1
- export * from './aes-gcm';
2
- export * from './ecies';
3
- export * from './pbkdf2';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./aes-gcm"), exports);
18
- __exportStar(require("./ecies"), exports);
19
- __exportStar(require("./pbkdf2"), exports);
20
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,0CAAwB;AACxB,2CAAyB"}