@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.
- package/README.md +4 -0
- package/package.json +6 -5
- package/src/constants.d.ts +32 -0
- package/src/constants.d.ts.map +1 -0
- package/src/constants.js +137 -0
- package/src/constants.js.map +1 -0
- package/src/enumerations/index.d.ts +2 -0
- package/src/enumerations/index.d.ts.map +1 -0
- package/src/enumerations/index.js +5 -0
- package/src/enumerations/index.js.map +1 -0
- package/src/enumerations/pbkdf2-profile.d.ts +9 -0
- package/src/enumerations/pbkdf2-profile.d.ts.map +1 -0
- package/src/enumerations/pbkdf2-profile.js +13 -0
- package/src/enumerations/pbkdf2-profile.js.map +1 -0
- package/src/i18n/ecies-i18n-factory.d.ts +54 -0
- package/src/i18n/ecies-i18n-factory.d.ts.map +1 -0
- package/src/i18n/ecies-i18n-factory.js +333 -0
- package/src/i18n/ecies-i18n-factory.js.map +1 -0
- package/src/i18n/{index.ts → index.d.ts} +1 -0
- package/src/i18n/index.d.ts.map +1 -0
- package/src/i18n/index.js +5 -0
- package/src/i18n/index.js.map +1 -0
- package/src/{index.ts → index.d.ts} +1 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +11 -0
- package/src/index.js.map +1 -0
- package/src/interfaces/authenticated-cipher.d.ts +10 -0
- package/src/interfaces/authenticated-cipher.d.ts.map +1 -0
- package/src/interfaces/authenticated-cipher.js +3 -0
- package/src/interfaces/authenticated-cipher.js.map +1 -0
- package/src/interfaces/authenticated-decipher.d.ts +9 -0
- package/src/interfaces/authenticated-decipher.d.ts.map +1 -0
- package/src/interfaces/authenticated-decipher.js +3 -0
- package/src/interfaces/authenticated-decipher.js.map +1 -0
- package/src/interfaces/checksum-config.d.ts +5 -0
- package/src/interfaces/checksum-config.d.ts.map +1 -0
- package/src/interfaces/checksum-config.js +3 -0
- package/src/interfaces/checksum-config.js.map +1 -0
- package/src/interfaces/checksum-consts.d.ts +11 -0
- package/src/interfaces/checksum-consts.d.ts.map +1 -0
- package/src/interfaces/checksum-consts.js +3 -0
- package/src/interfaces/checksum-consts.js.map +1 -0
- package/src/interfaces/constants.d.ts +43 -0
- package/src/interfaces/constants.d.ts.map +1 -0
- package/src/interfaces/constants.js +3 -0
- package/src/interfaces/constants.js.map +1 -0
- package/src/interfaces/ecies-consts.d.ts +88 -0
- package/src/interfaces/ecies-consts.d.ts.map +1 -0
- package/src/interfaces/ecies-consts.js +3 -0
- package/src/interfaces/ecies-consts.js.map +1 -0
- package/src/interfaces/encryption-consts.d.ts +11 -0
- package/src/interfaces/encryption-consts.d.ts.map +1 -0
- package/src/interfaces/encryption-consts.js +3 -0
- package/src/interfaces/encryption-consts.js.map +1 -0
- package/src/interfaces/{index.ts → index.d.ts} +1 -0
- package/src/interfaces/index.d.ts.map +1 -0
- package/src/interfaces/index.js +21 -0
- package/src/interfaces/index.js.map +1 -0
- package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts +6 -0
- package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts.map +1 -0
- package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.js +3 -0
- package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.js.map +1 -0
- package/src/interfaces/keyring-consts.d.ts +6 -0
- package/src/interfaces/keyring-consts.d.ts.map +1 -0
- package/src/interfaces/keyring-consts.js +3 -0
- package/src/interfaces/keyring-consts.js.map +1 -0
- package/src/interfaces/member-operational.d.ts +36 -0
- package/src/interfaces/member-operational.d.ts.map +1 -0
- package/src/interfaces/member-operational.js +3 -0
- package/src/interfaces/member-operational.js.map +1 -0
- package/src/interfaces/{member-with-mnemonic.ts → member-with-mnemonic.d.ts} +3 -3
- package/src/interfaces/member-with-mnemonic.d.ts.map +1 -0
- package/src/interfaces/member-with-mnemonic.js +3 -0
- package/src/interfaces/member-with-mnemonic.js.map +1 -0
- package/src/interfaces/{multi-encrypted-message.ts → multi-encrypted-message.d.ts} +5 -5
- package/src/interfaces/multi-encrypted-message.d.ts.map +1 -0
- package/src/interfaces/multi-encrypted-message.js +3 -0
- package/src/interfaces/multi-encrypted-message.js.map +1 -0
- package/src/interfaces/multi-encrypted-parsed-header.d.ts +24 -0
- package/src/interfaces/multi-encrypted-parsed-header.d.ts.map +1 -0
- package/src/interfaces/multi-encrypted-parsed-header.js +3 -0
- package/src/interfaces/multi-encrypted-parsed-header.js.map +1 -0
- package/src/interfaces/{pbkdf-profiles.ts → pbkdf-profiles.d.ts} +2 -2
- package/src/interfaces/pbkdf-profiles.d.ts.map +1 -0
- package/src/interfaces/pbkdf-profiles.js +3 -0
- package/src/interfaces/pbkdf-profiles.js.map +1 -0
- package/src/interfaces/pbkdf2-result.d.ts +6 -0
- package/src/interfaces/pbkdf2-result.d.ts.map +1 -0
- package/src/interfaces/pbkdf2-result.js +3 -0
- package/src/interfaces/pbkdf2-result.js.map +1 -0
- package/src/interfaces/signing-key-private-key-info.d.ts +11 -0
- package/src/interfaces/signing-key-private-key-info.d.ts.map +1 -0
- package/src/interfaces/signing-key-private-key-info.js +3 -0
- package/src/interfaces/signing-key-private-key-info.js.map +1 -0
- package/src/interfaces/{simple-keypair-buffer.ts → simple-keypair-buffer.d.ts} +3 -3
- package/src/interfaces/simple-keypair-buffer.d.ts.map +1 -0
- package/src/interfaces/simple-keypair-buffer.js +3 -0
- package/src/interfaces/simple-keypair-buffer.js.map +1 -0
- package/src/interfaces/{simple-keypair.ts → simple-keypair.d.ts} +3 -3
- package/src/interfaces/simple-keypair.d.ts.map +1 -0
- package/src/interfaces/simple-keypair.js +3 -0
- package/src/interfaces/simple-keypair.js.map +1 -0
- package/src/interfaces/simple-public-key-only-buffer.d.ts +4 -0
- package/src/interfaces/simple-public-key-only-buffer.d.ts.map +1 -0
- package/src/interfaces/simple-public-key-only-buffer.js +3 -0
- package/src/interfaces/simple-public-key-only-buffer.js.map +1 -0
- package/src/interfaces/simple-public-key-only.d.ts +4 -0
- package/src/interfaces/simple-public-key-only.d.ts.map +1 -0
- package/src/interfaces/simple-public-key-only.js +3 -0
- package/src/interfaces/simple-public-key-only.js.map +1 -0
- package/src/interfaces/single-encrypted-parsed-header.d.ts +35 -0
- package/src/interfaces/single-encrypted-parsed-header.d.ts.map +1 -0
- package/src/interfaces/single-encrypted-parsed-header.js +3 -0
- package/src/interfaces/single-encrypted-parsed-header.js.map +1 -0
- package/src/interfaces/{wallet-seed.ts → wallet-seed.d.ts} +3 -3
- package/src/interfaces/wallet-seed.d.ts.map +1 -0
- package/src/interfaces/wallet-seed.js +3 -0
- package/src/interfaces/wallet-seed.js.map +1 -0
- package/src/interfaces/wrapped-key-consts.d.ts +7 -0
- package/src/interfaces/wrapped-key-consts.d.ts.map +1 -0
- package/src/interfaces/wrapped-key-consts.js +3 -0
- package/src/interfaces/wrapped-key-consts.js.map +1 -0
- package/src/member.d.ts +74 -0
- package/src/member.d.ts.map +1 -0
- package/src/member.js +273 -0
- package/src/member.js.map +1 -0
- package/src/services/aes-gcm.d.ts +66 -0
- package/src/services/aes-gcm.d.ts.map +1 -0
- package/src/services/aes-gcm.js +115 -0
- package/src/services/aes-gcm.js.map +1 -0
- package/src/services/ecies/crypto-core.d.ts +83 -0
- package/src/services/ecies/crypto-core.d.ts.map +1 -0
- package/src/services/ecies/crypto-core.js +166 -0
- package/src/services/ecies/crypto-core.js.map +1 -0
- package/src/services/ecies/file.d.ts +30 -0
- package/src/services/ecies/file.d.ts.map +1 -0
- package/src/services/ecies/file.js +112 -0
- package/src/services/ecies/file.js.map +1 -0
- package/src/services/ecies/{index.ts → index.d.ts} +1 -0
- package/src/services/ecies/index.d.ts.map +1 -0
- package/src/services/ecies/index.js +11 -0
- package/src/services/ecies/index.js.map +1 -0
- package/src/services/ecies/multi-recipient.d.ts +82 -0
- package/src/services/ecies/multi-recipient.d.ts.map +1 -0
- package/src/services/ecies/multi-recipient.js +360 -0
- package/src/services/ecies/multi-recipient.js.map +1 -0
- package/src/services/ecies/service.d.ts +70 -0
- package/src/services/ecies/service.d.ts.map +1 -0
- package/src/services/ecies/service.js +167 -0
- package/src/services/ecies/service.js.map +1 -0
- package/src/services/ecies/signature.d.ts +38 -0
- package/src/services/ecies/signature.d.ts.map +1 -0
- package/src/services/ecies/signature.js +69 -0
- package/src/services/ecies/signature.js.map +1 -0
- package/src/services/ecies/single-recipient.d.ts +85 -0
- package/src/services/ecies/single-recipient.d.ts.map +1 -0
- package/src/services/ecies/single-recipient.js +399 -0
- package/src/services/ecies/single-recipient.js.map +1 -0
- package/src/services/ecies/utilities.d.ts +22 -0
- package/src/services/ecies/utilities.d.ts.map +1 -0
- package/src/services/ecies/utilities.js +75 -0
- package/src/services/ecies/utilities.js.map +1 -0
- package/src/services/index.d.ts +4 -0
- package/src/services/index.d.ts.map +1 -0
- package/src/services/index.js +7 -0
- package/src/services/index.js.map +1 -0
- package/src/services/pbkdf2.d.ts +106 -0
- package/src/services/pbkdf2.d.ts.map +1 -0
- package/src/services/pbkdf2.js +195 -0
- package/src/services/pbkdf2.js.map +1 -0
- package/src/{types.ts → types.d.ts} +9 -26
- package/src/types.d.ts.map +1 -0
- package/src/types.js +3 -0
- package/src/types.js.map +1 -0
- package/src/utils.d.ts +11 -0
- package/src/utils.d.ts.map +1 -0
- package/src/utils.js +82 -0
- package/src/utils.js.map +1 -0
- package/LICENSE +0 -21
- package/src/constants.ts +0 -182
- package/src/enumerations/index.ts +0 -1
- package/src/enumerations/pbkdf2-profile.ts +0 -8
- package/src/i18n/ecies-i18n-factory.ts +0 -435
- package/src/interfaces/authenticated-cipher.ts +0 -9
- package/src/interfaces/authenticated-decipher.ts +0 -8
- package/src/interfaces/checksum-config.ts +0 -4
- package/src/interfaces/checksum-consts.ts +0 -13
- package/src/interfaces/constants.ts +0 -43
- package/src/interfaces/ecies-consts.ts +0 -99
- package/src/interfaces/encryption-consts.ts +0 -10
- package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.ts +0 -7
- package/src/interfaces/keyring-consts.ts +0 -5
- package/src/interfaces/member-operational.ts +0 -52
- package/src/interfaces/multi-encrypted-parsed-header.ts +0 -24
- package/src/interfaces/pbkdf2-result.ts +0 -5
- package/src/interfaces/signing-key-private-key-info.ts +0 -12
- package/src/interfaces/simple-public-key-only-buffer.ts +0 -3
- package/src/interfaces/simple-public-key-only.ts +0 -3
- package/src/interfaces/single-encrypted-parsed-header.ts +0 -35
- package/src/interfaces/wrapped-key-consts.ts +0 -6
- package/src/member.ts +0 -463
- package/src/services/aes-gcm.ts +0 -160
- package/src/services/ecies/crypto-core.ts +0 -213
- package/src/services/ecies/file.ts +0 -174
- package/src/services/ecies/multi-recipient.ts +0 -583
- package/src/services/ecies/service.ts +0 -351
- package/src/services/ecies/signature.ts +0 -91
- package/src/services/ecies/single-recipient.ts +0 -676
- package/src/services/ecies/utilities.ts +0 -111
- package/src/services/index.ts +0 -3
- package/src/services/pbkdf2.ts +0 -307
- package/src/utils.ts +0 -104
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { HexString } from '@digitaldefiance/ecies-lib';
|
|
2
|
+
import { SignatureBuffer, SignatureString } from '../../types';
|
|
3
|
+
import { EciesCryptoCore } from './crypto-core';
|
|
4
|
+
/**
|
|
5
|
+
* Signature-related functions for ECIES
|
|
6
|
+
*/
|
|
7
|
+
export declare class EciesSignature {
|
|
8
|
+
private readonly cryptoCore;
|
|
9
|
+
constructor(cryptoCore: EciesCryptoCore);
|
|
10
|
+
/**
|
|
11
|
+
* Signs arbitrary binary data with the given private key.
|
|
12
|
+
* @param privateKey The private key to sign the message with.
|
|
13
|
+
* @param data The data to sign.
|
|
14
|
+
* @returns The signature (64 bytes: r + s).
|
|
15
|
+
*/
|
|
16
|
+
signMessage(privateKey: Buffer, data: Buffer): SignatureBuffer;
|
|
17
|
+
/**
|
|
18
|
+
* Verifies arbitrary binary data with the given public key.
|
|
19
|
+
* @param publicKey The public key to verify the message with.
|
|
20
|
+
* @param data The data to verify.
|
|
21
|
+
* @param signature The signature to verify (64 bytes: r + s).
|
|
22
|
+
* @returns True if the signature is valid, false otherwise.
|
|
23
|
+
*/
|
|
24
|
+
verifyMessage(publicKey: Buffer, data: Buffer, signature: SignatureBuffer): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Converts a signature string to a signature buffer.
|
|
27
|
+
* @param signatureString - The signature string to convert.
|
|
28
|
+
* @returns The signature buffer.
|
|
29
|
+
*/
|
|
30
|
+
signatureStringToSignatureBuffer(signatureString: HexString): SignatureBuffer;
|
|
31
|
+
/**
|
|
32
|
+
* Converts a signature buffer to a signature string.
|
|
33
|
+
* @param signatureBuffer - The signature buffer to convert.
|
|
34
|
+
* @returns The signature string.
|
|
35
|
+
*/
|
|
36
|
+
signatureBufferToSignatureString(signatureBuffer: SignatureBuffer): SignatureString;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=signature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/services/ecies/signature.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EACV,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkB;gBAEjC,UAAU,EAAE,eAAe;IAIvC;;;;;OAKG;IACI,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe;IASrE;;;;;;OAMG;IACI,aAAa,CAClB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,eAAe,GACzB,OAAO;IAsBV;;;;OAIG;IACI,gCAAgC,CACrC,eAAe,EAAE,SAAS,GACzB,eAAe;IAIlB;;;;OAIG;IACI,gCAAgC,CACrC,eAAe,EAAE,eAAe,GAC/B,eAAe;CAGnB"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EciesSignature = void 0;
|
|
4
|
+
const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
5
|
+
const secp256k1_js_1 = require("@noble/curves/secp256k1.js");
|
|
6
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
7
|
+
const ecies_i18n_factory_1 = require("../../i18n/ecies-i18n-factory");
|
|
8
|
+
/**
|
|
9
|
+
* Signature-related functions for ECIES
|
|
10
|
+
*/
|
|
11
|
+
class EciesSignature {
|
|
12
|
+
cryptoCore;
|
|
13
|
+
constructor(cryptoCore) {
|
|
14
|
+
this.cryptoCore = cryptoCore;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Signs arbitrary binary data with the given private key.
|
|
18
|
+
* @param privateKey The private key to sign the message with.
|
|
19
|
+
* @param data The data to sign.
|
|
20
|
+
* @returns The signature (64 bytes: r + s).
|
|
21
|
+
*/
|
|
22
|
+
signMessage(privateKey, data) {
|
|
23
|
+
const hash = (0, sha2_js_1.sha256)(data);
|
|
24
|
+
const signature = secp256k1_js_1.secp256k1.sign(hash, privateKey, {
|
|
25
|
+
format: 'compact',
|
|
26
|
+
extraEntropy: false,
|
|
27
|
+
});
|
|
28
|
+
return Buffer.from(signature);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Verifies arbitrary binary data with the given public key.
|
|
32
|
+
* @param publicKey The public key to verify the message with.
|
|
33
|
+
* @param data The data to verify.
|
|
34
|
+
* @param signature The signature to verify (64 bytes: r + s).
|
|
35
|
+
* @returns True if the signature is valid, false otherwise.
|
|
36
|
+
*/
|
|
37
|
+
verifyMessage(publicKey, data, signature) {
|
|
38
|
+
if (signature.length !== 64) {
|
|
39
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidSignature, (0, ecies_i18n_factory_1.createEciesTranslationEngine)());
|
|
40
|
+
}
|
|
41
|
+
// Normalize and validate the public key
|
|
42
|
+
try {
|
|
43
|
+
publicKey = this.cryptoCore.normalizePublicKey(publicKey);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidSenderPublicKey, (0, ecies_i18n_factory_1.createEciesTranslationEngine)());
|
|
47
|
+
}
|
|
48
|
+
const hash = (0, sha2_js_1.sha256)(data);
|
|
49
|
+
return secp256k1_js_1.secp256k1.verify(signature, hash, publicKey);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Converts a signature string to a signature buffer.
|
|
53
|
+
* @param signatureString - The signature string to convert.
|
|
54
|
+
* @returns The signature buffer.
|
|
55
|
+
*/
|
|
56
|
+
signatureStringToSignatureBuffer(signatureString) {
|
|
57
|
+
return Buffer.from(signatureString, 'hex');
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Converts a signature buffer to a signature string.
|
|
61
|
+
* @param signatureBuffer - The signature buffer to convert.
|
|
62
|
+
* @returns The signature string.
|
|
63
|
+
*/
|
|
64
|
+
signatureBufferToSignatureString(signatureBuffer) {
|
|
65
|
+
return signatureBuffer.toString('hex');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.EciesSignature = EciesSignature;
|
|
69
|
+
//# sourceMappingURL=signature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/services/ecies/signature.ts"],"names":[],"mappings":";;;AAAA,0DAIoC;AACpC,6DAAuD;AACvD,mDAA+C;AAC/C,sEAA6E;AAI7E;;GAEG;AACH,MAAa,cAAc;IACR,UAAU,CAAkB;IAE7C,YAAY,UAA2B;QACrC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/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
|
|
1
|
+
import { EciesEncryptionType, EciesEncryptionTypeEnum, IECIESConfig } from '@digitaldefiance/ecies-lib';
|
|
2
|
+
import { PluginI18nEngine, CoreLanguageCode } from '@digitaldefiance/i18n-lib';
|
|
3
|
+
import { ISingleEncryptedParsedHeader } from '../../interfaces/single-encrypted-parsed-header';
|
|
4
|
+
import { EciesCryptoCore } from './crypto-core';
|
|
5
|
+
export declare class EciesSingleRecipientCore {
|
|
6
|
+
protected readonly cryptoCore: EciesCryptoCore;
|
|
7
|
+
protected readonly config: IECIESConfig;
|
|
8
|
+
protected readonly engine: PluginI18nEngine<CoreLanguageCode>;
|
|
9
|
+
constructor(config: IECIESConfig, engine?: PluginI18nEngine<CoreLanguageCode>);
|
|
10
|
+
/**
|
|
11
|
+
* Get the size of the header for a given encryption type
|
|
12
|
+
* @param encryptionType The encryption type (single, simple, etc.)
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
getHeaderSize(encryptionType: EciesEncryptionType): number;
|
|
16
|
+
/**
|
|
17
|
+
* Encrypt a message with a public key
|
|
18
|
+
* @param encryptSimple Whether to simple encrypt (without crc, length)
|
|
19
|
+
* @param receiverPublicKey The public key of the receiver
|
|
20
|
+
* @param message The message to encrypt
|
|
21
|
+
* @param preamble Optional preamble to prepend to the encrypted message
|
|
22
|
+
* @param options Optional encryption options
|
|
23
|
+
* @param options.recipientCount The number of recipients for multiple encryption mode
|
|
24
|
+
* @returns The encrypted message
|
|
25
|
+
*/
|
|
26
|
+
encrypt(encryptSimple: boolean, receiverPublicKey: Buffer, message: Buffer, preamble?: Buffer): Buffer;
|
|
27
|
+
/**
|
|
28
|
+
* Parse the header from encrypted data
|
|
29
|
+
* @param encryptionType The type of encryption (single, simple, etc.) or undefined if not known
|
|
30
|
+
* @param data The encrypted data
|
|
31
|
+
* @param preambleSize The size of the preamble, if any
|
|
32
|
+
* @param options Optional parsing options
|
|
33
|
+
* @param options.dataLength The expected length of the data
|
|
34
|
+
* @returns The parsed header components
|
|
35
|
+
*/
|
|
36
|
+
parseEncryptedMessage(encryptionType: EciesEncryptionTypeEnum | undefined, data: Buffer, preambleSize?: number, options?: {
|
|
37
|
+
dataLength?: number;
|
|
38
|
+
}): {
|
|
39
|
+
header: ISingleEncryptedParsedHeader;
|
|
40
|
+
data: Buffer;
|
|
41
|
+
remainder: Buffer;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Decrypts data encrypted with ECIES using a header
|
|
45
|
+
* This method maintains backward compatibility with the original implementation
|
|
46
|
+
* by returning just the Buffer. For detailed information, use decryptSingleWithHeaderEx
|
|
47
|
+
* @param encryptionType The type of encryption (single, simple, etc.)
|
|
48
|
+
* @param privateKey The private key to decrypt the data
|
|
49
|
+
* @param encryptedData The data to decrypt
|
|
50
|
+
* @param preambleSize The size of the preamble, if any
|
|
51
|
+
* @param options Optional decryption options
|
|
52
|
+
* @param options.dataLength The expected length of the data
|
|
53
|
+
* @returns The decrypted data buffer
|
|
54
|
+
*/
|
|
55
|
+
decryptWithHeader(encryptionType: EciesEncryptionTypeEnum | undefined, privateKey: Buffer, encryptedData: Buffer, preambleSize?: number, options?: {
|
|
56
|
+
dataLength?: number;
|
|
57
|
+
}): Buffer;
|
|
58
|
+
/**
|
|
59
|
+
* Extended version of decryptSingleWithHeader that provides more detailed information
|
|
60
|
+
* @param encryptionType The type of encryption (single, simple, etc.)
|
|
61
|
+
* @param privateKey The private key to decrypt the data
|
|
62
|
+
* @param encryptedData The data to decrypt
|
|
63
|
+
* @param preambleSize The size of the preamble, if any
|
|
64
|
+
* @param options Optional decryption options
|
|
65
|
+
* @param options.dataLength The expected length of the data
|
|
66
|
+
* @returns The decrypted data and the number of bytes consumed from the input buffer
|
|
67
|
+
*/
|
|
68
|
+
decryptWithHeaderEx(encryptionType: EciesEncryptionTypeEnum | undefined, privateKey: Buffer, encryptedData: Buffer, preambleSize?: number, options?: {
|
|
69
|
+
dataLength?: number;
|
|
70
|
+
}): {
|
|
71
|
+
decrypted: Buffer;
|
|
72
|
+
consumedBytes: number;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Decrypts data encrypted with ECIES using components
|
|
76
|
+
* @param privateKey The private key to decrypt the data
|
|
77
|
+
* @param ephemeralPublicKey The ephemeral public key used to encrypt the data
|
|
78
|
+
* @param iv The initialization vector used to encrypt the data
|
|
79
|
+
* @param authTag The authentication tag used to encrypt the data
|
|
80
|
+
* @param encrypted The encrypted data
|
|
81
|
+
* @returns The decrypted data
|
|
82
|
+
*/
|
|
83
|
+
decryptWithComponents(privateKey: Buffer, ephemeralPublicKey: Buffer, iv: Buffer, authTag: Buffer, encrypted: Buffer): Buffer;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=single-recipient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-recipient.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/services/ecies/single-recipient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EACnB,uBAAuB,EAOvB,YAAY,EAGb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAW/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,iDAAiD,CAAC;AAC/F,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,qBAAa,wBAAwB;IACnC,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC;IAC/C,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IACxC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;gBAElD,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC;IAM7E;;;;OAIG;IACI,aAAa,CAAC,cAAc,EAAE,mBAAmB,GAAG,MAAM;IAcjE;;;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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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-recipient.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/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,CAA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