@digitaldefiance/ecies-lib 1.1.24 → 1.1.26
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 +8 -0
- package/package.json +5 -4
- package/src/constants.d.ts +46 -0
- package/src/constants.d.ts.map +1 -0
- package/src/constants.js +358 -0
- package/src/constants.js.map +1 -0
- package/src/email-string.d.ts +42 -0
- package/src/email-string.d.ts.map +1 -0
- package/src/email-string.js +73 -0
- package/src/email-string.js.map +1 -0
- package/src/enumerations/ecies-encryption-type.d.ts +15 -0
- package/src/enumerations/ecies-encryption-type.d.ts.map +1 -0
- package/src/enumerations/ecies-encryption-type.js +71 -0
- package/src/enumerations/ecies-encryption-type.js.map +1 -0
- package/src/enumerations/ecies-error-type.d.ts +32 -0
- package/src/enumerations/ecies-error-type.d.ts.map +1 -0
- package/src/enumerations/ecies-error-type.js +36 -0
- package/src/enumerations/ecies-error-type.js.map +1 -0
- package/src/enumerations/ecies-string-key.d.ts +96 -0
- package/src/enumerations/ecies-string-key.d.ts.map +1 -0
- package/src/enumerations/ecies-string-key.js +105 -0
- package/src/enumerations/ecies-string-key.js.map +1 -0
- package/src/enumerations/guid-brand-type.d.ts +27 -0
- package/src/enumerations/guid-brand-type.d.ts.map +1 -0
- package/src/enumerations/guid-brand-type.js +31 -0
- package/src/enumerations/guid-brand-type.js.map +1 -0
- package/src/enumerations/guid-error-type.d.ts +7 -0
- package/src/enumerations/guid-error-type.d.ts.map +1 -0
- package/src/enumerations/guid-error-type.js +11 -0
- package/src/enumerations/guid-error-type.js.map +1 -0
- package/src/enumerations/{index.ts → index.d.ts} +1 -0
- package/src/enumerations/index.d.ts.map +1 -0
- package/src/enumerations/index.js +18 -0
- package/src/enumerations/index.js.map +1 -0
- package/src/enumerations/invalid-email-type.d.ts +6 -0
- package/src/enumerations/invalid-email-type.d.ts.map +1 -0
- package/src/enumerations/invalid-email-type.js +10 -0
- package/src/enumerations/invalid-email-type.js.map +1 -0
- package/src/enumerations/length-encoding-type.d.ts +7 -0
- package/src/enumerations/length-encoding-type.d.ts.map +1 -0
- package/src/enumerations/length-encoding-type.js +11 -0
- package/src/enumerations/length-encoding-type.js.map +1 -0
- package/src/enumerations/length-error-type.d.ts +6 -0
- package/src/enumerations/length-error-type.d.ts.map +1 -0
- package/src/enumerations/length-error-type.js +10 -0
- package/src/enumerations/length-error-type.js.map +1 -0
- package/src/enumerations/member-error-type.d.ts +87 -0
- package/src/enumerations/member-error-type.d.ts.map +1 -0
- package/src/enumerations/member-error-type.js +91 -0
- package/src/enumerations/member-error-type.js.map +1 -0
- package/src/enumerations/{member-type.ts → member-type.d.ts} +6 -7
- package/src/enumerations/member-type.d.ts.map +1 -0
- package/src/enumerations/member-type.js +19 -0
- package/src/enumerations/member-type.js.map +1 -0
- package/src/enumerations/password-login-error-type.d.ts +5 -0
- package/src/enumerations/password-login-error-type.d.ts.map +1 -0
- package/src/enumerations/password-login-error-type.js +9 -0
- package/src/enumerations/password-login-error-type.js.map +1 -0
- package/src/enumerations/pbkdf2-error-type.d.ts +6 -0
- package/src/enumerations/pbkdf2-error-type.d.ts.map +1 -0
- package/src/enumerations/pbkdf2-error-type.js +10 -0
- package/src/enumerations/pbkdf2-error-type.js.map +1 -0
- package/src/enumerations/pbkdf2-profile.d.ts +6 -0
- package/src/enumerations/pbkdf2-profile.d.ts.map +1 -0
- package/src/enumerations/pbkdf2-profile.js +10 -0
- package/src/enumerations/pbkdf2-profile.js.map +1 -0
- package/src/enumerations/secure-storage-error-type.d.ts +6 -0
- package/src/enumerations/secure-storage-error-type.d.ts.map +1 -0
- package/src/enumerations/secure-storage-error-type.js +10 -0
- package/src/enumerations/secure-storage-error-type.js.map +1 -0
- package/src/errors/disposed.d.ts +4 -0
- package/src/errors/disposed.d.ts.map +1 -0
- package/src/errors/disposed.js +20 -0
- package/src/errors/disposed.js.map +1 -0
- package/src/errors/ecies.d.ts +7 -0
- package/src/errors/ecies.d.ts.map +1 -0
- package/src/errors/ecies.js +15 -0
- package/src/errors/ecies.js.map +1 -0
- package/src/errors/guid.d.ts +15 -0
- package/src/errors/guid.d.ts.map +1 -0
- package/src/errors/guid.js +26 -0
- package/src/errors/guid.js.map +1 -0
- package/src/errors/{index.ts → index.d.ts} +1 -0
- package/src/errors/index.d.ts.map +1 -0
- package/src/errors/index.js +12 -0
- package/src/errors/index.js.map +1 -0
- package/src/errors/invalid-email.d.ts +7 -0
- package/src/errors/invalid-email.d.ts.map +1 -0
- package/src/errors/invalid-email.js +14 -0
- package/src/errors/invalid-email.js.map +1 -0
- package/src/errors/length.d.ts +7 -0
- package/src/errors/length.d.ts.map +1 -0
- package/src/errors/length.js +14 -0
- package/src/errors/length.js.map +1 -0
- package/src/errors/member.d.ts +7 -0
- package/src/errors/member.d.ts.map +1 -0
- package/src/errors/member.js +14 -0
- package/src/errors/member.js.map +1 -0
- package/src/errors/pbkdf2.d.ts +7 -0
- package/src/errors/pbkdf2.d.ts.map +1 -0
- package/src/errors/pbkdf2.js +14 -0
- package/src/errors/pbkdf2.js.map +1 -0
- package/src/errors/secure-storage.d.ts +7 -0
- package/src/errors/secure-storage.d.ts.map +1 -0
- package/src/errors/secure-storage.js +15 -0
- package/src/errors/secure-storage.js.map +1 -0
- package/src/errors/simple-ecies.d.ts +6 -0
- package/src/errors/simple-ecies.d.ts.map +1 -0
- package/src/errors/simple-ecies.js +15 -0
- package/src/errors/simple-ecies.js.map +1 -0
- package/src/errors/simple-test-error.d.ts +4 -0
- package/src/errors/simple-test-error.d.ts.map +1 -0
- package/src/errors/simple-test-error.js +11 -0
- package/src/errors/simple-test-error.js.map +1 -0
- package/src/guid.d.ts +153 -0
- package/src/guid.d.ts.map +1 -0
- package/src/guid.js +615 -0
- package/src/guid.js.map +1 -0
- package/src/i18n-setup.d.ts +24 -0
- package/src/i18n-setup.d.ts.map +1 -0
- package/src/i18n-setup.js +837 -0
- package/src/i18n-setup.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 +19 -0
- package/src/index.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 +45 -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-config.d.ts +9 -0
- package/src/interfaces/ecies-config.d.ts.map +1 -0
- package/src/interfaces/ecies-config.js +3 -0
- package/src/interfaces/ecies-config.js.map +1 -0
- package/src/interfaces/ecies-consts.d.ts +58 -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/ecies-file-service.d.ts +7 -0
- package/src/interfaces/ecies-file-service.d.ts.map +1 -0
- package/src/interfaces/ecies-file-service.js +3 -0
- package/src/interfaces/ecies-file-service.js.map +1 -0
- package/src/interfaces/guid.d.ts +45 -0
- package/src/interfaces/guid.d.ts.map +1 -0
- package/src/interfaces/guid.js +3 -0
- package/src/interfaces/guid.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 +17 -0
- package/src/interfaces/index.js.map +1 -0
- package/src/interfaces/library-error.d.ts +23 -0
- package/src/interfaces/library-error.d.ts.map +1 -0
- package/src/interfaces/library-error.js +3 -0
- package/src/interfaces/library-error.js.map +1 -0
- package/src/interfaces/member-operational.d.ts +40 -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-storage.ts → member-storage.d.ts} +10 -11
- package/src/interfaces/member-storage.d.ts.map +1 -0
- package/src/interfaces/member-storage.js +3 -0
- package/src/interfaces/member-storage.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/pbkdf2-config.d.ts +7 -0
- package/src/interfaces/pbkdf2-config.d.ts.map +1 -0
- package/src/interfaces/pbkdf2-config.js +3 -0
- package/src/interfaces/pbkdf2-config.js.map +1 -0
- package/src/interfaces/pbkdf2-consts.d.ts +9 -0
- package/src/interfaces/pbkdf2-consts.d.ts.map +1 -0
- package/src/interfaces/pbkdf2-consts.js +3 -0
- package/src/interfaces/pbkdf2-consts.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/member.d.ts +66 -0
- package/src/member.d.ts.map +1 -0
- package/src/member.js +269 -0
- package/src/member.js.map +1 -0
- package/src/{pbkdf2-profiles.ts → pbkdf2-profiles.d.ts} +2 -2
- package/src/pbkdf2-profiles.d.ts.map +1 -0
- package/src/pbkdf2-profiles.js +3 -0
- package/src/pbkdf2-profiles.js.map +1 -0
- package/src/phone-number.d.ts +6 -0
- package/src/phone-number.d.ts.map +1 -0
- package/src/phone-number.js +22 -0
- package/src/phone-number.js.map +1 -0
- package/src/regexes.d.ts +7 -0
- package/src/regexes.d.ts.map +1 -0
- package/src/regexes.js +10 -0
- package/src/regexes.js.map +1 -0
- package/src/secure-buffer.d.ts +38 -0
- package/src/secure-buffer.d.ts.map +1 -0
- package/src/secure-buffer.js +168 -0
- package/src/secure-buffer.js.map +1 -0
- package/src/secure-string.d.ts +39 -0
- package/src/secure-string.d.ts.map +1 -0
- package/src/secure-string.js +195 -0
- package/src/secure-string.js.map +1 -0
- package/src/services/aes-gcm.d.ts +57 -0
- package/src/services/aes-gcm.d.ts.map +1 -0
- package/src/services/aes-gcm.js +111 -0
- package/src/services/aes-gcm.js.map +1 -0
- package/src/services/ecies/crypto-core.d.ts +51 -0
- package/src/services/ecies/crypto-core.d.ts.map +1 -0
- package/src/services/ecies/crypto-core.js +139 -0
- package/src/services/ecies/crypto-core.js.map +1 -0
- package/src/services/ecies/example.d.ts +25 -0
- package/src/services/ecies/example.d.ts.map +1 -0
- package/src/services/ecies/example.js +128 -0
- package/src/services/ecies/example.js.map +1 -0
- package/src/services/ecies/file.d.ts +18 -0
- package/src/services/ecies/file.d.ts.map +1 -0
- package/src/services/ecies/file.js +110 -0
- package/src/services/ecies/file.js.map +1 -0
- package/src/services/ecies/{index.ts → index.d.ts} +1 -3
- package/src/services/ecies/index.d.ts.map +1 -0
- package/src/services/ecies/index.js +44 -0
- package/src/services/ecies/index.js.map +1 -0
- package/src/services/ecies/integration.d.ts +59 -0
- package/src/services/ecies/integration.d.ts.map +1 -0
- package/src/services/ecies/integration.js +172 -0
- package/src/services/ecies/integration.js.map +1 -0
- package/src/services/ecies/interfaces.d.ts +51 -0
- package/src/services/ecies/interfaces.d.ts.map +1 -0
- package/src/services/ecies/interfaces.js +6 -0
- package/src/services/ecies/interfaces.js.map +1 -0
- package/src/services/ecies/manual-test.d.ts +29 -0
- package/src/services/ecies/manual-test.d.ts.map +1 -0
- package/src/services/ecies/manual-test.js +171 -0
- package/src/services/ecies/manual-test.js.map +1 -0
- package/src/services/ecies/multi-recipient.d.ts +52 -0
- package/src/services/ecies/multi-recipient.d.ts.map +1 -0
- package/src/services/ecies/multi-recipient.js +243 -0
- package/src/services/ecies/multi-recipient.js.map +1 -0
- package/src/services/ecies/service.d.ts +104 -0
- package/src/services/ecies/service.d.ts.map +1 -0
- package/src/services/ecies/service.js +192 -0
- package/src/services/ecies/service.js.map +1 -0
- package/src/services/ecies/signature.d.ts +27 -0
- package/src/services/ecies/signature.d.ts.map +1 -0
- package/src/services/ecies/signature.js +76 -0
- package/src/services/ecies/signature.js.map +1 -0
- package/src/services/ecies/single-recipient.d.ts +46 -0
- package/src/services/ecies/single-recipient.d.ts.map +1 -0
- package/src/services/ecies/single-recipient.js +212 -0
- package/src/services/ecies/single-recipient.js.map +1 -0
- package/src/services/{index.ts → index.d.ts} +1 -0
- package/src/services/index.d.ts.map +1 -0
- package/src/services/index.js +9 -0
- package/src/services/index.js.map +1 -0
- package/src/services/password-login.d.ts +49 -0
- package/src/services/password-login.d.ts.map +1 -0
- package/src/services/password-login.js +121 -0
- package/src/services/password-login.js.map +1 -0
- package/src/services/pbkdf2.d.ts +56 -0
- package/src/services/pbkdf2.d.ts.map +1 -0
- package/src/services/pbkdf2.js +114 -0
- package/src/services/pbkdf2.js.map +1 -0
- package/src/services/xor.d.ts +37 -0
- package/src/services/xor.d.ts.map +1 -0
- package/src/services/xor.js +67 -0
- package/src/services/xor.js.map +1 -0
- package/src/types/deep-partial.d.ts +4 -0
- package/src/types/deep-partial.d.ts.map +1 -0
- package/src/types/deep-partial.js +3 -0
- package/src/types/deep-partial.js.map +1 -0
- package/src/{types.ts → types.d.ts} +4 -10
- 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 +68 -0
- package/src/utils.d.ts.map +1 -0
- package/src/utils.js +288 -0
- package/src/utils.js.map +1 -0
- package/LICENSE +0 -21
- package/src/constants.ts +0 -474
- package/src/email-string.ts +0 -83
- package/src/enumerations/ecies-encryption-type.ts +0 -102
- package/src/enumerations/ecies-error-type.ts +0 -31
- package/src/enumerations/ecies-string-key.ts +0 -108
- package/src/enumerations/guid-brand-type.ts +0 -26
- package/src/enumerations/guid-error-type.ts +0 -6
- package/src/enumerations/invalid-email-type.ts +0 -5
- package/src/enumerations/length-encoding-type.ts +0 -6
- package/src/enumerations/length-error-type.ts +0 -5
- package/src/enumerations/member-error-type.ts +0 -106
- package/src/enumerations/password-login-error-type.ts +0 -4
- package/src/enumerations/pbkdf2-error-type.ts +0 -5
- package/src/enumerations/pbkdf2-profile.ts +0 -5
- package/src/enumerations/secure-storage-error-type.ts +0 -5
- package/src/errors/disposed.ts +0 -15
- package/src/errors/ecies.ts +0 -34
- package/src/errors/guid.ts +0 -34
- package/src/errors/invalid-email.ts +0 -11
- package/src/errors/length.ts +0 -11
- package/src/errors/member.ts +0 -12
- package/src/errors/pbkdf2.ts +0 -12
- package/src/errors/secure-storage.ts +0 -13
- package/src/errors/simple-ecies.ts +0 -18
- package/src/errors/simple-test-error.ts +0 -6
- package/src/guid.ts +0 -800
- package/src/i18n-setup.ts +0 -1312
- package/src/interfaces/checksum-config.ts +0 -4
- package/src/interfaces/checksum-consts.ts +0 -13
- package/src/interfaces/constants.ts +0 -48
- package/src/interfaces/ecies-config.ts +0 -8
- package/src/interfaces/ecies-consts.ts +0 -70
- package/src/interfaces/ecies-file-service.ts +0 -6
- package/src/interfaces/guid.ts +0 -53
- package/src/interfaces/library-error.ts +0 -23
- package/src/interfaces/member-operational.ts +0 -54
- package/src/interfaces/pbkdf2-config.ts +0 -6
- package/src/interfaces/pbkdf2-consts.ts +0 -10
- package/src/interfaces/pbkdf2-result.ts +0 -5
- package/src/member.ts +0 -429
- package/src/phone-number.ts +0 -18
- package/src/regexes.ts +0 -10
- package/src/secure-buffer.ts +0 -183
- package/src/secure-string.ts +0 -229
- package/src/services/aes-gcm.ts +0 -177
- package/src/services/ecies/README.md +0 -147
- package/src/services/ecies/crypto-core.ts +0 -180
- package/src/services/ecies/example.ts +0 -185
- package/src/services/ecies/file.ts +0 -167
- package/src/services/ecies/integration.ts +0 -241
- package/src/services/ecies/interfaces.ts +0 -59
- package/src/services/ecies/manual-test.ts +0 -219
- package/src/services/ecies/multi-recipient.ts +0 -394
- package/src/services/ecies/service.ts +0 -317
- package/src/services/ecies/signature.ts +0 -93
- package/src/services/ecies/single-recipient.ts +0 -340
- package/src/services/password-login.ts +0 -228
- package/src/services/pbkdf2.ts +0 -172
- package/src/services/xor.ts +0 -65
- package/src/types/deep-partial.ts +0 -11
- package/src/utils.ts +0 -331
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Pbkdf2Service = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const pbkdf2_error_type_1 = require("../enumerations/pbkdf2-error-type");
|
|
6
|
+
const pbkdf2_1 = require("../errors/pbkdf2");
|
|
7
|
+
/**
|
|
8
|
+
* Service for handling PBKDF2 (Password-Based Key Derivation Function 2) operations.
|
|
9
|
+
* This service provides functionality for:
|
|
10
|
+
* - Generating secure key derivation configurations
|
|
11
|
+
* - Deriving cryptographic keys from passwords
|
|
12
|
+
* - Managing salt and iteration parameters
|
|
13
|
+
* - Both synchronous and asynchronous key derivation
|
|
14
|
+
*/
|
|
15
|
+
class Pbkdf2Service {
|
|
16
|
+
engine;
|
|
17
|
+
profiles;
|
|
18
|
+
eciesConsts;
|
|
19
|
+
pbkdf2Consts;
|
|
20
|
+
constructor(engine, profiles = constants_1.Constants.PBKDF2_PROFILES, eciesParams = constants_1.Constants.ECIES, pbkdf2Params = constants_1.Constants.PBKDF2) {
|
|
21
|
+
this.engine = engine;
|
|
22
|
+
this.profiles = profiles;
|
|
23
|
+
this.eciesConsts = eciesParams;
|
|
24
|
+
this.pbkdf2Consts = pbkdf2Params;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get a predefined configuration profile for common use cases
|
|
28
|
+
* @param profile The name of the profile to use
|
|
29
|
+
* @returns Configuration object for the specified profile
|
|
30
|
+
*/
|
|
31
|
+
getProfileConfig(profile) {
|
|
32
|
+
const profileConfig = this.profiles[profile];
|
|
33
|
+
if (!profileConfig) {
|
|
34
|
+
throw new pbkdf2_1.Pbkdf2Error(pbkdf2_error_type_1.Pbkdf2ErrorType.InvalidProfile, this.engine);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
hashBytes: profileConfig.hashBytes,
|
|
38
|
+
saltBytes: profileConfig.saltBytes,
|
|
39
|
+
iterations: profileConfig.iterations,
|
|
40
|
+
algorithm: profileConfig.algorithm,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Generate an options object for pbkdf2
|
|
45
|
+
* @param iterations Optional number of iterations (defaults to Pbkdf2IterationsPerSecond)
|
|
46
|
+
* @param saltBytes Optional salt size in bytes (defaults to PBKDF2.SALT_BYTES)
|
|
47
|
+
* @param hashBytes Optional hash size in bytes (defaults to ECIES.SYMMETRIC.KEY_SIZE)
|
|
48
|
+
* @param algorithm Optional hash algorithm (defaults to PBKDF2.ALGORITHM)
|
|
49
|
+
* @returns Configuration object for PBKDF2
|
|
50
|
+
*/
|
|
51
|
+
getConfig(iterations, saltBytes, hashBytes, algorithm) {
|
|
52
|
+
// larger numbers mean better security, less
|
|
53
|
+
return {
|
|
54
|
+
// size of the generated hash
|
|
55
|
+
hashBytes: hashBytes ?? this.eciesConsts.SYMMETRIC.KEY_SIZE,
|
|
56
|
+
// larger salt means hashed passwords are more resistant to rainbow table, but
|
|
57
|
+
// you get diminishing returns pretty fast
|
|
58
|
+
saltBytes: saltBytes ?? this.pbkdf2Consts.SALT_BYTES,
|
|
59
|
+
// more iterations means an attacker has to take longer to brute force an
|
|
60
|
+
// individual password, so larger is better. however, larger also means longer
|
|
61
|
+
// to hash the password. tune so that hashing the password takes about a
|
|
62
|
+
// second
|
|
63
|
+
iterations: iterations ?? this.pbkdf2Consts.ITERATIONS_PER_SECOND,
|
|
64
|
+
// hash algorithm
|
|
65
|
+
algorithm: algorithm ?? this.pbkdf2Consts.ALGORITHM,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Given a password, use pbkdf2 to generate an appropriately sized key for AES encryption
|
|
70
|
+
* @param password The password to derive a key from
|
|
71
|
+
* @param salt Optional salt (will be randomly generated if not provided)
|
|
72
|
+
* @param iterations Optional number of iterations
|
|
73
|
+
* @param saltBytes Optional salt size in bytes
|
|
74
|
+
* @param keySize Optional key size in bytes
|
|
75
|
+
* @param algorithm Optional hash algorithm
|
|
76
|
+
* @returns Object containing the derived key, salt, and iteration count
|
|
77
|
+
*/
|
|
78
|
+
async deriveKeyFromPasswordAsync(password, salt, iterations, saltBytes, keySize, algorithm) {
|
|
79
|
+
const config = this.getConfig(iterations, saltBytes, keySize, algorithm);
|
|
80
|
+
const saltBytes_ = salt ?? crypto.getRandomValues(new Uint8Array(config.saltBytes));
|
|
81
|
+
if (saltBytes_.length !== config.saltBytes) {
|
|
82
|
+
throw new pbkdf2_1.Pbkdf2Error(pbkdf2_error_type_1.Pbkdf2ErrorType.InvalidSaltLength, this.engine);
|
|
83
|
+
}
|
|
84
|
+
const keyMaterial = await crypto.subtle.importKey('raw', new Uint8Array(password), 'PBKDF2', false, ['deriveBits']);
|
|
85
|
+
const keyArray = await crypto.subtle.deriveBits({
|
|
86
|
+
name: 'PBKDF2',
|
|
87
|
+
salt: new Uint8Array(saltBytes_),
|
|
88
|
+
iterations: config.iterations,
|
|
89
|
+
hash: config.algorithm,
|
|
90
|
+
}, keyMaterial, config.hashBytes * 8);
|
|
91
|
+
const keyBytes = new Uint8Array(keyArray);
|
|
92
|
+
if (keyBytes.length !== config.hashBytes) {
|
|
93
|
+
throw new pbkdf2_1.Pbkdf2Error(pbkdf2_error_type_1.Pbkdf2ErrorType.InvalidHashLength, this.engine);
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
salt: saltBytes_,
|
|
97
|
+
hash: keyBytes,
|
|
98
|
+
iterations: config.iterations,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Derive a key using a predefined configuration profile
|
|
103
|
+
* @param password The password to derive a key from
|
|
104
|
+
* @param profile The configuration profile to use
|
|
105
|
+
* @param salt Optional salt (will be randomly generated if not provided)
|
|
106
|
+
* @returns Object containing the derived key, salt, and iteration count
|
|
107
|
+
*/
|
|
108
|
+
async deriveKeyFromPasswordWithProfileAsync(password, profile, salt) {
|
|
109
|
+
const config = this.getProfileConfig(profile);
|
|
110
|
+
return await this.deriveKeyFromPasswordAsync(password, salt, config.iterations, config.saltBytes, config.hashBytes, config.algorithm);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.Pbkdf2Service = Pbkdf2Service;
|
|
114
|
+
//# sourceMappingURL=pbkdf2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pbkdf2.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/services/pbkdf2.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A simple and fast XOR cipher for obfuscating data in memory for browser environments.
|
|
3
|
+
* This is not a substitute for strong cryptography but provides a lightweight way
|
|
4
|
+
* to prevent sensitive data from being stored in plaintext in memory.
|
|
5
|
+
*/
|
|
6
|
+
export declare class XorService {
|
|
7
|
+
/**
|
|
8
|
+
* Encrypts or decrypts data using a simple XOR cipher.
|
|
9
|
+
* The key is XORed with the data. The same function is used for
|
|
10
|
+
* both encryption and decryption.
|
|
11
|
+
*
|
|
12
|
+
* @param data The data to process.
|
|
13
|
+
* @param key The key to use for the XOR operation.
|
|
14
|
+
* @returns A new Uint8Array containing the result of the XOR operation.
|
|
15
|
+
*/
|
|
16
|
+
static xor(data: Uint8Array, key: Uint8Array): Uint8Array;
|
|
17
|
+
/**
|
|
18
|
+
* Generates a random key of a specified length.
|
|
19
|
+
* @param length The length of the key in bytes.
|
|
20
|
+
* @returns A Uint8Array containing the random key.
|
|
21
|
+
* @throws Error if crypto API is not available.
|
|
22
|
+
*/
|
|
23
|
+
static generateKey(length: number): Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* Helper method to convert a string to a Uint8Array.
|
|
26
|
+
* @param str The string to convert.
|
|
27
|
+
* @returns A Uint8Array representation of the string.
|
|
28
|
+
*/
|
|
29
|
+
static stringToBytes(str: string): Uint8Array;
|
|
30
|
+
/**
|
|
31
|
+
* Helper method to convert a Uint8Array to a string.
|
|
32
|
+
* @param bytes The Uint8Array to convert.
|
|
33
|
+
* @returns A string representation of the Uint8Array.
|
|
34
|
+
*/
|
|
35
|
+
static bytesToString(bytes: Uint8Array): string;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=xor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xor.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/services/xor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,UAAU;IACrB;;;;;;;;OAQG;WACW,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,UAAU;IAQhE;;;;;OAKG;WACW,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;IAgBrD;;;;OAIG;WACW,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU;IAKpD;;;;OAIG;WACW,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM;CAIvD"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XorService = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A simple and fast XOR cipher for obfuscating data in memory for browser environments.
|
|
6
|
+
* This is not a substitute for strong cryptography but provides a lightweight way
|
|
7
|
+
* to prevent sensitive data from being stored in plaintext in memory.
|
|
8
|
+
*/
|
|
9
|
+
class XorService {
|
|
10
|
+
/**
|
|
11
|
+
* Encrypts or decrypts data using a simple XOR cipher.
|
|
12
|
+
* The key is XORed with the data. The same function is used for
|
|
13
|
+
* both encryption and decryption.
|
|
14
|
+
*
|
|
15
|
+
* @param data The data to process.
|
|
16
|
+
* @param key The key to use for the XOR operation.
|
|
17
|
+
* @returns A new Uint8Array containing the result of the XOR operation.
|
|
18
|
+
*/
|
|
19
|
+
static xor(data, key) {
|
|
20
|
+
const result = new Uint8Array(data.length);
|
|
21
|
+
for (let i = 0; i < data.length; i++) {
|
|
22
|
+
result[i] = data[i] ^ key[i % key.length];
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generates a random key of a specified length.
|
|
28
|
+
* @param length The length of the key in bytes.
|
|
29
|
+
* @returns A Uint8Array containing the random key.
|
|
30
|
+
* @throws Error if crypto API is not available.
|
|
31
|
+
*/
|
|
32
|
+
static generateKey(length) {
|
|
33
|
+
const randomBytes = new Uint8Array(length);
|
|
34
|
+
// Check if running in a browser with crypto support
|
|
35
|
+
if (typeof window !== 'undefined' && window.crypto) {
|
|
36
|
+
window.crypto.getRandomValues(randomBytes);
|
|
37
|
+
}
|
|
38
|
+
else if (typeof crypto !== 'undefined') {
|
|
39
|
+
// For environments where crypto is global (some newer JS runtimes)
|
|
40
|
+
crypto.getRandomValues(randomBytes);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error('Crypto API not available in this environment');
|
|
44
|
+
}
|
|
45
|
+
return randomBytes;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Helper method to convert a string to a Uint8Array.
|
|
49
|
+
* @param str The string to convert.
|
|
50
|
+
* @returns A Uint8Array representation of the string.
|
|
51
|
+
*/
|
|
52
|
+
static stringToBytes(str) {
|
|
53
|
+
const encoder = new TextEncoder();
|
|
54
|
+
return encoder.encode(str);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Helper method to convert a Uint8Array to a string.
|
|
58
|
+
* @param bytes The Uint8Array to convert.
|
|
59
|
+
* @returns A string representation of the Uint8Array.
|
|
60
|
+
*/
|
|
61
|
+
static bytesToString(bytes) {
|
|
62
|
+
const decoder = new TextDecoder();
|
|
63
|
+
return decoder.decode(bytes);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.XorService = XorService;
|
|
67
|
+
//# sourceMappingURL=xor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xor.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/services/xor.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAa,UAAU;IACrB;;;;;;;;OAQG;IACI,MAAM,CAAC,GAAG,CAAC,IAAgB,EAAE,GAAe;QACjD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,WAAW,CAAC,MAAc;QACtC,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;QAE3C,oDAAoD;QACpD,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YACnD,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QAC7C,CAAC;aAAM,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YACzC,mEAAmE;YACnE,MAAM,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAC,GAAW;QACrC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,OAAO,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAC,KAAiB;QAC3C,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;CACF;AA3DD,gCA2DC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type DeepPartial<T> = {
|
|
2
|
+
[P in keyof T]?: T[P] extends (...args: any[]) => any ? T[P] : T[P] extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
3
|
+
};
|
|
4
|
+
//# sourceMappingURL=deep-partial.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-partial.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/types/deep-partial.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GACjD,CAAC,CAAC,CAAC,CAAC,GACJ,CAAC,CAAC,CAAC,CAAC,SAAS,aAAa,CAAC,MAAM,CAAC,CAAC,GACnC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAC7B,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GAC3B,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GACrB,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GACnB,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACjB,CAAC,CAAC,CAAC,CAAC;CACT,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-partial.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/types/deep-partial.ts"],"names":[],"mappings":""}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Brand } from 'ts-brand';
|
|
2
2
|
import { GuidBrandType } from './enumerations';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* GUID stored as a BigInt
|
|
6
5
|
*/
|
|
@@ -20,18 +19,13 @@ export type Base64Guid = Brand<string, 'GuidV4', GuidBrandType.Base64Guid>;
|
|
|
20
19
|
/**
|
|
21
20
|
* GUID stored as a raw buffer
|
|
22
21
|
*/
|
|
23
|
-
export type RawGuidUint8Array = Uint8Array &
|
|
24
|
-
Brand<Uint8Array, 'GuidV4', GuidBrandType.RawGuidUint8Array>;
|
|
25
|
-
|
|
26
|
-
// Placeholder GUID types for cross-project compatibility
|
|
22
|
+
export type RawGuidUint8Array = Uint8Array & Brand<Uint8Array, 'GuidV4', GuidBrandType.RawGuidUint8Array>;
|
|
27
23
|
export type BinaryGuid = Uint8Array;
|
|
28
24
|
export type HexGuid = string;
|
|
29
25
|
export type ShortGuid = string;
|
|
30
|
-
|
|
31
|
-
export type
|
|
32
|
-
Brand<Uint8Array, 'SignatureArray'>;
|
|
33
|
-
export type ChecksumUint8Array = Uint8Array &
|
|
34
|
-
Brand<Uint8Array, 'Sha3Checksum', 'ChecksumArray'>;
|
|
26
|
+
export type SignatureUint8Array = Uint8Array & Brand<Uint8Array, 'SignatureArray'>;
|
|
27
|
+
export type ChecksumUint8Array = Uint8Array & Brand<Uint8Array, 'Sha3Checksum', 'ChecksumArray'>;
|
|
35
28
|
export type SignatureString = string & Brand<string, 'SignatureString'>;
|
|
36
29
|
export type HexString = Brand<string, 'HexString'>;
|
|
37
30
|
export type ChecksumString = Brand<HexString, 'Sha3Checksum', 'ChecksumString'>;
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-ecies-lib/src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;AAC3E;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;AAC7E;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;AAC/E;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;AAC3E;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,UAAU,GACxC,KAAK,CAAC,UAAU,EAAE,QAAQ,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;AAG/D,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC;AACpC,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAC7B,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAC1C,KAAK,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;AACtC,MAAM,MAAM,kBAAkB,GAAG,UAAU,GACzC,KAAK,CAAC,UAAU,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;AACrD,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AACxE,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AACnD,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,SAAS,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAC"}
|
package/src/types.js
ADDED
package/src/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-ecies-lib/src/types.ts"],"names":[],"mappings":""}
|
package/src/utils.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { LengthEncodingType } from './enumerations/length-encoding-type';
|
|
2
|
+
/**
|
|
3
|
+
* Encodes the length of the data in the buffer
|
|
4
|
+
* @param buffer The buffer to encode
|
|
5
|
+
* @returns The encoded buffer
|
|
6
|
+
*/
|
|
7
|
+
export declare function lengthEncodeData(buffer: Uint8Array): Uint8Array;
|
|
8
|
+
export declare function decodeLengthEncodedData(buffer: Uint8Array): {
|
|
9
|
+
data: Uint8Array;
|
|
10
|
+
totalLength: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function uint8ArrayToBase64(uint8Array: Uint8Array): string;
|
|
13
|
+
export declare function base64ToUint8Array(base64String: string): Uint8Array;
|
|
14
|
+
export declare function uint8ArrayToHex(uint8Array: Uint8Array): string;
|
|
15
|
+
export declare function hexToUint8Array(hexString: string): Uint8Array;
|
|
16
|
+
/**
|
|
17
|
+
* Utility functions for browser ECIES implementation
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* CRC16-CCITT implementation for data integrity checking
|
|
21
|
+
* Uses CRC16-CCITT-FALSE variant (init 0xFFFF)
|
|
22
|
+
*/
|
|
23
|
+
export declare function crc16(data: Uint8Array): Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* Convert string to Uint8Array (UTF-8 encoding)
|
|
26
|
+
*/
|
|
27
|
+
export declare function stringToUint8Array(str: string): Uint8Array;
|
|
28
|
+
/**
|
|
29
|
+
* Convert Uint8Array to string (UTF-8 decoding)
|
|
30
|
+
*/
|
|
31
|
+
export declare function uint8ArrayToString(array: Uint8Array): string;
|
|
32
|
+
/**
|
|
33
|
+
* Secure random bytes generation
|
|
34
|
+
*/
|
|
35
|
+
export declare function randomBytes(length: number): Uint8Array;
|
|
36
|
+
/**
|
|
37
|
+
* Compare two Uint8Arrays for equality
|
|
38
|
+
*/
|
|
39
|
+
export declare function arraysEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Concatenate multiple Uint8Arrays
|
|
42
|
+
*/
|
|
43
|
+
export declare function concatUint8Arrays(...arrays: Uint8Array[]): Uint8Array;
|
|
44
|
+
/**
|
|
45
|
+
* Get the length encoding type for a given length
|
|
46
|
+
* @param length The length to evaluate
|
|
47
|
+
* @returns The corresponding LengthEncodingType
|
|
48
|
+
*/
|
|
49
|
+
export declare function getLengthEncodingTypeForLength<TStringKey extends string, TLanguage extends string>(length: number | BigInt): LengthEncodingType;
|
|
50
|
+
/**
|
|
51
|
+
* Get the length encoding type for a given value
|
|
52
|
+
* @param value The value to evaluate
|
|
53
|
+
* @returns The corresponding LengthEncodingType
|
|
54
|
+
*/
|
|
55
|
+
export declare function getLengthEncodingTypeFromValue<TStringKey extends string, TLanguage extends string>(value: number): LengthEncodingType;
|
|
56
|
+
/**
|
|
57
|
+
* Safely converts BigInt to Number, throwing if value exceeds safe integer range
|
|
58
|
+
* @param value The BigInt value to convert
|
|
59
|
+
* @returns The number value
|
|
60
|
+
*/
|
|
61
|
+
export declare function safeBigIntToNumber(value: bigint): number;
|
|
62
|
+
/**
|
|
63
|
+
* Get the length in bytes for a given LengthEncodingType
|
|
64
|
+
* @param type The LengthEncodingType to evaluate
|
|
65
|
+
* @returns The length in bytes
|
|
66
|
+
*/
|
|
67
|
+
export declare function getLengthForLengthType<TStringKey extends string, TLanguage extends string>(type: LengthEncodingType): number;
|
|
68
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-ecies-lib/src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAKzE;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAyB/D;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,UAAU,GAAG;IAC3D,IAAI,EAAE,UAAU,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB,CA+DA;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAMjE;AAED,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,UAAU,CAQnE;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAI9D;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CAgB7D;AAED;;GAEG;AAEH;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAoBlD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAE1D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE5D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAEtD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAOjE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,GAAG,UAAU,CASrE;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC5C,UAAU,SAAS,MAAM,EACzB,SAAS,SAAS,MAAM,EACxB,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,kBAAkB,CAqC7C;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC5C,UAAU,SAAS,MAAM,EACzB,SAAS,SAAS,MAAM,EACxB,KAAK,EAAE,MAAM,GAAG,kBAAkB,CAUnC;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQxD;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,SAAS,MAAM,EACzB,SAAS,SAAS,MAAM,EACxB,IAAI,EAAE,kBAAkB,GAAG,MAAM,CAgBlC"}
|
package/src/utils.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lengthEncodeData = lengthEncodeData;
|
|
4
|
+
exports.decodeLengthEncodedData = decodeLengthEncodedData;
|
|
5
|
+
exports.uint8ArrayToBase64 = uint8ArrayToBase64;
|
|
6
|
+
exports.base64ToUint8Array = base64ToUint8Array;
|
|
7
|
+
exports.uint8ArrayToHex = uint8ArrayToHex;
|
|
8
|
+
exports.hexToUint8Array = hexToUint8Array;
|
|
9
|
+
exports.crc16 = crc16;
|
|
10
|
+
exports.stringToUint8Array = stringToUint8Array;
|
|
11
|
+
exports.uint8ArrayToString = uint8ArrayToString;
|
|
12
|
+
exports.randomBytes = randomBytes;
|
|
13
|
+
exports.arraysEqual = arraysEqual;
|
|
14
|
+
exports.concatUint8Arrays = concatUint8Arrays;
|
|
15
|
+
exports.getLengthEncodingTypeForLength = getLengthEncodingTypeForLength;
|
|
16
|
+
exports.getLengthEncodingTypeFromValue = getLengthEncodingTypeFromValue;
|
|
17
|
+
exports.safeBigIntToNumber = safeBigIntToNumber;
|
|
18
|
+
exports.getLengthForLengthType = getLengthForLengthType;
|
|
19
|
+
const length_encoding_type_1 = require("./enumerations/length-encoding-type");
|
|
20
|
+
const length_error_type_1 = require("./enumerations/length-error-type");
|
|
21
|
+
const errors_1 = require("./errors");
|
|
22
|
+
const i18n_setup_1 = require("./i18n-setup");
|
|
23
|
+
/**
|
|
24
|
+
* Encodes the length of the data in the buffer
|
|
25
|
+
* @param buffer The buffer to encode
|
|
26
|
+
* @returns The encoded buffer
|
|
27
|
+
*/
|
|
28
|
+
function lengthEncodeData(buffer) {
|
|
29
|
+
const lengthType = getLengthEncodingTypeForLength(buffer.length);
|
|
30
|
+
const lengthTypeSize = getLengthForLengthType(lengthType);
|
|
31
|
+
const result = new Uint8Array(1 + lengthTypeSize + buffer.length);
|
|
32
|
+
const view = new DataView(result.buffer);
|
|
33
|
+
view.setUint8(0, lengthType);
|
|
34
|
+
switch (lengthType) {
|
|
35
|
+
case length_encoding_type_1.LengthEncodingType.UInt8:
|
|
36
|
+
view.setUint8(1, buffer.length);
|
|
37
|
+
break;
|
|
38
|
+
case length_encoding_type_1.LengthEncodingType.UInt16:
|
|
39
|
+
view.setUint16(1, buffer.length, false); // big-endian
|
|
40
|
+
break;
|
|
41
|
+
case length_encoding_type_1.LengthEncodingType.UInt32:
|
|
42
|
+
view.setUint32(1, buffer.length, false); // big-endian
|
|
43
|
+
break;
|
|
44
|
+
case length_encoding_type_1.LengthEncodingType.UInt64:
|
|
45
|
+
view.setBigUint64(1, BigInt(buffer.length), false); // big-endian
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
result.set(buffer, 1 + lengthTypeSize);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
function decodeLengthEncodedData(buffer) {
|
|
52
|
+
if (buffer.length < 1) {
|
|
53
|
+
throw new errors_1.LengthError(length_error_type_1.LengthErrorType.LengthIsTooShort, (0, i18n_setup_1.getEciesI18nEngine)());
|
|
54
|
+
}
|
|
55
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
56
|
+
const lengthType = getLengthEncodingTypeFromValue(view.getUint8(0));
|
|
57
|
+
const lengthTypeSize = getLengthForLengthType(lengthType);
|
|
58
|
+
if (buffer.length < 1 + lengthTypeSize) {
|
|
59
|
+
throw new errors_1.LengthError(length_error_type_1.LengthErrorType.LengthIsTooShort, (0, i18n_setup_1.getEciesI18nEngine)());
|
|
60
|
+
}
|
|
61
|
+
let length;
|
|
62
|
+
switch (lengthType) {
|
|
63
|
+
case length_encoding_type_1.LengthEncodingType.UInt8:
|
|
64
|
+
length = view.getUint8(1);
|
|
65
|
+
break;
|
|
66
|
+
case length_encoding_type_1.LengthEncodingType.UInt16:
|
|
67
|
+
length = view.getUint16(1, false); // big-endian
|
|
68
|
+
break;
|
|
69
|
+
case length_encoding_type_1.LengthEncodingType.UInt32:
|
|
70
|
+
length = view.getUint32(1, false); // big-endian
|
|
71
|
+
break;
|
|
72
|
+
case length_encoding_type_1.LengthEncodingType.UInt64:
|
|
73
|
+
length = view.getBigUint64(1, false); // big-endian
|
|
74
|
+
if (length.valueOf() > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
75
|
+
throw new errors_1.LengthError(length_error_type_1.LengthErrorType.LengthIsTooLong, (0, i18n_setup_1.getEciesI18nEngine)());
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
default:
|
|
79
|
+
throw new errors_1.LengthError(length_error_type_1.LengthErrorType.LengthIsInvalidType, (0, i18n_setup_1.getEciesI18nEngine)());
|
|
80
|
+
}
|
|
81
|
+
const totalLength = 1 + lengthTypeSize + Number(length);
|
|
82
|
+
if (totalLength > buffer.length) {
|
|
83
|
+
throw new errors_1.LengthError(length_error_type_1.LengthErrorType.LengthIsTooShort, (0, i18n_setup_1.getEciesI18nEngine)());
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
data: buffer.subarray(1 + lengthTypeSize, totalLength),
|
|
87
|
+
totalLength,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function uint8ArrayToBase64(uint8Array) {
|
|
91
|
+
let binaryString = '';
|
|
92
|
+
for (let i = 0; i < uint8Array.length; i++) {
|
|
93
|
+
binaryString += String.fromCharCode(uint8Array[i]);
|
|
94
|
+
}
|
|
95
|
+
return btoa(binaryString);
|
|
96
|
+
}
|
|
97
|
+
function base64ToUint8Array(base64String) {
|
|
98
|
+
const binaryString = atob(base64String);
|
|
99
|
+
const len = binaryString.length;
|
|
100
|
+
const bytes = new Uint8Array(len);
|
|
101
|
+
for (let i = 0; i < len; i++) {
|
|
102
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
103
|
+
}
|
|
104
|
+
return bytes;
|
|
105
|
+
}
|
|
106
|
+
function uint8ArrayToHex(uint8Array) {
|
|
107
|
+
return Array.from(uint8Array)
|
|
108
|
+
.map((byte) => byte.toString(16).padStart(2, '0'))
|
|
109
|
+
.join('');
|
|
110
|
+
}
|
|
111
|
+
function hexToUint8Array(hexString) {
|
|
112
|
+
if (!hexString || typeof hexString !== 'string') {
|
|
113
|
+
throw new Error('Invalid hex string');
|
|
114
|
+
}
|
|
115
|
+
if (hexString.length % 2 !== 0) {
|
|
116
|
+
throw new Error('Hex string must have even length');
|
|
117
|
+
}
|
|
118
|
+
if (!/^[0-9a-fA-F]*$/.test(hexString)) {
|
|
119
|
+
throw new Error('Hex string contains invalid characters');
|
|
120
|
+
}
|
|
121
|
+
const len = hexString.length;
|
|
122
|
+
const bytes = new Uint8Array(len / 2);
|
|
123
|
+
for (let i = 0; i < len; i += 2) {
|
|
124
|
+
bytes[i / 2] = parseInt(hexString.substring(i, i + 2), 16);
|
|
125
|
+
}
|
|
126
|
+
return bytes;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Utility functions for browser ECIES implementation
|
|
130
|
+
*/
|
|
131
|
+
/**
|
|
132
|
+
* CRC16-CCITT implementation for data integrity checking
|
|
133
|
+
* Uses CRC16-CCITT-FALSE variant (init 0xFFFF)
|
|
134
|
+
*/
|
|
135
|
+
function crc16(data) {
|
|
136
|
+
let crc = 0xffff; // Initial value for CRC16-CCITT-FALSE
|
|
137
|
+
const polynomial = 0x1021; // CRC16-CCITT polynomial
|
|
138
|
+
for (let i = 0; i < data.length; i++) {
|
|
139
|
+
crc ^= data[i] << 8;
|
|
140
|
+
for (let j = 0; j < 8; j++) {
|
|
141
|
+
if (crc & 0x8000) {
|
|
142
|
+
crc = (crc << 1) ^ polynomial;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
crc = crc << 1;
|
|
146
|
+
}
|
|
147
|
+
crc &= 0xffff; // Keep it 16-bit
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const result = new Uint8Array(2);
|
|
151
|
+
result[0] = (crc >>> 8) & 0xff; // Big-endian
|
|
152
|
+
result[1] = crc & 0xff;
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Convert string to Uint8Array (UTF-8 encoding)
|
|
157
|
+
*/
|
|
158
|
+
function stringToUint8Array(str) {
|
|
159
|
+
return new TextEncoder().encode(str);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Convert Uint8Array to string (UTF-8 decoding)
|
|
163
|
+
*/
|
|
164
|
+
function uint8ArrayToString(array) {
|
|
165
|
+
return new TextDecoder().decode(array);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Secure random bytes generation
|
|
169
|
+
*/
|
|
170
|
+
function randomBytes(length) {
|
|
171
|
+
return crypto.getRandomValues(new Uint8Array(length));
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Compare two Uint8Arrays for equality
|
|
175
|
+
*/
|
|
176
|
+
function arraysEqual(a, b) {
|
|
177
|
+
if (a.length !== b.length)
|
|
178
|
+
return false;
|
|
179
|
+
let result = 0;
|
|
180
|
+
for (let i = 0; i < a.length; i++) {
|
|
181
|
+
result |= a[i] ^ b[i];
|
|
182
|
+
}
|
|
183
|
+
return result === 0;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Concatenate multiple Uint8Arrays
|
|
187
|
+
*/
|
|
188
|
+
function concatUint8Arrays(...arrays) {
|
|
189
|
+
const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
|
|
190
|
+
const result = new Uint8Array(totalLength);
|
|
191
|
+
let offset = 0;
|
|
192
|
+
for (const array of arrays) {
|
|
193
|
+
result.set(array, offset);
|
|
194
|
+
offset += array.length;
|
|
195
|
+
}
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Get the length encoding type for a given length
|
|
200
|
+
* @param length The length to evaluate
|
|
201
|
+
* @returns The corresponding LengthEncodingType
|
|
202
|
+
*/
|
|
203
|
+
function getLengthEncodingTypeForLength(length) {
|
|
204
|
+
if (typeof length === 'number') {
|
|
205
|
+
if (length < 256) {
|
|
206
|
+
return length_encoding_type_1.LengthEncodingType.UInt8;
|
|
207
|
+
}
|
|
208
|
+
else if (length < 65536) {
|
|
209
|
+
return length_encoding_type_1.LengthEncodingType.UInt16;
|
|
210
|
+
}
|
|
211
|
+
else if (length < 4294967296) {
|
|
212
|
+
return length_encoding_type_1.LengthEncodingType.UInt32;
|
|
213
|
+
}
|
|
214
|
+
else if (length < Number.MAX_SAFE_INTEGER) {
|
|
215
|
+
return length_encoding_type_1.LengthEncodingType.UInt64;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
throw new errors_1.LengthError(length_error_type_1.LengthErrorType.LengthIsTooLong, (0, i18n_setup_1.getEciesI18nEngine)());
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else if (typeof length === 'bigint') {
|
|
222
|
+
if (length < 256n) {
|
|
223
|
+
return length_encoding_type_1.LengthEncodingType.UInt8;
|
|
224
|
+
}
|
|
225
|
+
else if (length < 65536n) {
|
|
226
|
+
return length_encoding_type_1.LengthEncodingType.UInt16;
|
|
227
|
+
}
|
|
228
|
+
else if (length < 4294967296n) {
|
|
229
|
+
return length_encoding_type_1.LengthEncodingType.UInt32;
|
|
230
|
+
}
|
|
231
|
+
else if (length < 18446744073709551616n) {
|
|
232
|
+
return length_encoding_type_1.LengthEncodingType.UInt64;
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
throw new errors_1.LengthError(length_error_type_1.LengthErrorType.LengthIsTooLong, (0, i18n_setup_1.getEciesI18nEngine)());
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
throw new errors_1.LengthError(length_error_type_1.LengthErrorType.LengthIsInvalidType, (0, i18n_setup_1.getEciesI18nEngine)());
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Get the length encoding type for a given value
|
|
244
|
+
* @param value The value to evaluate
|
|
245
|
+
* @returns The corresponding LengthEncodingType
|
|
246
|
+
*/
|
|
247
|
+
function getLengthEncodingTypeFromValue(value) {
|
|
248
|
+
for (const length of Object.values(length_encoding_type_1.LengthEncodingType)) {
|
|
249
|
+
if (length === value) {
|
|
250
|
+
return length;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
throw new errors_1.LengthError(length_error_type_1.LengthErrorType.LengthIsInvalidType, (0, i18n_setup_1.getEciesI18nEngine)());
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Safely converts BigInt to Number, throwing if value exceeds safe integer range
|
|
257
|
+
* @param value The BigInt value to convert
|
|
258
|
+
* @returns The number value
|
|
259
|
+
*/
|
|
260
|
+
function safeBigIntToNumber(value) {
|
|
261
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
262
|
+
throw new Error('Value exceeds safe integer range');
|
|
263
|
+
}
|
|
264
|
+
if (value < BigInt(Number.MIN_SAFE_INTEGER)) {
|
|
265
|
+
throw new Error('Value below safe integer range');
|
|
266
|
+
}
|
|
267
|
+
return Number(value);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Get the length in bytes for a given LengthEncodingType
|
|
271
|
+
* @param type The LengthEncodingType to evaluate
|
|
272
|
+
* @returns The length in bytes
|
|
273
|
+
*/
|
|
274
|
+
function getLengthForLengthType(type) {
|
|
275
|
+
switch (type) {
|
|
276
|
+
case length_encoding_type_1.LengthEncodingType.UInt8:
|
|
277
|
+
return 1;
|
|
278
|
+
case length_encoding_type_1.LengthEncodingType.UInt16:
|
|
279
|
+
return 2;
|
|
280
|
+
case length_encoding_type_1.LengthEncodingType.UInt32:
|
|
281
|
+
return 4;
|
|
282
|
+
case length_encoding_type_1.LengthEncodingType.UInt64:
|
|
283
|
+
return 8;
|
|
284
|
+
default:
|
|
285
|
+
throw new errors_1.LengthError(length_error_type_1.LengthErrorType.LengthIsInvalidType, (0, i18n_setup_1.getEciesI18nEngine)());
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
//# sourceMappingURL=utils.js.map
|