@digitaldefiance/ecies-lib 1.1.22 → 1.1.24
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 +9 -0
- package/package.json +13 -33
- package/src/constants.ts +474 -0
- package/src/email-string.ts +83 -0
- package/src/enumerations/ecies-encryption-type.ts +102 -0
- package/src/enumerations/ecies-error-type.ts +31 -0
- package/src/enumerations/ecies-string-key.ts +108 -0
- package/src/enumerations/guid-brand-type.ts +26 -0
- package/src/enumerations/guid-error-type.ts +6 -0
- package/{dist/enumerations/index.d.ts → src/enumerations/index.ts} +0 -1
- package/src/enumerations/invalid-email-type.ts +5 -0
- package/src/enumerations/length-encoding-type.ts +6 -0
- package/src/enumerations/length-error-type.ts +5 -0
- package/src/enumerations/member-error-type.ts +106 -0
- package/{dist/enumerations/member-type.d.ts → src/enumerations/member-type.ts} +7 -6
- package/src/enumerations/password-login-error-type.ts +4 -0
- package/src/enumerations/pbkdf2-error-type.ts +5 -0
- package/src/enumerations/pbkdf2-profile.ts +5 -0
- package/src/enumerations/secure-storage-error-type.ts +5 -0
- package/src/errors/disposed.ts +15 -0
- package/src/errors/ecies.ts +34 -0
- package/src/errors/guid.ts +34 -0
- package/{dist/errors/index.d.ts → src/errors/index.ts} +0 -1
- package/src/errors/invalid-email.ts +11 -0
- package/src/errors/length.ts +11 -0
- package/src/errors/member.ts +12 -0
- package/src/errors/pbkdf2.ts +12 -0
- package/src/errors/secure-storage.ts +13 -0
- package/src/errors/simple-ecies.ts +18 -0
- package/src/errors/simple-test-error.ts +6 -0
- package/src/guid.ts +800 -0
- package/src/i18n-setup.ts +1312 -0
- package/{dist/index.d.ts → src/index.ts} +0 -1
- package/src/interfaces/checksum-config.ts +4 -0
- package/src/interfaces/checksum-consts.ts +13 -0
- package/src/interfaces/constants.ts +48 -0
- package/src/interfaces/ecies-config.ts +8 -0
- package/src/interfaces/ecies-consts.ts +70 -0
- package/src/interfaces/ecies-file-service.ts +6 -0
- package/src/interfaces/guid.ts +53 -0
- package/{dist/interfaces/index.d.ts → src/interfaces/index.ts} +0 -1
- package/src/interfaces/library-error.ts +23 -0
- package/src/interfaces/member-operational.ts +54 -0
- package/{dist/interfaces/member-storage.d.ts → src/interfaces/member-storage.ts} +11 -10
- package/{dist/interfaces/member-with-mnemonic.d.ts → src/interfaces/member-with-mnemonic.ts} +3 -3
- package/src/interfaces/pbkdf2-config.ts +6 -0
- package/src/interfaces/pbkdf2-consts.ts +10 -0
- package/src/interfaces/pbkdf2-result.ts +5 -0
- package/src/member.ts +429 -0
- package/{dist/pbkdf2-profiles.d.ts → src/pbkdf2-profiles.ts} +2 -2
- package/src/phone-number.ts +18 -0
- package/src/regexes.ts +10 -0
- package/src/secure-buffer.ts +183 -0
- package/src/secure-string.ts +229 -0
- package/src/services/aes-gcm.ts +177 -0
- package/src/services/ecies/README.md +147 -0
- package/src/services/ecies/crypto-core.ts +180 -0
- package/src/services/ecies/example.ts +185 -0
- package/src/services/ecies/file.ts +167 -0
- package/{dist/services/ecies/index.d.ts → src/services/ecies/index.ts} +3 -1
- package/src/services/ecies/integration.ts +241 -0
- package/src/services/ecies/interfaces.ts +59 -0
- package/src/services/ecies/manual-test.ts +219 -0
- package/src/services/ecies/multi-recipient.ts +394 -0
- package/src/services/ecies/service.ts +317 -0
- package/src/services/ecies/signature.ts +93 -0
- package/src/services/ecies/single-recipient.ts +340 -0
- package/{dist/services/index.d.ts → src/services/index.ts} +0 -1
- package/src/services/password-login.ts +228 -0
- package/src/services/pbkdf2.ts +172 -0
- package/src/services/xor.ts +65 -0
- package/src/types/deep-partial.ts +11 -0
- package/{dist/types.d.ts → src/types.ts} +10 -4
- package/src/utils.ts +331 -0
- package/dist/constants.d.ts +0 -46
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -358
- package/dist/constants.js.map +0 -1
- package/dist/email-string.d.ts +0 -42
- package/dist/email-string.d.ts.map +0 -1
- package/dist/email-string.js +0 -75
- package/dist/email-string.js.map +0 -1
- package/dist/enumerations/ecies-encryption-type.d.ts +0 -15
- package/dist/enumerations/ecies-encryption-type.d.ts.map +0 -1
- package/dist/enumerations/ecies-encryption-type.js +0 -71
- package/dist/enumerations/ecies-encryption-type.js.map +0 -1
- package/dist/enumerations/ecies-error-type.d.ts +0 -32
- package/dist/enumerations/ecies-error-type.d.ts.map +0 -1
- package/dist/enumerations/ecies-error-type.js +0 -36
- package/dist/enumerations/ecies-error-type.js.map +0 -1
- package/dist/enumerations/ecies-string-key.d.ts +0 -94
- package/dist/enumerations/ecies-string-key.d.ts.map +0 -1
- package/dist/enumerations/ecies-string-key.js +0 -103
- package/dist/enumerations/ecies-string-key.js.map +0 -1
- package/dist/enumerations/guid-brand-type.d.ts +0 -27
- package/dist/enumerations/guid-brand-type.d.ts.map +0 -1
- package/dist/enumerations/guid-brand-type.js +0 -31
- package/dist/enumerations/guid-brand-type.js.map +0 -1
- package/dist/enumerations/guid-error-type.d.ts +0 -7
- package/dist/enumerations/guid-error-type.d.ts.map +0 -1
- package/dist/enumerations/guid-error-type.js +0 -11
- package/dist/enumerations/guid-error-type.js.map +0 -1
- package/dist/enumerations/index.d.ts.map +0 -1
- package/dist/enumerations/index.js +0 -31
- package/dist/enumerations/index.js.map +0 -1
- package/dist/enumerations/invalid-email-type.d.ts +0 -6
- package/dist/enumerations/invalid-email-type.d.ts.map +0 -1
- package/dist/enumerations/invalid-email-type.js +0 -10
- package/dist/enumerations/invalid-email-type.js.map +0 -1
- package/dist/enumerations/length-encoding-type.d.ts +0 -7
- package/dist/enumerations/length-encoding-type.d.ts.map +0 -1
- package/dist/enumerations/length-encoding-type.js +0 -11
- package/dist/enumerations/length-encoding-type.js.map +0 -1
- package/dist/enumerations/length-error-type.d.ts +0 -6
- package/dist/enumerations/length-error-type.d.ts.map +0 -1
- package/dist/enumerations/length-error-type.js +0 -10
- package/dist/enumerations/length-error-type.js.map +0 -1
- package/dist/enumerations/member-error-type.d.ts +0 -87
- package/dist/enumerations/member-error-type.d.ts.map +0 -1
- package/dist/enumerations/member-error-type.js +0 -91
- package/dist/enumerations/member-error-type.js.map +0 -1
- package/dist/enumerations/member-type.d.ts.map +0 -1
- package/dist/enumerations/member-type.js +0 -19
- package/dist/enumerations/member-type.js.map +0 -1
- package/dist/enumerations/password-login-error-type.d.ts +0 -5
- package/dist/enumerations/password-login-error-type.d.ts.map +0 -1
- package/dist/enumerations/password-login-error-type.js +0 -9
- package/dist/enumerations/password-login-error-type.js.map +0 -1
- package/dist/enumerations/pbkdf2-error-type.d.ts +0 -6
- package/dist/enumerations/pbkdf2-error-type.d.ts.map +0 -1
- package/dist/enumerations/pbkdf2-error-type.js +0 -10
- package/dist/enumerations/pbkdf2-error-type.js.map +0 -1
- package/dist/enumerations/pbkdf2-profile.d.ts +0 -6
- package/dist/enumerations/pbkdf2-profile.d.ts.map +0 -1
- package/dist/enumerations/pbkdf2-profile.js +0 -10
- package/dist/enumerations/pbkdf2-profile.js.map +0 -1
- package/dist/enumerations/secure-storage-error-type.d.ts +0 -6
- package/dist/enumerations/secure-storage-error-type.d.ts.map +0 -1
- package/dist/enumerations/secure-storage-error-type.js +0 -10
- package/dist/enumerations/secure-storage-error-type.js.map +0 -1
- package/dist/errors/disposed.d.ts +0 -4
- package/dist/errors/disposed.d.ts.map +0 -1
- package/dist/errors/disposed.js +0 -20
- package/dist/errors/disposed.js.map +0 -1
- package/dist/errors/ecies.d.ts +0 -7
- package/dist/errors/ecies.d.ts.map +0 -1
- package/dist/errors/ecies.js +0 -15
- package/dist/errors/ecies.js.map +0 -1
- package/dist/errors/guid.d.ts +0 -15
- package/dist/errors/guid.d.ts.map +0 -1
- package/dist/errors/guid.js +0 -25
- package/dist/errors/guid.js.map +0 -1
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js +0 -25
- package/dist/errors/index.js.map +0 -1
- package/dist/errors/invalid-email.d.ts +0 -7
- package/dist/errors/invalid-email.d.ts.map +0 -1
- package/dist/errors/invalid-email.js +0 -13
- package/dist/errors/invalid-email.js.map +0 -1
- package/dist/errors/length.d.ts +0 -7
- package/dist/errors/length.d.ts.map +0 -1
- package/dist/errors/length.js +0 -13
- package/dist/errors/length.js.map +0 -1
- package/dist/errors/member.d.ts +0 -7
- package/dist/errors/member.d.ts.map +0 -1
- package/dist/errors/member.js +0 -13
- package/dist/errors/member.js.map +0 -1
- package/dist/errors/pbkdf2.d.ts +0 -7
- package/dist/errors/pbkdf2.d.ts.map +0 -1
- package/dist/errors/pbkdf2.js +0 -13
- package/dist/errors/pbkdf2.js.map +0 -1
- package/dist/errors/secure-storage.d.ts +0 -7
- package/dist/errors/secure-storage.d.ts.map +0 -1
- package/dist/errors/secure-storage.js +0 -14
- package/dist/errors/secure-storage.js.map +0 -1
- package/dist/errors/simple-ecies.d.ts +0 -6
- package/dist/errors/simple-ecies.d.ts.map +0 -1
- package/dist/errors/simple-ecies.js +0 -14
- package/dist/errors/simple-ecies.js.map +0 -1
- package/dist/errors/simple-test-error.d.ts +0 -4
- package/dist/errors/simple-test-error.d.ts.map +0 -1
- package/dist/errors/simple-test-error.js +0 -11
- package/dist/errors/simple-test-error.js.map +0 -1
- package/dist/guid.d.ts +0 -153
- package/dist/guid.d.ts.map +0 -1
- package/dist/guid.js +0 -647
- package/dist/guid.js.map +0 -1
- package/dist/i18n-setup.d.ts +0 -27
- package/dist/i18n-setup.d.ts.map +0 -1
- package/dist/i18n-setup.js +0 -851
- package/dist/i18n-setup.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -32
- package/dist/index.js.map +0 -1
- package/dist/interfaces/checksum-config.d.ts +0 -5
- package/dist/interfaces/checksum-config.d.ts.map +0 -1
- package/dist/interfaces/checksum-config.js +0 -3
- package/dist/interfaces/checksum-config.js.map +0 -1
- package/dist/interfaces/checksum-consts.d.ts +0 -11
- package/dist/interfaces/checksum-consts.d.ts.map +0 -1
- package/dist/interfaces/checksum-consts.js +0 -3
- package/dist/interfaces/checksum-consts.js.map +0 -1
- package/dist/interfaces/constants.d.ts +0 -45
- package/dist/interfaces/constants.d.ts.map +0 -1
- package/dist/interfaces/constants.js +0 -3
- package/dist/interfaces/constants.js.map +0 -1
- package/dist/interfaces/ecies-config.d.ts +0 -9
- package/dist/interfaces/ecies-config.d.ts.map +0 -1
- package/dist/interfaces/ecies-config.js +0 -3
- package/dist/interfaces/ecies-config.js.map +0 -1
- package/dist/interfaces/ecies-consts.d.ts +0 -58
- package/dist/interfaces/ecies-consts.d.ts.map +0 -1
- package/dist/interfaces/ecies-consts.js +0 -3
- package/dist/interfaces/ecies-consts.js.map +0 -1
- package/dist/interfaces/ecies-file-service.d.ts +0 -7
- package/dist/interfaces/ecies-file-service.d.ts.map +0 -1
- package/dist/interfaces/ecies-file-service.js +0 -3
- package/dist/interfaces/ecies-file-service.js.map +0 -1
- package/dist/interfaces/guid.d.ts +0 -45
- package/dist/interfaces/guid.d.ts.map +0 -1
- package/dist/interfaces/guid.js +0 -3
- package/dist/interfaces/guid.js.map +0 -1
- package/dist/interfaces/index.d.ts.map +0 -1
- package/dist/interfaces/index.js +0 -30
- package/dist/interfaces/index.js.map +0 -1
- package/dist/interfaces/library-error.d.ts +0 -23
- package/dist/interfaces/library-error.d.ts.map +0 -1
- package/dist/interfaces/library-error.js +0 -3
- package/dist/interfaces/library-error.js.map +0 -1
- package/dist/interfaces/member-operational.d.ts +0 -40
- package/dist/interfaces/member-operational.d.ts.map +0 -1
- package/dist/interfaces/member-operational.js +0 -3
- package/dist/interfaces/member-operational.js.map +0 -1
- package/dist/interfaces/member-storage.d.ts.map +0 -1
- package/dist/interfaces/member-storage.js +0 -3
- package/dist/interfaces/member-storage.js.map +0 -1
- package/dist/interfaces/member-with-mnemonic.d.ts.map +0 -1
- package/dist/interfaces/member-with-mnemonic.js +0 -3
- package/dist/interfaces/member-with-mnemonic.js.map +0 -1
- package/dist/interfaces/pbkdf2-config.d.ts +0 -7
- package/dist/interfaces/pbkdf2-config.d.ts.map +0 -1
- package/dist/interfaces/pbkdf2-config.js +0 -3
- package/dist/interfaces/pbkdf2-config.js.map +0 -1
- package/dist/interfaces/pbkdf2-consts.d.ts +0 -9
- package/dist/interfaces/pbkdf2-consts.d.ts.map +0 -1
- package/dist/interfaces/pbkdf2-consts.js +0 -3
- package/dist/interfaces/pbkdf2-consts.js.map +0 -1
- package/dist/interfaces/pbkdf2-result.d.ts +0 -6
- package/dist/interfaces/pbkdf2-result.d.ts.map +0 -1
- package/dist/interfaces/pbkdf2-result.js +0 -3
- package/dist/interfaces/pbkdf2-result.js.map +0 -1
- package/dist/member.d.ts +0 -66
- package/dist/member.d.ts.map +0 -1
- package/dist/member.js +0 -271
- package/dist/member.js.map +0 -1
- package/dist/pbkdf2-profiles.d.ts.map +0 -1
- package/dist/pbkdf2-profiles.js +0 -3
- package/dist/pbkdf2-profiles.js.map +0 -1
- package/dist/phone-number.d.ts +0 -6
- package/dist/phone-number.d.ts.map +0 -1
- package/dist/phone-number.js +0 -22
- package/dist/phone-number.js.map +0 -1
- package/dist/regexes.d.ts +0 -7
- package/dist/regexes.d.ts.map +0 -1
- package/dist/regexes.js +0 -10
- package/dist/regexes.js.map +0 -1
- package/dist/secure-buffer.d.ts +0 -38
- package/dist/secure-buffer.d.ts.map +0 -1
- package/dist/secure-buffer.js +0 -168
- package/dist/secure-buffer.js.map +0 -1
- package/dist/secure-string.d.ts +0 -39
- package/dist/secure-string.d.ts.map +0 -1
- package/dist/secure-string.js +0 -195
- package/dist/secure-string.js.map +0 -1
- package/dist/services/aes-gcm.d.ts +0 -57
- package/dist/services/aes-gcm.d.ts.map +0 -1
- package/dist/services/aes-gcm.js +0 -111
- package/dist/services/aes-gcm.js.map +0 -1
- package/dist/services/ecies/crypto-core.d.ts +0 -51
- package/dist/services/ecies/crypto-core.d.ts.map +0 -1
- package/dist/services/ecies/crypto-core.js +0 -139
- package/dist/services/ecies/crypto-core.js.map +0 -1
- package/dist/services/ecies/example.d.ts +0 -25
- package/dist/services/ecies/example.d.ts.map +0 -1
- package/dist/services/ecies/example.js +0 -128
- package/dist/services/ecies/example.js.map +0 -1
- package/dist/services/ecies/file.d.ts +0 -18
- package/dist/services/ecies/file.d.ts.map +0 -1
- package/dist/services/ecies/file.js +0 -110
- package/dist/services/ecies/file.js.map +0 -1
- package/dist/services/ecies/index.d.ts.map +0 -1
- package/dist/services/ecies/index.js +0 -57
- package/dist/services/ecies/index.js.map +0 -1
- package/dist/services/ecies/integration.d.ts +0 -59
- package/dist/services/ecies/integration.d.ts.map +0 -1
- package/dist/services/ecies/integration.js +0 -172
- package/dist/services/ecies/integration.js.map +0 -1
- package/dist/services/ecies/interfaces.d.ts +0 -51
- package/dist/services/ecies/interfaces.d.ts.map +0 -1
- package/dist/services/ecies/interfaces.js +0 -6
- package/dist/services/ecies/interfaces.js.map +0 -1
- package/dist/services/ecies/manual-test.d.ts +0 -29
- package/dist/services/ecies/manual-test.d.ts.map +0 -1
- package/dist/services/ecies/manual-test.js +0 -171
- package/dist/services/ecies/manual-test.js.map +0 -1
- package/dist/services/ecies/multi-recipient.d.ts +0 -52
- package/dist/services/ecies/multi-recipient.d.ts.map +0 -1
- package/dist/services/ecies/multi-recipient.js +0 -243
- package/dist/services/ecies/multi-recipient.js.map +0 -1
- package/dist/services/ecies/service.d.ts +0 -104
- package/dist/services/ecies/service.d.ts.map +0 -1
- package/dist/services/ecies/service.js +0 -192
- package/dist/services/ecies/service.js.map +0 -1
- package/dist/services/ecies/signature.d.ts +0 -27
- package/dist/services/ecies/signature.d.ts.map +0 -1
- package/dist/services/ecies/signature.js +0 -76
- package/dist/services/ecies/signature.js.map +0 -1
- package/dist/services/ecies/single-recipient.d.ts +0 -46
- package/dist/services/ecies/single-recipient.d.ts.map +0 -1
- package/dist/services/ecies/single-recipient.js +0 -212
- package/dist/services/ecies/single-recipient.js.map +0 -1
- package/dist/services/index.d.ts.map +0 -1
- package/dist/services/index.js +0 -22
- package/dist/services/index.js.map +0 -1
- package/dist/services/password-login.d.ts +0 -50
- package/dist/services/password-login.d.ts.map +0 -1
- package/dist/services/password-login.js +0 -120
- package/dist/services/password-login.js.map +0 -1
- package/dist/services/pbkdf2.d.ts +0 -57
- package/dist/services/pbkdf2.d.ts.map +0 -1
- package/dist/services/pbkdf2.js +0 -114
- package/dist/services/pbkdf2.js.map +0 -1
- package/dist/services/xor.d.ts +0 -37
- package/dist/services/xor.d.ts.map +0 -1
- package/dist/services/xor.js +0 -67
- package/dist/services/xor.js.map +0 -1
- package/dist/types/deep-partial.d.ts +0 -4
- package/dist/types/deep-partial.d.ts.map +0 -1
- package/dist/types/deep-partial.js +0 -3
- package/dist/types/deep-partial.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -68
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -288
- package/dist/utils.js.map +0 -1
package/README.md
CHANGED
|
@@ -600,6 +600,15 @@ MIT © Digital Defiance
|
|
|
600
600
|
|
|
601
601
|
## ChangeLog
|
|
602
602
|
|
|
603
|
+
### v1.1.24
|
|
604
|
+
|
|
605
|
+
- Upgrade to es2022/nx monorepo
|
|
606
|
+
|
|
607
|
+
### v1.1.23
|
|
608
|
+
|
|
609
|
+
- Upgrade pbkdf2Service and various errors to pluginI18n
|
|
610
|
+
- Add legacy i18n ecies engine config
|
|
611
|
+
|
|
603
612
|
### v1.1.22
|
|
604
613
|
|
|
605
614
|
- Update i18n
|
package/package.json
CHANGED
|
@@ -1,44 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitaldefiance/ecies-lib",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.24",
|
|
4
4
|
"description": "Digital Defiance ECIES Library",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"types": "src/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "
|
|
9
|
-
"test": "
|
|
10
|
-
"test:stream": "
|
|
11
|
-
"lint": "
|
|
12
|
-
"lint:fix": "
|
|
8
|
+
"build": "npx nx build digitaldefiance-ecies-lib",
|
|
9
|
+
"test": "npx nx test digitaldefiance-ecies-lib",
|
|
10
|
+
"test:stream": "npx nx test digitaldefiance-ecies-lib --output-style=stream",
|
|
11
|
+
"lint": "npx nx lint digitaldefiance-ecies-lib",
|
|
12
|
+
"lint:fix": "npx nx lint digitaldefiance-ecies-lib --fix",
|
|
13
13
|
"prettier:check": "prettier --check 'src/**/*.{ts,tsx}'",
|
|
14
14
|
"prettier:fix": "prettier --write 'src/**/*.{ts,tsx}'",
|
|
15
|
-
"format": "
|
|
16
|
-
"
|
|
15
|
+
"format": "npx nx format:write --projects=digitaldefiance-ecies-lib",
|
|
16
|
+
"format:check": "npx nx format:check --projects=digitaldefiance-ecies-lib",
|
|
17
|
+
"prepublishOnly": "npx nx build digitaldefiance-ecies-lib",
|
|
17
18
|
"publish:public": "npm publish --access public"
|
|
18
19
|
},
|
|
19
|
-
"devDependencies": {
|
|
20
|
-
"@babel/core": "^7.28.4",
|
|
21
|
-
"@babel/preset-env": "^7.28.3",
|
|
22
|
-
"@babel/preset-typescript": "^7.27.1",
|
|
23
|
-
"@types/babel__core": "^7",
|
|
24
|
-
"@types/babel__preset-env": "^7",
|
|
25
|
-
"@types/jest": "^29.0.0",
|
|
26
|
-
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
|
27
|
-
"@typescript-eslint/parser": "^8.31.1",
|
|
28
|
-
"babel-jest": "^30.1.2",
|
|
29
|
-
"eslint": "^9.8.0",
|
|
30
|
-
"eslint-config-prettier": "^10.1.2",
|
|
31
|
-
"eslint-plugin-import": "^2.32.0",
|
|
32
|
-
"eslint-plugin-prettier": "^5.3.1",
|
|
33
|
-
"jest": "^29.0.0",
|
|
34
|
-
"jest-util": "^30.0.5",
|
|
35
|
-
"prettier": "^2.6.2",
|
|
36
|
-
"prettier-plugin-organize-imports": "^4.1.0",
|
|
37
|
-
"ts-jest": "^29.0.0",
|
|
38
|
-
"typescript": "^5.9.2"
|
|
39
|
-
},
|
|
40
20
|
"files": [
|
|
41
|
-
"
|
|
21
|
+
"src",
|
|
42
22
|
"README.md"
|
|
43
23
|
],
|
|
44
24
|
"keywords": [
|
|
@@ -51,7 +31,7 @@
|
|
|
51
31
|
"license": "MIT",
|
|
52
32
|
"packageManager": "yarn@4.10.3",
|
|
53
33
|
"dependencies": {
|
|
54
|
-
"@digitaldefiance/i18n-lib": "1.3.
|
|
34
|
+
"@digitaldefiance/i18n-lib": "1.3.13",
|
|
55
35
|
"@ethereumjs/wallet": "^10.0.0",
|
|
56
36
|
"@noble/curves": "^2.0.1",
|
|
57
37
|
"@noble/hashes": "^2.0.1",
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
import { ObjectId } from 'bson';
|
|
2
|
+
import { ECIESErrorTypeEnum, EciesStringKey } from './enumerations';
|
|
3
|
+
import { Pbkdf2ProfileEnum } from './enumerations/pbkdf2-profile';
|
|
4
|
+
import { ECIESError } from './errors/ecies';
|
|
5
|
+
import { EciesComponentId, getEciesI18nEngine } from './i18n-setup';
|
|
6
|
+
import { IChecksumConsts } from './interfaces';
|
|
7
|
+
import { IConstants } from './interfaces/constants';
|
|
8
|
+
import { DeepPartial } from './types/deep-partial';
|
|
9
|
+
import { IECIESConstants } from './interfaces/ecies-consts';
|
|
10
|
+
import { IPBkdf2Consts } from './interfaces/pbkdf2-consts';
|
|
11
|
+
import { Pbkdf2Profiles } from './pbkdf2-profiles';
|
|
12
|
+
import { MNEMONIC_REGEX, PASSWORD_REGEX } from './regexes';
|
|
13
|
+
|
|
14
|
+
export const UINT8_SIZE: number = 1 as const;
|
|
15
|
+
export const UINT16_SIZE: number = 2 as const;
|
|
16
|
+
export const UINT16_MAX: number = 65535 as const;
|
|
17
|
+
export const UINT32_SIZE: number = 4 as const;
|
|
18
|
+
export const UINT32_MAX: number = 4294967295 as const;
|
|
19
|
+
export const UINT64_SIZE: number = 8 as const;
|
|
20
|
+
export const UINT64_MAX: bigint = 18446744073709551615n as const;
|
|
21
|
+
export const GUID_SIZE: number = 16 as const;
|
|
22
|
+
|
|
23
|
+
const objectIdLength = new ObjectId().toHexString().length / 2;
|
|
24
|
+
|
|
25
|
+
if (objectIdLength !== 12) {
|
|
26
|
+
console.warn(
|
|
27
|
+
'ObjectID length may have changed, breaking encryption',
|
|
28
|
+
objectIdLength,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Constants for checksum operations
|
|
34
|
+
* These values are critical for data integrity and MUST NOT be changed
|
|
35
|
+
* in an already established system as it will break all existing checksums.
|
|
36
|
+
*/
|
|
37
|
+
export const CHECKSUM: IChecksumConsts = Object.freeze({
|
|
38
|
+
/** Default hash bits for SHA3 */
|
|
39
|
+
SHA3_DEFAULT_HASH_BITS: 512 as const,
|
|
40
|
+
|
|
41
|
+
/** Length of a SHA3 checksum buffer in bytes */
|
|
42
|
+
SHA3_BUFFER_LENGTH: 64 as const,
|
|
43
|
+
|
|
44
|
+
/** algorithm to use for checksum */
|
|
45
|
+
ALGORITHM: 'sha3-512' as const,
|
|
46
|
+
|
|
47
|
+
/** encoding to use for checksum */
|
|
48
|
+
ENCODING: 'hex' as const,
|
|
49
|
+
} as const);
|
|
50
|
+
|
|
51
|
+
export const PBKDF2: IPBkdf2Consts = Object.freeze({
|
|
52
|
+
ALGORITHM: 'SHA-256' as const,
|
|
53
|
+
SALT_BYTES: 32 as const,
|
|
54
|
+
/**
|
|
55
|
+
* Number of pbkdf2 iterations per second when hashing a password.
|
|
56
|
+
* This is the high-security default for user login operations.
|
|
57
|
+
*/
|
|
58
|
+
ITERATIONS_PER_SECOND: 1304000 as const,
|
|
59
|
+
} as const);
|
|
60
|
+
|
|
61
|
+
export const PBKDF2_PROFILES: Pbkdf2Profiles = Object.freeze({
|
|
62
|
+
[Pbkdf2ProfileEnum.BROWSER_PASSWORD]: Object.freeze({
|
|
63
|
+
hashBytes: 32 as const,
|
|
64
|
+
saltBytes: 64 as const,
|
|
65
|
+
iterations: 2000000 as const,
|
|
66
|
+
algorithm: 'SHA-512' as const,
|
|
67
|
+
} as const),
|
|
68
|
+
[Pbkdf2ProfileEnum.HIGH_SECURITY]: Object.freeze({
|
|
69
|
+
hashBytes: 64 as const,
|
|
70
|
+
saltBytes: 32 as const,
|
|
71
|
+
iterations: 5000000 as const,
|
|
72
|
+
algorithm: 'SHA-256' as const,
|
|
73
|
+
} as const),
|
|
74
|
+
[Pbkdf2ProfileEnum.TEST_FAST]: Object.freeze({
|
|
75
|
+
hashBytes: 32 as const,
|
|
76
|
+
saltBytes: 64 as const,
|
|
77
|
+
iterations: 1000 as const,
|
|
78
|
+
algorithm: 'SHA-512' as const,
|
|
79
|
+
} as const),
|
|
80
|
+
} as const);
|
|
81
|
+
|
|
82
|
+
const ECIES_SYMMETRIC_KEY_SIZE = 32 as const;
|
|
83
|
+
const ECIES_PUBLIC_KEY_LENGTH = 65 as const;
|
|
84
|
+
const ECIES_RAW_PUBLIC_KEY_LENGTH = 64 as const;
|
|
85
|
+
const ECIES_IV_SIZE = 16 as const;
|
|
86
|
+
const ECIES_AUTH_TAG_SIZE = 16 as const;
|
|
87
|
+
const ECIES_MULTIPLE_RECIPIENT_ID_SIZE = 16 as const;
|
|
88
|
+
|
|
89
|
+
// Define the expected value for SIMPLE.FIXED_OVERHEAD_SIZE
|
|
90
|
+
const expectedSimpleOverhead =
|
|
91
|
+
UINT8_SIZE + ECIES_PUBLIC_KEY_LENGTH + ECIES_IV_SIZE + ECIES_AUTH_TAG_SIZE;
|
|
92
|
+
|
|
93
|
+
// Define the expected value for MULTIPLE.FIXED_OVERHEAD_SIZE
|
|
94
|
+
// Includes: type (1) + IV (16) + auth tag (16) = 33 (no CRC, AES-GCM provides authentication)
|
|
95
|
+
const expectedMultipleOverhead =
|
|
96
|
+
UINT8_SIZE + ECIES_IV_SIZE + ECIES_AUTH_TAG_SIZE;
|
|
97
|
+
|
|
98
|
+
// Update ENCRYPTED_KEY_SIZE to match Simple encryption (no CRC)
|
|
99
|
+
const expectedMultipleEncryptedKeySize =
|
|
100
|
+
ECIES_PUBLIC_KEY_LENGTH +
|
|
101
|
+
ECIES_IV_SIZE +
|
|
102
|
+
ECIES_AUTH_TAG_SIZE +
|
|
103
|
+
ECIES_SYMMETRIC_KEY_SIZE;
|
|
104
|
+
|
|
105
|
+
export const ECIES: IECIESConstants = Object.freeze({
|
|
106
|
+
/** The elliptic curve to use for all ECDSA operations */
|
|
107
|
+
CURVE_NAME: 'secp256k1' as const,
|
|
108
|
+
|
|
109
|
+
/** The primary key derivation path for HD wallets */
|
|
110
|
+
PRIMARY_KEY_DERIVATION_PATH: "m/44'/60'/0'/0/0" as const,
|
|
111
|
+
|
|
112
|
+
SYMMETRIC_ALGORITHM_CONFIGURATION: 'aes-256-gcm' as const,
|
|
113
|
+
|
|
114
|
+
/** Length of ECDSA signatures in bytes */
|
|
115
|
+
SIGNATURE_SIZE: 64 as const,
|
|
116
|
+
|
|
117
|
+
/** Length of raw public keys in bytes (without 0x04 prefix) */
|
|
118
|
+
RAW_PUBLIC_KEY_LENGTH: ECIES_RAW_PUBLIC_KEY_LENGTH,
|
|
119
|
+
|
|
120
|
+
/** Length of public keys in bytes (with 0x04 prefix) */
|
|
121
|
+
PUBLIC_KEY_LENGTH: ECIES_PUBLIC_KEY_LENGTH,
|
|
122
|
+
|
|
123
|
+
PUBLIC_KEY_MAGIC: 0x04 as const,
|
|
124
|
+
|
|
125
|
+
/** Mnemonic strength in bits. This will produce a 32-bit key for ECDSA */
|
|
126
|
+
MNEMONIC_STRENGTH: 256 as const,
|
|
127
|
+
|
|
128
|
+
/** Symmetric encryption algorithm configuration */
|
|
129
|
+
SYMMETRIC: Object.freeze({
|
|
130
|
+
ALGORITHM: 'aes' as const,
|
|
131
|
+
MODE: 'gcm' as const,
|
|
132
|
+
KEY_BITS: 256 as const,
|
|
133
|
+
KEY_SIZE: ECIES_SYMMETRIC_KEY_SIZE, // KEY_BITS / 8
|
|
134
|
+
} as const),
|
|
135
|
+
|
|
136
|
+
IV_SIZE: ECIES_IV_SIZE,
|
|
137
|
+
AUTH_TAG_SIZE: ECIES_AUTH_TAG_SIZE,
|
|
138
|
+
MAX_RAW_DATA_SIZE: 9007199254740991 as const, // 2^53 - 1 (max safe integer for JS)
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Message encrypts without data length or crc
|
|
142
|
+
*/
|
|
143
|
+
SIMPLE: Object.freeze({
|
|
144
|
+
FIXED_OVERHEAD_SIZE: expectedSimpleOverhead, // type (1) + public key (65) + IV (16) + auth tag (16)
|
|
145
|
+
DATA_LENGTH_SIZE: 0 as const,
|
|
146
|
+
} as const),
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Message encrypts with data length but no CRC (AES-GCM provides authentication)
|
|
150
|
+
*/
|
|
151
|
+
SINGLE: Object.freeze({
|
|
152
|
+
FIXED_OVERHEAD_SIZE: 106 as const, // type (1) + public key (65) + IV (16) + auth tag (16) + data length (8)
|
|
153
|
+
DATA_LENGTH_SIZE: 8,
|
|
154
|
+
} as const),
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Message encrypts for multiple recipients
|
|
158
|
+
*/
|
|
159
|
+
MULTIPLE: Object.freeze({
|
|
160
|
+
FIXED_OVERHEAD_SIZE: expectedMultipleOverhead, // type (1) + IV (16) + auth tag (16), no CRC
|
|
161
|
+
ENCRYPTED_KEY_SIZE: expectedMultipleEncryptedKeySize, // 129
|
|
162
|
+
MAX_RECIPIENTS: 65535,
|
|
163
|
+
RECIPIENT_ID_SIZE: ECIES_MULTIPLE_RECIPIENT_ID_SIZE,
|
|
164
|
+
RECIPIENT_COUNT_SIZE: 2,
|
|
165
|
+
DATA_LENGTH_SIZE: 8,
|
|
166
|
+
} as const),
|
|
167
|
+
|
|
168
|
+
ENCRYPTION_TYPE: Object.freeze({
|
|
169
|
+
SIMPLE: 33 as const,
|
|
170
|
+
SINGLE: 66 as const,
|
|
171
|
+
MULTIPLE: 99 as const,
|
|
172
|
+
} as const),
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
export const Constants: IConstants = Object.freeze({
|
|
176
|
+
UINT8_SIZE: UINT8_SIZE,
|
|
177
|
+
UINT16_SIZE: UINT16_SIZE,
|
|
178
|
+
UINT16_MAX: UINT16_MAX,
|
|
179
|
+
UINT32_SIZE: UINT32_SIZE,
|
|
180
|
+
UINT32_MAX: UINT32_MAX,
|
|
181
|
+
UINT64_SIZE: UINT64_SIZE,
|
|
182
|
+
UINT64_MAX: UINT64_MAX,
|
|
183
|
+
HEX_RADIX: 16 as const,
|
|
184
|
+
GUID_SIZE: GUID_SIZE,
|
|
185
|
+
OBJECT_ID_LENGTH: objectIdLength,
|
|
186
|
+
CHECKSUM: CHECKSUM,
|
|
187
|
+
ECIES: ECIES,
|
|
188
|
+
PBKDF2: PBKDF2,
|
|
189
|
+
PBKDF2_PROFILES: PBKDF2_PROFILES,
|
|
190
|
+
/**
|
|
191
|
+
* Number of rounds for bcrypt hashing. Higher values increase security but also consume more CPU resources.
|
|
192
|
+
*/
|
|
193
|
+
BcryptRounds: 10 as const,
|
|
194
|
+
/**
|
|
195
|
+
* Minimum password length
|
|
196
|
+
*/
|
|
197
|
+
PasswordMinLength: 8 as const,
|
|
198
|
+
/**
|
|
199
|
+
* The regular expression for valid passwords.
|
|
200
|
+
*/
|
|
201
|
+
PasswordRegex: PASSWORD_REGEX,
|
|
202
|
+
/**
|
|
203
|
+
* The regular expression for valid mnemonic phrases.
|
|
204
|
+
* BIP39 - supports 12, 15, 18, 21, or 24 word mnemonics
|
|
205
|
+
*/
|
|
206
|
+
MnemonicRegex: MNEMONIC_REGEX,
|
|
207
|
+
/**
|
|
208
|
+
* Matches a 64-character hexadecimal string (SHA-256).
|
|
209
|
+
*/
|
|
210
|
+
HmacRegex: /^[a-f0-9]{64}$/,
|
|
211
|
+
} as const);
|
|
212
|
+
|
|
213
|
+
export type ConfigurationKey = string | symbol;
|
|
214
|
+
|
|
215
|
+
const DEFAULT_CONFIGURATION_KEY: ConfigurationKey = Symbol.for(
|
|
216
|
+
'digitaldefiance.ecies.constants.default',
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
220
|
+
if (value === null) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
if (typeof value !== 'object') {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
if (Array.isArray(value)) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
if (value instanceof RegExp || value instanceof Date) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
return Object.getPrototypeOf(value) === Object.prototype;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function deepClone<T>(input: T): T {
|
|
236
|
+
if (input === null) {
|
|
237
|
+
return input;
|
|
238
|
+
}
|
|
239
|
+
if (Array.isArray(input)) {
|
|
240
|
+
return input.map((item) => deepClone(item)) as unknown as T;
|
|
241
|
+
}
|
|
242
|
+
if (input instanceof RegExp) {
|
|
243
|
+
return new RegExp(input.source, input.flags) as unknown as T;
|
|
244
|
+
}
|
|
245
|
+
if (input instanceof Date) {
|
|
246
|
+
return new Date(input.getTime()) as unknown as T;
|
|
247
|
+
}
|
|
248
|
+
if (isPlainObject(input)) {
|
|
249
|
+
const result: Record<string, unknown> = {};
|
|
250
|
+
for (const [key, value] of Object.entries(input)) {
|
|
251
|
+
result[key] = deepClone(value);
|
|
252
|
+
}
|
|
253
|
+
return result as T;
|
|
254
|
+
}
|
|
255
|
+
return input;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function applyOverrides<T>(target: T, overrides?: DeepPartial<T>): T {
|
|
259
|
+
if (!overrides) {
|
|
260
|
+
return target;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
for (const [key, overrideValue] of Object.entries(overrides)) {
|
|
264
|
+
const typedKey = key as keyof T;
|
|
265
|
+
if (overrideValue === undefined) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const currentValue = (target as any)[typedKey];
|
|
270
|
+
|
|
271
|
+
if (isPlainObject(currentValue) && isPlainObject(overrideValue)) {
|
|
272
|
+
(target as any)[typedKey] = applyOverrides(
|
|
273
|
+
currentValue,
|
|
274
|
+
overrideValue as any,
|
|
275
|
+
);
|
|
276
|
+
} else {
|
|
277
|
+
(target as any)[typedKey] = deepClone(overrideValue);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return target;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function deepFreeze<T>(value: T): T {
|
|
285
|
+
if (value === null || typeof value !== 'object') {
|
|
286
|
+
return value;
|
|
287
|
+
}
|
|
288
|
+
if (Object.isFrozen(value)) {
|
|
289
|
+
return value;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
Object.freeze(value);
|
|
293
|
+
|
|
294
|
+
for (const property of Object.getOwnPropertyNames(value)) {
|
|
295
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
296
|
+
const nestedValue = (value as any)[property];
|
|
297
|
+
deepFreeze(nestedValue);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return value;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function computeMultipleEncryptedKeySize(ecies: IECIESConstants): number {
|
|
304
|
+
return (
|
|
305
|
+
ecies.PUBLIC_KEY_LENGTH +
|
|
306
|
+
ecies.IV_SIZE +
|
|
307
|
+
ecies.AUTH_TAG_SIZE +
|
|
308
|
+
ecies.SYMMETRIC.KEY_SIZE
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function validateConstants(config: IConstants): void {
|
|
313
|
+
const checksum = config.CHECKSUM;
|
|
314
|
+
const ecies = config.ECIES;
|
|
315
|
+
|
|
316
|
+
if (
|
|
317
|
+
checksum.SHA3_BUFFER_LENGTH !== checksum.SHA3_DEFAULT_HASH_BITS / 8 ||
|
|
318
|
+
checksum.SHA3_BUFFER_LENGTH !== checksum.SHA3_DEFAULT_HASH_BITS / 8
|
|
319
|
+
) {
|
|
320
|
+
const engine = getEciesI18nEngine();
|
|
321
|
+
throw new Error(engine.translate(EciesComponentId, EciesStringKey.Error_ECIESError_InvalidChecksumConstants));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const expectedEncryptedKeySize = computeMultipleEncryptedKeySize(ecies);
|
|
325
|
+
if (ecies.MULTIPLE.ENCRYPTED_KEY_SIZE !== expectedEncryptedKeySize) {
|
|
326
|
+
throw new ECIESError(
|
|
327
|
+
ECIESErrorTypeEnum.InvalidECIESMultipleEncryptedKeySize,
|
|
328
|
+
getEciesI18nEngine() as any,
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (ecies.PUBLIC_KEY_LENGTH !== ecies.RAW_PUBLIC_KEY_LENGTH + 1) {
|
|
333
|
+
throw new ECIESError(
|
|
334
|
+
ECIESErrorTypeEnum.InvalidECIESPublicKeyLength,
|
|
335
|
+
getEciesI18nEngine() as any,
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (ecies.MULTIPLE.RECIPIENT_COUNT_SIZE !== UINT16_SIZE) {
|
|
340
|
+
throw new ECIESError(
|
|
341
|
+
ECIESErrorTypeEnum.InvalidECIESMultipleRecipientCountSize,
|
|
342
|
+
getEciesI18nEngine() as any,
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (ecies.MULTIPLE.DATA_LENGTH_SIZE !== UINT64_SIZE) {
|
|
347
|
+
throw new ECIESError(
|
|
348
|
+
ECIESErrorTypeEnum.InvalidECIESMultipleDataLengthSize,
|
|
349
|
+
getEciesI18nEngine() as any,
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (ecies.MULTIPLE.RECIPIENT_ID_SIZE !== GUID_SIZE) {
|
|
354
|
+
throw new ECIESError(
|
|
355
|
+
ECIESErrorTypeEnum.InvalidECIESMultipleRecipientIdSize,
|
|
356
|
+
getEciesI18nEngine() as any,
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
validateConstants(Constants);
|
|
363
|
+
|
|
364
|
+
const configurationRegistry = new Map<ConfigurationKey, IConstants>();
|
|
365
|
+
configurationRegistry.set(DEFAULT_CONFIGURATION_KEY, Constants);
|
|
366
|
+
|
|
367
|
+
function isFullConstantsConfig(value: unknown): value is IConstants {
|
|
368
|
+
if (!isPlainObject(value)) {
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
const candidate = value as Partial<IConstants>;
|
|
372
|
+
return (
|
|
373
|
+
candidate.CHECKSUM !== undefined &&
|
|
374
|
+
candidate.ECIES !== undefined &&
|
|
375
|
+
candidate.PBKDF2 !== undefined &&
|
|
376
|
+
candidate.PBKDF2_PROFILES !== undefined
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export function createRuntimeConfiguration(
|
|
381
|
+
overrides?: DeepPartial<IConstants>,
|
|
382
|
+
base: IConstants = Constants,
|
|
383
|
+
): IConstants {
|
|
384
|
+
const merged = deepClone(base);
|
|
385
|
+
applyOverrides(merged, overrides);
|
|
386
|
+
validateConstants(merged);
|
|
387
|
+
return deepFreeze(merged);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export class ConstantsRegistry {
|
|
391
|
+
public static readonly DEFAULT_KEY = DEFAULT_CONFIGURATION_KEY;
|
|
392
|
+
|
|
393
|
+
public static listKeys(): ConfigurationKey[] {
|
|
394
|
+
return Array.from(configurationRegistry.keys());
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
public static has(key: ConfigurationKey): boolean {
|
|
398
|
+
return configurationRegistry.has(key);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
public static get(key: ConfigurationKey = DEFAULT_CONFIGURATION_KEY): IConstants {
|
|
402
|
+
return (
|
|
403
|
+
configurationRegistry.get(key) ??
|
|
404
|
+
configurationRegistry.get(DEFAULT_CONFIGURATION_KEY)!
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
public static create(
|
|
409
|
+
overrides?: DeepPartial<IConstants>,
|
|
410
|
+
baseKey: ConfigurationKey = DEFAULT_CONFIGURATION_KEY,
|
|
411
|
+
): IConstants {
|
|
412
|
+
const baseConfig = ConstantsRegistry.get(baseKey);
|
|
413
|
+
return createRuntimeConfiguration(overrides, baseConfig);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
public static register(
|
|
417
|
+
key: ConfigurationKey,
|
|
418
|
+
configOrOverrides?: DeepPartial<IConstants> | IConstants,
|
|
419
|
+
options?: { baseKey?: ConfigurationKey },
|
|
420
|
+
): IConstants {
|
|
421
|
+
if (key === DEFAULT_CONFIGURATION_KEY) {
|
|
422
|
+
const engine = getEciesI18nEngine();
|
|
423
|
+
throw new Error(engine.translate(EciesComponentId, EciesStringKey.Error_ECIESError_CannotOverwriteDefaultConfiguration));
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const baseKey = options?.baseKey ?? DEFAULT_CONFIGURATION_KEY;
|
|
427
|
+
const baseConfig = ConstantsRegistry.get(baseKey);
|
|
428
|
+
|
|
429
|
+
const configuration = isFullConstantsConfig(configOrOverrides)
|
|
430
|
+
? createRuntimeConfiguration(undefined, configOrOverrides)
|
|
431
|
+
: createRuntimeConfiguration(configOrOverrides, baseConfig);
|
|
432
|
+
|
|
433
|
+
configurationRegistry.set(key, configuration);
|
|
434
|
+
return configuration;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
public static unregister(key: ConfigurationKey): boolean {
|
|
438
|
+
if (key === DEFAULT_CONFIGURATION_KEY) {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
return configurationRegistry.delete(key);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
public static clear(): void {
|
|
445
|
+
configurationRegistry.clear();
|
|
446
|
+
configurationRegistry.set(DEFAULT_CONFIGURATION_KEY, Constants);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export function getRuntimeConfiguration(
|
|
451
|
+
key: ConfigurationKey = DEFAULT_CONFIGURATION_KEY,
|
|
452
|
+
): IConstants {
|
|
453
|
+
return ConstantsRegistry.get(key);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
export function registerRuntimeConfiguration(
|
|
457
|
+
key: ConfigurationKey,
|
|
458
|
+
configOrOverrides?: DeepPartial<IConstants> | IConstants,
|
|
459
|
+
options?: { baseKey?: ConfigurationKey },
|
|
460
|
+
): IConstants {
|
|
461
|
+
return ConstantsRegistry.register(key, configOrOverrides, options);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
export function unregisterRuntimeConfiguration(
|
|
465
|
+
key: ConfigurationKey,
|
|
466
|
+
): boolean {
|
|
467
|
+
return ConstantsRegistry.unregister(key);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
export function clearRuntimeConfigurations(): void {
|
|
471
|
+
ConstantsRegistry.clear();
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
export { PASSWORD_REGEX, MNEMONIC_REGEX } from './regexes';
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import validator from 'validator';
|
|
2
|
+
import { InvalidEmailErrorType } from './enumerations/invalid-email-type';
|
|
3
|
+
import { InvalidEmailError } from './errors/invalid-email';
|
|
4
|
+
import { getEciesI18nEngine } from './i18n-setup';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* EmailString represents a validated email address.
|
|
8
|
+
* It ensures that the email is not empty, does not have leading or trailing spaces,
|
|
9
|
+
* and is a valid email format.
|
|
10
|
+
*/
|
|
11
|
+
export class EmailString {
|
|
12
|
+
public readonly email: string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates an instance of EmailString.
|
|
16
|
+
* @param email - The email address to validate and store.
|
|
17
|
+
* @throws Will throw an error if the email is invalid.
|
|
18
|
+
*/
|
|
19
|
+
constructor(email: string) {
|
|
20
|
+
const trimmedEmail = email.trim();
|
|
21
|
+
if (trimmedEmail.length == 0) {
|
|
22
|
+
throw new InvalidEmailError(
|
|
23
|
+
InvalidEmailErrorType.Missing,
|
|
24
|
+
getEciesI18nEngine() as any,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
if (trimmedEmail.length != email.length) {
|
|
28
|
+
throw new InvalidEmailError(
|
|
29
|
+
InvalidEmailErrorType.Whitespace,
|
|
30
|
+
getEciesI18nEngine() as any,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
if (!validator.isEmail(trimmedEmail)) {
|
|
34
|
+
throw new InvalidEmailError(
|
|
35
|
+
InvalidEmailErrorType.Invalid,
|
|
36
|
+
getEciesI18nEngine() as any,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
this.email = trimmedEmail;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns the email address as a string.
|
|
44
|
+
* @returns The email address.
|
|
45
|
+
*/
|
|
46
|
+
public toString(): string {
|
|
47
|
+
return this.email;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Checks if this email address is equal to another email address.
|
|
52
|
+
* @param other - The other email address to compare.
|
|
53
|
+
* @returns True if the email addresses are equal, false otherwise.
|
|
54
|
+
*/
|
|
55
|
+
public equals(other: EmailString): boolean {
|
|
56
|
+
return this.email === other.email;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Converts the email address to a JSON string.
|
|
61
|
+
* @returns The email address as a JSON string.
|
|
62
|
+
*/
|
|
63
|
+
public toJson(): string {
|
|
64
|
+
return JSON.stringify(this.email);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Creates an EmailString instance from a JSON string.
|
|
69
|
+
* @param email - The JSON string representing the email address.
|
|
70
|
+
* @returns The EmailString instance.
|
|
71
|
+
*/
|
|
72
|
+
public static fromJson(email: string): EmailString {
|
|
73
|
+
return new EmailString(JSON.parse(email));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Gets the length of the email address.
|
|
78
|
+
* @returns The length of the email address.
|
|
79
|
+
*/
|
|
80
|
+
public get length(): number {
|
|
81
|
+
return this.email.length;
|
|
82
|
+
}
|
|
83
|
+
}
|