@digitaldefiance/node-ecies-lib 4.4.8 → 4.4.10
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/package.json +6 -5
- package/src/builders/ecies-builder.d.ts +11 -0
- package/src/builders/ecies-builder.d.ts.map +1 -0
- package/src/builders/ecies-builder.js +26 -0
- package/src/builders/ecies-builder.js.map +1 -0
- package/src/builders/{index.ts → index.d.ts} +1 -0
- package/src/builders/index.d.ts.map +1 -0
- package/src/builders/index.js +6 -0
- package/src/builders/index.js.map +1 -0
- package/src/builders/member-builder.d.ts +47 -0
- package/src/builders/member-builder.d.ts.map +1 -0
- package/src/builders/member-builder.js +99 -0
- package/src/builders/member-builder.js.map +1 -0
- package/src/constants.d.ts +38 -0
- package/src/constants.d.ts.map +1 -0
- package/src/constants.js +183 -0
- package/src/constants.js.map +1 -0
- package/src/core/errors/crypto-error.d.ts +6 -0
- package/src/core/errors/crypto-error.d.ts.map +1 -0
- package/src/core/errors/crypto-error.js +15 -0
- package/src/core/errors/crypto-error.js.map +1 -0
- package/src/core/{index.ts → index.d.ts} +1 -0
- package/src/core/index.d.ts.map +1 -0
- package/src/core/index.js +6 -0
- package/src/core/index.js.map +1 -0
- package/src/core/types/result.d.ts +8 -0
- package/src/core/types/result.d.ts.map +1 -0
- package/src/core/types/result.js +3 -0
- package/src/core/types/result.js.map +1 -0
- package/src/enumerations/index.d.ts +2 -0
- package/src/enumerations/index.d.ts.map +1 -0
- package/src/enumerations/index.js +5 -0
- package/src/enumerations/index.js.map +1 -0
- package/src/enumerations/pbkdf2-profile.d.ts +9 -0
- package/src/enumerations/pbkdf2-profile.d.ts.map +1 -0
- package/src/enumerations/pbkdf2-profile.js +13 -0
- package/src/enumerations/pbkdf2-profile.js.map +1 -0
- package/src/i18n/ecies-i18n-factory.d.ts +28 -0
- package/src/i18n/ecies-i18n-factory.d.ts.map +1 -0
- package/src/i18n/ecies-i18n-factory.js +89 -0
- package/src/i18n/ecies-i18n-factory.js.map +1 -0
- package/src/i18n/{index.ts → index.d.ts} +1 -3
- package/src/i18n/index.d.ts.map +1 -0
- package/src/i18n/index.js +8 -0
- package/src/i18n/index.js.map +1 -0
- package/src/i18n/node-ecies-i18n-setup.d.ts +5 -0
- package/src/i18n/node-ecies-i18n-setup.d.ts.map +1 -0
- package/src/i18n/node-ecies-i18n-setup.js +46 -0
- package/src/i18n/node-ecies-i18n-setup.js.map +1 -0
- package/src/i18n/node-keys.d.ts +57 -0
- package/src/i18n/node-keys.d.ts.map +1 -0
- package/src/i18n/node-keys.js +67 -0
- package/src/i18n/node-keys.js.map +1 -0
- package/src/i18n/translations/de.d.ts +3 -0
- package/src/i18n/translations/de.d.ts.map +1 -0
- package/src/i18n/translations/de.js +57 -0
- package/src/i18n/translations/de.js.map +1 -0
- package/src/i18n/translations/en-GB.d.ts +3 -0
- package/src/i18n/translations/en-GB.d.ts.map +1 -0
- package/src/i18n/translations/en-GB.js +61 -0
- package/src/i18n/translations/en-GB.js.map +1 -0
- package/src/i18n/translations/en-US.d.ts +6 -0
- package/src/i18n/translations/en-US.d.ts.map +1 -0
- package/src/i18n/translations/en-US.js +65 -0
- package/src/i18n/translations/en-US.js.map +1 -0
- package/src/i18n/translations/es.d.ts +3 -0
- package/src/i18n/translations/es.d.ts.map +1 -0
- package/src/i18n/translations/es.js +57 -0
- package/src/i18n/translations/es.js.map +1 -0
- package/src/i18n/translations/fr.d.ts +3 -0
- package/src/i18n/translations/fr.d.ts.map +1 -0
- package/src/i18n/translations/fr.js +57 -0
- package/src/i18n/translations/fr.js.map +1 -0
- package/src/i18n/translations/{index.ts → index.d.ts} +1 -0
- package/src/i18n/translations/index.d.ts.map +1 -0
- package/src/i18n/translations/index.js +20 -0
- package/src/i18n/translations/index.js.map +1 -0
- package/src/i18n/translations/ja.d.ts +3 -0
- package/src/i18n/translations/ja.d.ts.map +1 -0
- package/src/i18n/translations/ja.js +57 -0
- package/src/i18n/translations/ja.js.map +1 -0
- package/src/i18n/translations/uk.d.ts +3 -0
- package/src/i18n/translations/uk.d.ts.map +1 -0
- package/src/i18n/translations/uk.js +57 -0
- package/src/i18n/translations/uk.js.map +1 -0
- package/src/i18n/translations/zh-cn.d.ts +3 -0
- package/src/i18n/translations/zh-cn.d.ts.map +1 -0
- package/src/i18n/translations/zh-cn.js +57 -0
- package/src/i18n/translations/zh-cn.js.map +1 -0
- package/src/{index.ts → index.d.ts} +1 -5
- package/src/index.d.ts.map +1 -0
- package/src/index.js +31 -0
- package/src/index.js.map +1 -0
- package/src/interfaces/authenticated-cipher.d.ts +12 -0
- package/src/interfaces/authenticated-cipher.d.ts.map +1 -0
- package/src/interfaces/authenticated-cipher.js +3 -0
- package/src/interfaces/authenticated-cipher.js.map +1 -0
- package/src/interfaces/authenticated-decipher.d.ts +11 -0
- package/src/interfaces/authenticated-decipher.d.ts.map +1 -0
- package/src/interfaces/authenticated-decipher.js +3 -0
- package/src/interfaces/authenticated-decipher.js.map +1 -0
- package/src/interfaces/backend-member-operational.d.ts +48 -0
- package/src/interfaces/backend-member-operational.d.ts.map +1 -0
- package/src/interfaces/backend-member-operational.js +3 -0
- package/src/interfaces/backend-member-operational.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 +52 -0
- package/src/interfaces/constants.d.ts.map +1 -0
- package/src/interfaces/constants.js +3 -0
- package/src/interfaces/constants.js.map +1 -0
- package/src/interfaces/ecies-consts.d.ts +88 -0
- package/src/interfaces/ecies-consts.d.ts.map +1 -0
- package/src/interfaces/ecies-consts.js +3 -0
- package/src/interfaces/ecies-consts.js.map +1 -0
- package/src/interfaces/encrypted-chunk.d.ts +12 -0
- package/src/interfaces/encrypted-chunk.d.ts.map +1 -0
- package/src/interfaces/encrypted-chunk.js +3 -0
- package/src/interfaces/encrypted-chunk.js.map +1 -0
- package/src/interfaces/encryption-consts.d.ts +11 -0
- package/src/interfaces/encryption-consts.d.ts.map +1 -0
- package/src/interfaces/encryption-consts.js +3 -0
- package/src/interfaces/encryption-consts.js.map +1 -0
- package/src/interfaces/{index.ts → index.d.ts} +1 -0
- package/src/interfaces/index.d.ts.map +1 -0
- package/src/interfaces/index.js +30 -0
- package/src/interfaces/index.js.map +1 -0
- package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts +6 -0
- package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts.map +1 -0
- package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.js +3 -0
- package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.js.map +1 -0
- package/src/interfaces/keyring-consts.d.ts +6 -0
- package/src/interfaces/keyring-consts.d.ts.map +1 -0
- package/src/interfaces/keyring-consts.js +3 -0
- package/src/interfaces/keyring-consts.js.map +1 -0
- package/src/interfaces/{member-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/member.d.ts +47 -0
- package/src/interfaces/member.d.ts.map +1 -0
- package/src/interfaces/member.js +3 -0
- package/src/interfaces/member.js.map +1 -0
- package/src/interfaces/{multi-encrypted-message.ts → multi-encrypted-message.d.ts} +5 -5
- package/src/interfaces/multi-encrypted-message.d.ts.map +1 -0
- package/src/interfaces/multi-encrypted-message.js +3 -0
- package/src/interfaces/multi-encrypted-message.js.map +1 -0
- package/src/interfaces/multi-encrypted-parsed-header.d.ts +27 -0
- package/src/interfaces/multi-encrypted-parsed-header.d.ts.map +1 -0
- package/src/interfaces/multi-encrypted-parsed-header.js +3 -0
- package/src/interfaces/multi-encrypted-parsed-header.js.map +1 -0
- package/src/interfaces/multi-recipient-chunk.d.ts +26 -0
- package/src/interfaces/multi-recipient-chunk.d.ts.map +1 -0
- package/src/interfaces/multi-recipient-chunk.js +13 -0
- package/src/interfaces/multi-recipient-chunk.js.map +1 -0
- package/src/interfaces/{pbkdf-profiles.ts → pbkdf-profiles.d.ts} +2 -2
- package/src/interfaces/pbkdf-profiles.d.ts.map +1 -0
- package/src/interfaces/pbkdf-profiles.js +3 -0
- package/src/interfaces/pbkdf-profiles.js.map +1 -0
- package/src/interfaces/pbkdf2-result.d.ts +6 -0
- package/src/interfaces/pbkdf2-result.d.ts.map +1 -0
- package/src/interfaces/pbkdf2-result.js +3 -0
- package/src/interfaces/pbkdf2-result.js.map +1 -0
- package/src/interfaces/signing-key-private-key-info.d.ts +11 -0
- package/src/interfaces/signing-key-private-key-info.d.ts.map +1 -0
- package/src/interfaces/signing-key-private-key-info.js +3 -0
- package/src/interfaces/signing-key-private-key-info.js.map +1 -0
- package/src/interfaces/{simple-keypair-buffer.ts → simple-keypair-buffer.d.ts} +3 -3
- package/src/interfaces/simple-keypair-buffer.d.ts.map +1 -0
- package/src/interfaces/simple-keypair-buffer.js +3 -0
- package/src/interfaces/simple-keypair-buffer.js.map +1 -0
- package/src/interfaces/{simple-keypair.ts → simple-keypair.d.ts} +3 -3
- package/src/interfaces/simple-keypair.d.ts.map +1 -0
- package/src/interfaces/simple-keypair.js +3 -0
- package/src/interfaces/simple-keypair.js.map +1 -0
- package/src/interfaces/simple-public-key-only-buffer.d.ts +4 -0
- package/src/interfaces/simple-public-key-only-buffer.d.ts.map +1 -0
- package/src/interfaces/simple-public-key-only-buffer.js +3 -0
- package/src/interfaces/simple-public-key-only-buffer.js.map +1 -0
- package/src/interfaces/simple-public-key-only.d.ts +4 -0
- package/src/interfaces/simple-public-key-only.d.ts.map +1 -0
- package/src/interfaces/simple-public-key-only.js +3 -0
- package/src/interfaces/simple-public-key-only.js.map +1 -0
- package/src/interfaces/single-encrypted-parsed-header.d.ts +35 -0
- package/src/interfaces/single-encrypted-parsed-header.d.ts.map +1 -0
- package/src/interfaces/single-encrypted-parsed-header.js +3 -0
- package/src/interfaces/single-encrypted-parsed-header.js.map +1 -0
- package/src/interfaces/stream-config.d.ts +6 -0
- package/src/interfaces/stream-config.d.ts.map +1 -0
- package/src/interfaces/stream-config.js +8 -0
- package/src/interfaces/stream-config.js.map +1 -0
- package/src/interfaces/stream-progress.d.ts +8 -0
- package/src/interfaces/stream-progress.d.ts.map +1 -0
- package/src/interfaces/stream-progress.js +3 -0
- package/src/interfaces/stream-progress.js.map +1 -0
- package/src/interfaces/{wallet-seed.ts → wallet-seed.d.ts} +3 -3
- package/src/interfaces/wallet-seed.d.ts.map +1 -0
- package/src/interfaces/wallet-seed.js +3 -0
- package/src/interfaces/wallet-seed.js.map +1 -0
- package/src/interfaces/wrapped-key-consts.d.ts +7 -0
- package/src/interfaces/wrapped-key-consts.d.ts.map +1 -0
- package/src/interfaces/wrapped-key-consts.js +3 -0
- package/src/interfaces/wrapped-key-consts.js.map +1 -0
- package/src/lib/crypto-container.d.ts +13 -0
- package/src/lib/crypto-container.d.ts.map +1 -0
- package/src/lib/crypto-container.js +29 -0
- package/src/lib/crypto-container.js.map +1 -0
- package/src/lib/{index.ts → index.d.ts} +1 -0
- package/src/lib/index.d.ts.map +1 -0
- package/src/lib/index.js +7 -0
- package/src/lib/index.js.map +1 -0
- package/src/lib/invariant-validator.d.ts +62 -0
- package/src/lib/invariant-validator.d.ts.map +1 -0
- package/src/lib/invariant-validator.js +108 -0
- package/src/lib/invariant-validator.js.map +1 -0
- package/src/lib/invariants/{index.ts → index.d.ts} +2 -2
- package/src/lib/invariants/index.d.ts.map +1 -0
- package/src/lib/invariants/index.js +12 -0
- package/src/lib/invariants/index.js.map +1 -0
- package/src/lib/invariants/recipient-id-consistency.d.ts +22 -0
- package/src/lib/invariants/recipient-id-consistency.d.ts.map +1 -0
- package/src/lib/invariants/recipient-id-consistency.js +62 -0
- package/src/lib/invariants/recipient-id-consistency.js.map +1 -0
- package/src/member.d.ts +81 -0
- package/src/member.d.ts.map +1 -0
- package/src/member.js +285 -0
- package/src/member.js.map +1 -0
- package/src/services/aes-gcm.d.ts +66 -0
- package/src/services/aes-gcm.d.ts.map +1 -0
- package/src/services/aes-gcm.js +158 -0
- package/src/services/aes-gcm.js.map +1 -0
- package/src/services/chunk-processor.d.ts +15 -0
- package/src/services/chunk-processor.d.ts.map +1 -0
- package/src/services/chunk-processor.js +36 -0
- package/src/services/chunk-processor.js.map +1 -0
- package/src/services/ecies/crypto-core.d.ts +104 -0
- package/src/services/ecies/crypto-core.d.ts.map +1 -0
- package/src/services/ecies/crypto-core.js +237 -0
- package/src/services/ecies/crypto-core.js.map +1 -0
- package/src/services/ecies/file.d.ts +30 -0
- package/src/services/ecies/file.d.ts.map +1 -0
- package/src/services/ecies/file.js +112 -0
- package/src/services/ecies/file.js.map +1 -0
- package/src/services/ecies/{index.ts → index.d.ts} +1 -0
- package/src/services/ecies/index.d.ts.map +1 -0
- package/src/services/ecies/index.js +11 -0
- package/src/services/ecies/index.js.map +1 -0
- package/src/services/ecies/multi-recipient.d.ts +84 -0
- package/src/services/ecies/multi-recipient.d.ts.map +1 -0
- package/src/services/ecies/multi-recipient.js +496 -0
- package/src/services/ecies/multi-recipient.js.map +1 -0
- package/src/services/ecies/service.d.ts +69 -0
- package/src/services/ecies/service.d.ts.map +1 -0
- package/src/services/ecies/service.js +144 -0
- package/src/services/ecies/service.js.map +1 -0
- package/src/services/ecies/signature.d.ts +38 -0
- package/src/services/ecies/signature.d.ts.map +1 -0
- package/src/services/ecies/signature.js +69 -0
- package/src/services/ecies/signature.js.map +1 -0
- package/src/services/ecies/single-recipient.d.ts +83 -0
- package/src/services/ecies/single-recipient.d.ts.map +1 -0
- package/src/services/ecies/single-recipient.js +447 -0
- package/src/services/ecies/single-recipient.js.map +1 -0
- package/src/services/ecies/utilities.d.ts +33 -0
- package/src/services/ecies/utilities.d.ts.map +1 -0
- package/src/services/ecies/utilities.js +91 -0
- package/src/services/ecies/utilities.js.map +1 -0
- package/src/services/encryption-stream.d.ts +33 -0
- package/src/services/encryption-stream.d.ts.map +1 -0
- package/src/services/encryption-stream.js +207 -0
- package/src/services/encryption-stream.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 +11 -0
- package/src/services/index.js.map +1 -0
- package/src/services/multi-recipient-processor.d.ts +72 -0
- package/src/services/multi-recipient-processor.d.ts.map +1 -0
- package/src/services/multi-recipient-processor.js +322 -0
- package/src/services/multi-recipient-processor.js.map +1 -0
- package/src/services/pbkdf2.d.ts +105 -0
- package/src/services/pbkdf2.d.ts.map +1 -0
- package/src/services/pbkdf2.js +189 -0
- package/src/services/pbkdf2.js.map +1 -0
- package/src/services/progress-tracker.d.ts +9 -0
- package/src/services/progress-tracker.d.ts.map +1 -0
- package/src/services/progress-tracker.js +41 -0
- package/src/services/progress-tracker.js.map +1 -0
- package/src/test-mocks/index.d.ts +2 -0
- package/src/test-mocks/index.d.ts.map +1 -0
- package/src/test-mocks/index.js +5 -0
- package/src/test-mocks/index.js.map +1 -0
- package/src/test-mocks/mock-backend-member.d.ts +71 -0
- package/src/test-mocks/mock-backend-member.d.ts.map +1 -0
- package/src/test-mocks/mock-backend-member.js +133 -0
- package/src/test-mocks/mock-backend-member.js.map +1 -0
- package/src/testing.d.ts +2 -0
- package/src/testing.d.ts.map +1 -0
- package/src/testing.js +6 -0
- package/src/testing.js.map +1 -0
- package/src/types/id-guards.d.ts +39 -0
- package/src/types/id-guards.d.ts.map +1 -0
- package/src/types/id-guards.js +91 -0
- package/src/types/id-guards.js.map +1 -0
- package/src/types/index.d.ts +2 -0
- package/src/types/index.d.ts.map +1 -0
- package/src/types/index.js +5 -0
- package/src/types/index.js.map +1 -0
- package/src/{types.ts → types.d.ts} +9 -28
- package/src/types.d.ts.map +1 -0
- package/src/types.js +6 -0
- package/src/types.js.map +1 -0
- package/src/utils.d.ts +11 -0
- package/src/utils.d.ts.map +1 -0
- package/src/utils.js +82 -0
- package/src/utils.js.map +1 -0
- package/LICENSE +0 -21
- package/src/builders/ecies-builder.ts +0 -27
- package/src/builders/member-builder.ts +0 -158
- package/src/constants.ts +0 -251
- package/src/core/errors/crypto-error.ts +0 -10
- package/src/core/types/result.ts +0 -3
- package/src/enumerations/index.ts +0 -2
- package/src/enumerations/pbkdf2-profile.ts +0 -8
- package/src/i18n/ecies-i18n-factory.ts +0 -111
- package/src/i18n/node-ecies-i18n-setup.ts +0 -56
- package/src/i18n/node-keys.ts +0 -69
- package/src/i18n/translations/de.ts +0 -54
- package/src/i18n/translations/en-GB.ts +0 -83
- package/src/i18n/translations/en-US.ts +0 -88
- package/src/i18n/translations/es.ts +0 -54
- package/src/i18n/translations/fr.ts +0 -54
- package/src/i18n/translations/ja.ts +0 -54
- package/src/i18n/translations/uk.ts +0 -54
- package/src/i18n/translations/zh-cn.ts +0 -54
- package/src/interfaces/authenticated-cipher.ts +0 -10
- package/src/interfaces/authenticated-decipher.ts +0 -9
- package/src/interfaces/backend-member-operational.ts +0 -75
- package/src/interfaces/checksum-config.ts +0 -4
- package/src/interfaces/checksum-consts.ts +0 -13
- package/src/interfaces/constants.ts +0 -54
- package/src/interfaces/ecies-consts.ts +0 -99
- package/src/interfaces/encrypted-chunk.ts +0 -12
- package/src/interfaces/encryption-consts.ts +0 -10
- package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.ts +0 -7
- package/src/interfaces/keyring-consts.ts +0 -5
- package/src/interfaces/member.ts +0 -76
- package/src/interfaces/multi-encrypted-parsed-header.ts +0 -28
- package/src/interfaces/multi-recipient-chunk.ts +0 -35
- package/src/interfaces/pbkdf2-result.ts +0 -5
- package/src/interfaces/signing-key-private-key-info.ts +0 -12
- package/src/interfaces/simple-public-key-only-buffer.ts +0 -3
- package/src/interfaces/simple-public-key-only.ts +0 -3
- package/src/interfaces/single-encrypted-parsed-header.ts +0 -35
- package/src/interfaces/stream-config.ts +0 -9
- package/src/interfaces/stream-progress.ts +0 -7
- package/src/interfaces/wrapped-key-consts.ts +0 -6
- package/src/lib/crypto-container.ts +0 -32
- package/src/lib/invariant-validator.ts +0 -124
- package/src/lib/invariants/recipient-id-consistency.ts +0 -77
- package/src/member.ts +0 -511
- package/src/services/aes-gcm.ts +0 -260
- package/src/services/chunk-processor.ts +0 -47
- package/src/services/ecies/crypto-core.ts +0 -319
- package/src/services/ecies/file.ts +0 -171
- package/src/services/ecies/multi-recipient.ts +0 -782
- package/src/services/ecies/service.ts +0 -316
- package/src/services/ecies/signature.ts +0 -91
- package/src/services/ecies/single-recipient.ts +0 -743
- package/src/services/ecies/utilities.ts +0 -128
- package/src/services/encryption-stream.ts +0 -432
- package/src/services/multi-recipient-processor.ts +0 -505
- package/src/services/pbkdf2.ts +0 -304
- package/src/services/progress-tracker.ts +0 -43
- package/src/test-mocks/index.ts +0 -1
- package/src/test-mocks/mock-backend-member.ts +0 -195
- package/src/testing.ts +0 -2
- package/src/types/id-guards.ts +0 -91
- package/src/types/index.ts +0 -1
- package/src/utils.ts +0 -124
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AESGCMService = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const i18n_1 = require("../i18n");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
class AESGCMService {
|
|
8
|
+
algorithmName;
|
|
9
|
+
mode;
|
|
10
|
+
keyBits;
|
|
11
|
+
ivSize;
|
|
12
|
+
keyringAlgorithmConfiguration;
|
|
13
|
+
constructor(constants = constants_1.Constants) {
|
|
14
|
+
this.algorithmName = constants.KEYRING.ALGORITHM;
|
|
15
|
+
this.mode = constants.KEYRING.MODE;
|
|
16
|
+
this.keyBits = constants.KEYRING.KEY_BITS;
|
|
17
|
+
this.ivSize = constants.WRAPPED_KEY.IV_SIZE;
|
|
18
|
+
this.keyringAlgorithmConfiguration =
|
|
19
|
+
constants.KEYRING_ALGORITHM_CONFIGURATION;
|
|
20
|
+
}
|
|
21
|
+
get ALGORITHM_NAME() {
|
|
22
|
+
return this.algorithmName;
|
|
23
|
+
}
|
|
24
|
+
get MODE() {
|
|
25
|
+
return this.mode;
|
|
26
|
+
}
|
|
27
|
+
get KEY_BITS() {
|
|
28
|
+
return this.keyBits;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Encrypt data using AES-GCM
|
|
32
|
+
* @param data Data to encrypt
|
|
33
|
+
* @param key Key to use for encryption (must be 16, 24 or 32 bytes for AES)
|
|
34
|
+
* @param authTag Whether to return separate auth tag
|
|
35
|
+
* @returns Encrypted data with IV and optional separate auth tag
|
|
36
|
+
*/
|
|
37
|
+
encrypt(data, key, authTag = false, aad) {
|
|
38
|
+
// Security fix 9: Key length validation - must match algorithm requirements
|
|
39
|
+
const requiredKeyLength = this.keyBits / 8;
|
|
40
|
+
if (key.length !== requiredKeyLength) {
|
|
41
|
+
const pluginEngine = (0, i18n_1.getEciesPluginI18nEngine)();
|
|
42
|
+
throw new Error(pluginEngine.translate(i18n_1.NodeEciesComponentId, i18n_1.NodeEciesStringKey.Error_InvalidAESKeyLength));
|
|
43
|
+
}
|
|
44
|
+
// Security fix 11: Data null/undefined check
|
|
45
|
+
if (data === null || data === undefined) {
|
|
46
|
+
const pluginEngine = (0, i18n_1.getEciesPluginI18nEngine)();
|
|
47
|
+
throw new Error(pluginEngine.translate(i18n_1.NodeEciesComponentId, i18n_1.NodeEciesStringKey.Error_CannotEncryptEmptyData));
|
|
48
|
+
}
|
|
49
|
+
// Security fix 12: Data size validation (max 2GB)
|
|
50
|
+
if (data.length > 0x7FFFFFFF) {
|
|
51
|
+
const pluginEngine = (0, i18n_1.getEciesPluginI18nEngine)();
|
|
52
|
+
throw new Error(pluginEngine.translate(i18n_1.NodeEciesComponentId, i18n_1.NodeEciesStringKey.Error_MessageTooLarge));
|
|
53
|
+
}
|
|
54
|
+
const iv = (0, crypto_1.randomBytes)(this.ivSize);
|
|
55
|
+
const cipher = (0, crypto_1.createCipheriv)(this.keyringAlgorithmConfiguration, key, iv);
|
|
56
|
+
if (aad) {
|
|
57
|
+
cipher.setAAD(aad);
|
|
58
|
+
}
|
|
59
|
+
const encrypted = Buffer.concat([cipher.update(data), cipher.final()]);
|
|
60
|
+
const tag = cipher.getAuthTag();
|
|
61
|
+
if (!authTag) {
|
|
62
|
+
const encryptedWithTag = Buffer.concat([encrypted, tag]);
|
|
63
|
+
return { encrypted: encryptedWithTag, iv: iv };
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
encrypted: encrypted,
|
|
67
|
+
iv: iv,
|
|
68
|
+
tag: tag,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Combine encrypted data and auth tag into a single Buffer
|
|
73
|
+
* @param encryptedData The encrypted data
|
|
74
|
+
* @param authTag The authentication tag
|
|
75
|
+
* @returns The combined Buffer
|
|
76
|
+
*/
|
|
77
|
+
combineEncryptedDataAndTag(encryptedData, authTag) {
|
|
78
|
+
return Buffer.concat([encryptedData, authTag]);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Combine IV and encrypted data (with optional auth tag) into a single Buffer
|
|
82
|
+
* @param iv The initialization vector
|
|
83
|
+
* @param encryptedDataWithTag The encrypted data with auth tag already appended (if applicable)
|
|
84
|
+
* @returns The combined Buffer
|
|
85
|
+
*/
|
|
86
|
+
combineIvAndEncryptedData(iv, encryptedDataWithTag) {
|
|
87
|
+
return Buffer.concat([iv, encryptedDataWithTag]);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Combine IV, encrypted data and auth tag into a single Buffer
|
|
91
|
+
* @param iv The initialization vector
|
|
92
|
+
* @param encryptedData The encrypted data
|
|
93
|
+
* @param authTag The authentication tag
|
|
94
|
+
* @returns The combined Buffer
|
|
95
|
+
*/
|
|
96
|
+
combineIvTagAndEncryptedData(iv, encryptedData, authTag) {
|
|
97
|
+
const encryptedWithTag = this.combineEncryptedDataAndTag(encryptedData, authTag);
|
|
98
|
+
return this.combineIvAndEncryptedData(iv, encryptedWithTag);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Split combined encrypted data back into its components
|
|
102
|
+
* @param combinedData The combined data containing IV, encrypted data, and optionally auth tag
|
|
103
|
+
* @param hasAuthTag Whether the combined data includes an authentication tag
|
|
104
|
+
* @returns Object containing the split components
|
|
105
|
+
*/
|
|
106
|
+
splitEncryptedData(combinedData, hasAuthTag = true) {
|
|
107
|
+
const ivLength = this.ivSize;
|
|
108
|
+
const minLength = ivLength + (hasAuthTag ? 16 : 0);
|
|
109
|
+
if (combinedData.length < minLength) {
|
|
110
|
+
const pluginEngine = (0, i18n_1.getEciesPluginI18nEngine)();
|
|
111
|
+
throw new Error(pluginEngine.translate(i18n_1.NodeEciesComponentId, i18n_1.NodeEciesStringKey.Error_CombinedDataTooShort));
|
|
112
|
+
}
|
|
113
|
+
const iv = combinedData.subarray(0, ivLength);
|
|
114
|
+
const encryptedDataWithTag = combinedData.subarray(ivLength);
|
|
115
|
+
return { iv, encryptedDataWithTag };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Decrypt data using AES-GCM
|
|
119
|
+
* @param iv The initialization vector
|
|
120
|
+
* @param encryptedData Data to decrypt (with auth tag appended)
|
|
121
|
+
* @param key Key to use for decryption (must be 16, 24 or 32 bytes for AES)
|
|
122
|
+
* @param authTag Whether the encrypted data includes an authentication tag
|
|
123
|
+
* @returns Decrypted data
|
|
124
|
+
*/
|
|
125
|
+
decrypt(iv, encryptedData, key, authTag = false, aad) {
|
|
126
|
+
// Security fix 9: Key length validation - must match algorithm requirements
|
|
127
|
+
const requiredKeyLength = this.keyBits / 8;
|
|
128
|
+
if (key.length !== requiredKeyLength) {
|
|
129
|
+
const pluginEngine = (0, i18n_1.getEciesPluginI18nEngine)();
|
|
130
|
+
throw new Error(pluginEngine.translate(i18n_1.NodeEciesComponentId, i18n_1.NodeEciesStringKey.Error_InvalidAESKeyLength));
|
|
131
|
+
}
|
|
132
|
+
// Security fix 10: IV length validation
|
|
133
|
+
if (iv.length !== 16) {
|
|
134
|
+
const pluginEngine = (0, i18n_1.getEciesPluginI18nEngine)();
|
|
135
|
+
throw new Error(pluginEngine.translate(i18n_1.NodeEciesComponentId, i18n_1.NodeEciesStringKey.Error_InvalidIVLength));
|
|
136
|
+
}
|
|
137
|
+
// Security fix 13: Decrypt input validation
|
|
138
|
+
if (encryptedData === null || encryptedData === undefined) {
|
|
139
|
+
const pluginEngine = (0, i18n_1.getEciesPluginI18nEngine)();
|
|
140
|
+
throw new Error(pluginEngine.translate(i18n_1.NodeEciesComponentId, i18n_1.NodeEciesStringKey.Error_CannotDecryptEmptyData));
|
|
141
|
+
}
|
|
142
|
+
if (encryptedData.length > 0x7FFFFFFF) {
|
|
143
|
+
const pluginEngine = (0, i18n_1.getEciesPluginI18nEngine)();
|
|
144
|
+
throw new Error(pluginEngine.translate(i18n_1.NodeEciesComponentId, i18n_1.NodeEciesStringKey.Error_MessageTooLarge));
|
|
145
|
+
}
|
|
146
|
+
const decipher = (0, crypto_1.createDecipheriv)(this.keyringAlgorithmConfiguration, key, iv);
|
|
147
|
+
if (aad) {
|
|
148
|
+
decipher.setAAD(aad);
|
|
149
|
+
}
|
|
150
|
+
const tagLength = 16;
|
|
151
|
+
const tag = encryptedData.subarray(-tagLength);
|
|
152
|
+
const ciphertext = encryptedData.subarray(0, -tagLength);
|
|
153
|
+
decipher.setAuthTag(tag);
|
|
154
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.AESGCMService = AESGCMService;
|
|
158
|
+
//# sourceMappingURL=aes-gcm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aes-gcm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,CAAC;QACvB,CAAC;QAED,MAAM,SAAS,GAAG,EAAE,CAAC;QACrB,MAAM,GAAG,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC;QAC/C,MAAM,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;QAEzD,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAEzB,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACxE,CAAC;CACF;AAzPD,sCAyPC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IEncryptedChunk } from '../interfaces/encrypted-chunk';
|
|
2
|
+
import { ECIESService } from './ecies/service';
|
|
3
|
+
export declare class ChunkProcessor {
|
|
4
|
+
private readonly ecies;
|
|
5
|
+
constructor(ecies: ECIESService);
|
|
6
|
+
encryptChunk(data: Buffer, publicKey: Buffer, chunkIndex: number, isLast: boolean, includeChecksums?: boolean): Promise<IEncryptedChunk>;
|
|
7
|
+
decryptChunk(chunkData: Buffer, privateKey: Buffer): Promise<{
|
|
8
|
+
data: Buffer;
|
|
9
|
+
header: {
|
|
10
|
+
index: number;
|
|
11
|
+
flags: number;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=chunk-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-processor.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/services/chunk-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,YAAY;IAEnC,YAAY,CACvB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,OAAO,EACf,gBAAgB,GAAE,OAAe,GAChC,OAAO,CAAC,eAAe,CAAC;IAkBd,YAAY,CACvB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CAavE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChunkProcessor = void 0;
|
|
4
|
+
class ChunkProcessor {
|
|
5
|
+
ecies;
|
|
6
|
+
constructor(ecies) {
|
|
7
|
+
this.ecies = ecies;
|
|
8
|
+
}
|
|
9
|
+
async encryptChunk(data, publicKey, chunkIndex, isLast, includeChecksums = false) {
|
|
10
|
+
const encrypted = this.ecies.encryptSimpleOrSingle(false, publicKey, data);
|
|
11
|
+
// Prepend chunk header: 4 bytes index + 1 byte flags
|
|
12
|
+
const header = Buffer.alloc(5);
|
|
13
|
+
header.writeUInt32BE(chunkIndex, 0);
|
|
14
|
+
header.writeUInt8(isLast ? 1 : 0, 4);
|
|
15
|
+
const dataWithHeader = Buffer.concat([header, encrypted]);
|
|
16
|
+
return {
|
|
17
|
+
index: chunkIndex,
|
|
18
|
+
data: dataWithHeader,
|
|
19
|
+
isLast,
|
|
20
|
+
metadata: includeChecksums ? { totalChunks: chunkIndex + 1 } : undefined,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async decryptChunk(chunkData, privateKey) {
|
|
24
|
+
// Extract chunk header: 4 bytes index + 1 byte flags
|
|
25
|
+
const index = chunkData.readUInt32BE(0);
|
|
26
|
+
const flags = chunkData.readUInt8(4);
|
|
27
|
+
const encrypted = chunkData.subarray(5);
|
|
28
|
+
const decrypted = this.ecies.decryptSimpleOrSingleWithHeader(false, privateKey, encrypted);
|
|
29
|
+
return {
|
|
30
|
+
data: decrypted,
|
|
31
|
+
header: { index, flags },
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ChunkProcessor = ChunkProcessor;
|
|
36
|
+
//# sourceMappingURL=chunk-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-processor.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/services/chunk-processor.ts"],"names":[],"mappings":";;;AAGA,MAAa,cAAc;IACI;IAA7B,YAA6B,KAAmB;QAAnB,UAAK,GAAL,KAAK,CAAc;IAAG,CAAC;IAE7C,KAAK,CAAC,YAAY,CACvB,IAAY,EACZ,SAAiB,EACjB,UAAkB,EAClB,MAAe,EACf,mBAA4B,KAAK;QAEjC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QAE3E,qDAAqD;QACrD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC/B,MAAM,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;QACpC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAErC,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;QAE1D,OAAO;YACL,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,cAAc;YACpB,MAAM;YACN,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,UAAU,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;SACzE,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,YAAY,CACvB,SAAiB,EACjB,UAAkB;QAElB,qDAAqD;QACrD,MAAM,KAAK,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QACxC,MAAM,KAAK,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACrC,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAExC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,+BAA+B,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;QAE3F,OAAO;YACL,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;SACzB,CAAC;IACJ,CAAC;CACF;AA3CD,wCA2CC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { IECIESConfig, IECIESConstants, SecureString } from '@digitaldefiance/ecies-lib';
|
|
2
|
+
import { Wallet } from '@ethereumjs/wallet';
|
|
3
|
+
import { ISimpleKeyPairBuffer } from '../../interfaces/simple-keypair-buffer';
|
|
4
|
+
import { IWalletSeed } from '../../interfaces/wallet-seed';
|
|
5
|
+
/**
|
|
6
|
+
* Core encryption and decryption functions for ECIES
|
|
7
|
+
* Includes coverage for simple and single modes, does not cover multiple mode which is in a separate module
|
|
8
|
+
*/
|
|
9
|
+
export declare class EciesCryptoCore {
|
|
10
|
+
protected readonly _config: IECIESConfig;
|
|
11
|
+
protected readonly _consts: IECIESConstants;
|
|
12
|
+
get config(): IECIESConfig;
|
|
13
|
+
get consts(): IECIESConstants;
|
|
14
|
+
constructor(config: IECIESConfig, eciesParams?: IECIESConstants);
|
|
15
|
+
/**
|
|
16
|
+
* Validates and normalizes a public key for ECIES operations
|
|
17
|
+
* @param publicKey The public key to normalize
|
|
18
|
+
* @returns Properly formatted public key
|
|
19
|
+
*/
|
|
20
|
+
normalizePublicKey(publicKey: Buffer): Buffer;
|
|
21
|
+
/**
|
|
22
|
+
* Generate a new mnemonic
|
|
23
|
+
* @returns {SecureString} The new mnemonic
|
|
24
|
+
*/
|
|
25
|
+
generateNewMnemonic(): SecureString;
|
|
26
|
+
/**
|
|
27
|
+
* Generate a new wallet from a seed
|
|
28
|
+
* @param seed {Buffer} The seed to generate the wallet from
|
|
29
|
+
* @returns {Wallet} The new wallet
|
|
30
|
+
*/
|
|
31
|
+
walletFromSeed(seed: Buffer): Wallet;
|
|
32
|
+
/**
|
|
33
|
+
* Generate a new wallet and seed from a mnemonic
|
|
34
|
+
* @param mnemonic {SecureString} The mnemonic to generate the wallet and seed from
|
|
35
|
+
* @returns {IWalletSeed} The new wallet and seed
|
|
36
|
+
*/
|
|
37
|
+
walletAndSeedFromMnemonic(mnemonic: SecureString): IWalletSeed;
|
|
38
|
+
/**
|
|
39
|
+
* Generate a new wallet and seed from a mnemonic
|
|
40
|
+
* @param wallet {Wallet} The wallet to generate the key pair from
|
|
41
|
+
* @returns {ISimpleKeyPairBuffer} The new key pair
|
|
42
|
+
*/
|
|
43
|
+
walletToSimpleKeyPairBuffer(wallet: Wallet): ISimpleKeyPairBuffer;
|
|
44
|
+
/**
|
|
45
|
+
* Create a simple key pair from a seed
|
|
46
|
+
* @param seed {Buffer} The seed to generate the key pair from
|
|
47
|
+
* @returns {ISimpleKeyPairBuffer} The new key pair
|
|
48
|
+
*/
|
|
49
|
+
seedToSimpleKeyPairBuffer(seed: Buffer): ISimpleKeyPairBuffer;
|
|
50
|
+
/**
|
|
51
|
+
* Create a simple key pair from a mnemonic
|
|
52
|
+
* @param mnemonic {SecureString} The mnemonic to generate the key pair from
|
|
53
|
+
* @returns {ISimpleKeyPairBuffer} The new key pair
|
|
54
|
+
*/
|
|
55
|
+
mnemonicToSimpleKeyPairBuffer(mnemonic: SecureString): ISimpleKeyPairBuffer;
|
|
56
|
+
/**
|
|
57
|
+
* Generate a random private key
|
|
58
|
+
* @returns {Buffer} The new private key
|
|
59
|
+
*/
|
|
60
|
+
generatePrivateKey(): Buffer;
|
|
61
|
+
/**
|
|
62
|
+
* Get public key from private key
|
|
63
|
+
* @param privateKey {Buffer} The private key
|
|
64
|
+
* @returns {Buffer} The public key
|
|
65
|
+
*/
|
|
66
|
+
getPublicKey(privateKey: Buffer): Buffer;
|
|
67
|
+
/**
|
|
68
|
+
* Generate ephemeral key pair for ECIES
|
|
69
|
+
* @returns {Promise<ISimpleKeyPairBuffer>} The key pair
|
|
70
|
+
*/
|
|
71
|
+
generateEphemeralKeyPair(): Promise<{
|
|
72
|
+
privateKey: Buffer;
|
|
73
|
+
publicKey: Buffer;
|
|
74
|
+
}>;
|
|
75
|
+
/**
|
|
76
|
+
* Compute ECDH shared secret
|
|
77
|
+
* @param privateKey {Buffer} The private key
|
|
78
|
+
* @param publicKey {Buffer} The public key
|
|
79
|
+
* @returns {Buffer} The shared secret
|
|
80
|
+
*/
|
|
81
|
+
computeSharedSecret(privateKey: Buffer, publicKey: Buffer): Buffer;
|
|
82
|
+
/**
|
|
83
|
+
* Derive a symmetric key from a shared secret using HKDF
|
|
84
|
+
* @param sharedSecret The shared secret (ECDH output)
|
|
85
|
+
* @param salt Optional salt
|
|
86
|
+
* @param info Optional context info
|
|
87
|
+
* @param length Length of the output key (default 32 for AES-256)
|
|
88
|
+
*/
|
|
89
|
+
deriveSharedKey(sharedSecret: Buffer, salt?: Buffer, info?: Buffer, length?: number): Buffer;
|
|
90
|
+
/**
|
|
91
|
+
* Sign a message using ECDSA
|
|
92
|
+
* @param privateKey The private key to sign with
|
|
93
|
+
* @param message The message to sign
|
|
94
|
+
*/
|
|
95
|
+
sign(privateKey: Buffer, message: Buffer): Buffer;
|
|
96
|
+
/**
|
|
97
|
+
* Verify a signature using ECDSA
|
|
98
|
+
* @param publicKey The public key to verify with
|
|
99
|
+
* @param message The message that was signed
|
|
100
|
+
* @param signature The signature to verify
|
|
101
|
+
*/
|
|
102
|
+
verify(publicKey: Buffer, message: Buffer, signature: Buffer): boolean;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=crypto-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto-core.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/services/ecies/crypto-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EACZ,eAAe,EAEf,YAAY,EACb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAS,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAUnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAG3D;;;GAGG;AACH,qBAAa,eAAe;IAC1B,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IACzC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAC5C,IAAW,MAAM,IAAI,YAAY,CAEhC;IAED,IAAW,MAAM,IAAI,eAAe,CAEnC;gBAGC,MAAM,EAAE,YAAY,EACpB,WAAW,GAAE,eAAiC;IAMhD;;;;OAIG;IACI,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IA+EpD;;;OAGG;IACI,mBAAmB,IAAI,YAAY;IAI1C;;;;OAIG;IACI,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAO3C;;;;OAIG;IACI,yBAAyB,CAAC,QAAQ,EAAE,YAAY,GAAG,WAAW;IAiBrE;;;;OAIG;IACI,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB;IAUxE;;;;OAIG;IACI,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB;IAKpE;;;;OAIG;IACI,6BAA6B,CAClC,QAAQ,EAAE,YAAY,GACrB,oBAAoB;IAKvB;;;OAGG;IACI,kBAAkB,IAAI,MAAM;IAInC;;;;OAIG;IACI,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAY/C;;;OAGG;IACU,wBAAwB,IAAI,OAAO,CAAC;QAC/C,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IAMF;;;;;OAKG;IACI,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM;IAyBzE;;;;;;OAMG;IACI,eAAe,CACpB,YAAY,EAAE,MAAM,EACpB,IAAI,GAAE,MAAwB,EAC9B,IAAI,GAAE,MAAwB,EAC9B,MAAM,GAAE,MAAW,GAClB,MAAM;IAIT;;;;OAIG;IACI,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM;IAMxD;;;;;OAKG;IACI,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO;CAQ9E"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EciesCryptoCore = void 0;
|
|
4
|
+
const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
5
|
+
const wallet_1 = require("@ethereumjs/wallet");
|
|
6
|
+
const bip39_1 = require("bip39");
|
|
7
|
+
const secp256k1_js_1 = require("ethereum-cryptography/secp256k1.js");
|
|
8
|
+
const crypto_1 = require("crypto");
|
|
9
|
+
const ecies_i18n_factory_1 = require("../../i18n/ecies-i18n-factory");
|
|
10
|
+
const constants_1 = require("../../constants");
|
|
11
|
+
/**
|
|
12
|
+
* Core encryption and decryption functions for ECIES
|
|
13
|
+
* Includes coverage for simple and single modes, does not cover multiple mode which is in a separate module
|
|
14
|
+
*/
|
|
15
|
+
class EciesCryptoCore {
|
|
16
|
+
_config;
|
|
17
|
+
_consts;
|
|
18
|
+
get config() {
|
|
19
|
+
return this._config;
|
|
20
|
+
}
|
|
21
|
+
get consts() {
|
|
22
|
+
return this._consts;
|
|
23
|
+
}
|
|
24
|
+
constructor(config, eciesParams = constants_1.Constants.ECIES) {
|
|
25
|
+
this._config = config;
|
|
26
|
+
this._consts = eciesParams;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Validates and normalizes a public key for ECIES operations
|
|
30
|
+
* @param publicKey The public key to normalize
|
|
31
|
+
* @returns Properly formatted public key
|
|
32
|
+
*/
|
|
33
|
+
normalizePublicKey(publicKey) {
|
|
34
|
+
if (!publicKey) {
|
|
35
|
+
const pluginEngine = (0, ecies_i18n_factory_1.getEciesPluginI18nEngine)();
|
|
36
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEphemeralPublicKey, undefined, undefined, {
|
|
37
|
+
error: pluginEngine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_InvalidPublicKey),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const keyLength = publicKey.length;
|
|
41
|
+
// console.log('[normalizePublicKey] Magic:', this._consts.PUBLIC_KEY_MAGIC);
|
|
42
|
+
// Check for compressed key (33 bytes, starts with 0x02 or 0x03)
|
|
43
|
+
if (keyLength === 33 &&
|
|
44
|
+
(publicKey[0] === 0x02 || publicKey[0] === 0x03)) {
|
|
45
|
+
return publicKey;
|
|
46
|
+
}
|
|
47
|
+
// Check for uncompressed key (65 bytes, starts with 0x04)
|
|
48
|
+
if (keyLength === 65 &&
|
|
49
|
+
publicKey[0] === 0x04) {
|
|
50
|
+
return publicKey;
|
|
51
|
+
}
|
|
52
|
+
// Raw key without prefix (64 bytes) - add the 0x04 prefix
|
|
53
|
+
if (keyLength === 64) {
|
|
54
|
+
return Buffer.concat([
|
|
55
|
+
Buffer.from([0x04]),
|
|
56
|
+
publicKey,
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
// Raw key without prefix (32 bytes) - add the 0x02 prefix (assuming even Y)
|
|
60
|
+
// Note: This is ambiguous for compressed keys as we don't know Y parity.
|
|
61
|
+
// But if we assume it's a raw X coordinate, we might default to 0x02?
|
|
62
|
+
// Actually, RAW_PUBLIC_KEY_LENGTH is 32.
|
|
63
|
+
if (keyLength === this._consts.RAW_PUBLIC_KEY_LENGTH) {
|
|
64
|
+
// If we only have X, we can't fully reconstruct without knowing Y parity.
|
|
65
|
+
// But maybe the intention of RAW_PUBLIC_KEY_LENGTH was for uncompressed without prefix (64 bytes)?
|
|
66
|
+
// The constants say RAW_PUBLIC_KEY_LENGTH = 32.
|
|
67
|
+
// So it expects X coordinate only.
|
|
68
|
+
// We can try to prepend 0x02.
|
|
69
|
+
return Buffer.concat([
|
|
70
|
+
Buffer.from([this._consts.PUBLIC_KEY_MAGIC]),
|
|
71
|
+
publicKey,
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
const pluginEngine = (0, ecies_i18n_factory_1.getEciesPluginI18nEngine)();
|
|
75
|
+
// Invalid format
|
|
76
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEphemeralPublicKey, undefined, undefined, {
|
|
77
|
+
error: pluginEngine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_InvalidPublicKeyFormat),
|
|
78
|
+
keyLength: String(keyLength),
|
|
79
|
+
expectedLength64: String(this._consts.RAW_PUBLIC_KEY_LENGTH),
|
|
80
|
+
expectedLength65: String(this._consts.PUBLIC_KEY_LENGTH),
|
|
81
|
+
keyPrefix: keyLength > 0 ? String(publicKey[0]) : 'N/A',
|
|
82
|
+
expectedPrefix: String(this._consts.PUBLIC_KEY_MAGIC),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Generate a new mnemonic
|
|
87
|
+
* @returns {SecureString} The new mnemonic
|
|
88
|
+
*/
|
|
89
|
+
generateNewMnemonic() {
|
|
90
|
+
return new ecies_lib_1.SecureString((0, bip39_1.generateMnemonic)(this._config.mnemonicStrength));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Generate a new wallet from a seed
|
|
94
|
+
* @param seed {Buffer} The seed to generate the wallet from
|
|
95
|
+
* @returns {Wallet} The new wallet
|
|
96
|
+
*/
|
|
97
|
+
walletFromSeed(seed) {
|
|
98
|
+
const hdWallet = wallet_1.hdkey.EthereumHDKey.fromMasterSeed(seed);
|
|
99
|
+
return hdWallet
|
|
100
|
+
.derivePath(this._config.primaryKeyDerivationPath)
|
|
101
|
+
.getWallet();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Generate a new wallet and seed from a mnemonic
|
|
105
|
+
* @param mnemonic {SecureString} The mnemonic to generate the wallet and seed from
|
|
106
|
+
* @returns {IWalletSeed} The new wallet and seed
|
|
107
|
+
*/
|
|
108
|
+
walletAndSeedFromMnemonic(mnemonic) {
|
|
109
|
+
if (!mnemonic.value || !(0, bip39_1.validateMnemonic)(mnemonic.value)) {
|
|
110
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidMnemonic, (0, ecies_i18n_factory_1.createEciesTranslationEngine)());
|
|
111
|
+
}
|
|
112
|
+
const seed = (0, bip39_1.mnemonicToSeedSync)(mnemonic.value);
|
|
113
|
+
const wallet = this.walletFromSeed(seed);
|
|
114
|
+
return {
|
|
115
|
+
seed: new ecies_lib_1.SecureBuffer(seed),
|
|
116
|
+
wallet,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Generate a new wallet and seed from a mnemonic
|
|
121
|
+
* @param wallet {Wallet} The wallet to generate the key pair from
|
|
122
|
+
* @returns {ISimpleKeyPairBuffer} The new key pair
|
|
123
|
+
*/
|
|
124
|
+
walletToSimpleKeyPairBuffer(wallet) {
|
|
125
|
+
const privateKey = Buffer.from(wallet.getPrivateKey());
|
|
126
|
+
const publicKey = this.getPublicKey(privateKey);
|
|
127
|
+
return {
|
|
128
|
+
privateKey,
|
|
129
|
+
publicKey,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Create a simple key pair from a seed
|
|
134
|
+
* @param seed {Buffer} The seed to generate the key pair from
|
|
135
|
+
* @returns {ISimpleKeyPairBuffer} The new key pair
|
|
136
|
+
*/
|
|
137
|
+
seedToSimpleKeyPairBuffer(seed) {
|
|
138
|
+
const wallet = this.walletFromSeed(seed);
|
|
139
|
+
return this.walletToSimpleKeyPairBuffer(wallet);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Create a simple key pair from a mnemonic
|
|
143
|
+
* @param mnemonic {SecureString} The mnemonic to generate the key pair from
|
|
144
|
+
* @returns {ISimpleKeyPairBuffer} The new key pair
|
|
145
|
+
*/
|
|
146
|
+
mnemonicToSimpleKeyPairBuffer(mnemonic) {
|
|
147
|
+
const { seed } = this.walletAndSeedFromMnemonic(mnemonic);
|
|
148
|
+
return this.seedToSimpleKeyPairBuffer(Buffer.from(seed.value));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Generate a random private key
|
|
152
|
+
* @returns {Buffer} The new private key
|
|
153
|
+
*/
|
|
154
|
+
generatePrivateKey() {
|
|
155
|
+
return Buffer.from(secp256k1_js_1.secp256k1.utils.randomPrivateKey());
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Get public key from private key
|
|
159
|
+
* @param privateKey {Buffer} The private key
|
|
160
|
+
* @returns {Buffer} The public key
|
|
161
|
+
*/
|
|
162
|
+
getPublicKey(privateKey) {
|
|
163
|
+
// Security fix 2: Private key validation
|
|
164
|
+
if (privateKey.every(byte => byte === 0)) {
|
|
165
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.PrivateKeyNotLoaded, (0, ecies_i18n_factory_1.createEciesTranslationEngine)());
|
|
166
|
+
}
|
|
167
|
+
const publicKey = secp256k1_js_1.secp256k1.getPublicKey(privateKey, true);
|
|
168
|
+
return Buffer.from(publicKey);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Generate ephemeral key pair for ECIES
|
|
172
|
+
* @returns {Promise<ISimpleKeyPairBuffer>} The key pair
|
|
173
|
+
*/
|
|
174
|
+
async generateEphemeralKeyPair() {
|
|
175
|
+
const privateKey = this.generatePrivateKey();
|
|
176
|
+
const publicKey = this.getPublicKey(privateKey);
|
|
177
|
+
return { privateKey, publicKey };
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Compute ECDH shared secret
|
|
181
|
+
* @param privateKey {Buffer} The private key
|
|
182
|
+
* @param publicKey {Buffer} The public key
|
|
183
|
+
* @returns {Buffer} The shared secret
|
|
184
|
+
*/
|
|
185
|
+
computeSharedSecret(privateKey, publicKey) {
|
|
186
|
+
// Security fix 1: Public key validation (check normalized key)
|
|
187
|
+
const normalizedKey = this.normalizePublicKey(publicKey);
|
|
188
|
+
const isAllZeros = normalizedKey.slice(1).every(byte => byte === 0);
|
|
189
|
+
if (isAllZeros) {
|
|
190
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidRecipientPublicKey, (0, ecies_i18n_factory_1.createEciesTranslationEngine)());
|
|
191
|
+
}
|
|
192
|
+
const sharedSecret = secp256k1_js_1.secp256k1.getSharedSecret(privateKey, normalizedKey, true);
|
|
193
|
+
const secret = Buffer.from(sharedSecret.slice(1)); // Remove the 0x02/0x03 prefix
|
|
194
|
+
// Security fix 3: Shared secret validation
|
|
195
|
+
if (secret.every(byte => byte === 0)) {
|
|
196
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.SecretComputationFailed, (0, ecies_i18n_factory_1.createEciesTranslationEngine)());
|
|
197
|
+
}
|
|
198
|
+
return secret;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Derive a symmetric key from a shared secret using HKDF
|
|
202
|
+
* @param sharedSecret The shared secret (ECDH output)
|
|
203
|
+
* @param salt Optional salt
|
|
204
|
+
* @param info Optional context info
|
|
205
|
+
* @param length Length of the output key (default 32 for AES-256)
|
|
206
|
+
*/
|
|
207
|
+
deriveSharedKey(sharedSecret, salt = Buffer.alloc(0), info = Buffer.alloc(0), length = 32) {
|
|
208
|
+
return Buffer.from((0, crypto_1.hkdfSync)('sha256', sharedSecret, salt, info, length));
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Sign a message using ECDSA
|
|
212
|
+
* @param privateKey The private key to sign with
|
|
213
|
+
* @param message The message to sign
|
|
214
|
+
*/
|
|
215
|
+
sign(privateKey, message) {
|
|
216
|
+
const hash = (0, crypto_1.createHash)('sha256').update(message).digest();
|
|
217
|
+
const signature = secp256k1_js_1.secp256k1.sign(hash, privateKey);
|
|
218
|
+
return Buffer.from(signature.toCompactRawBytes());
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Verify a signature using ECDSA
|
|
222
|
+
* @param publicKey The public key to verify with
|
|
223
|
+
* @param message The message that was signed
|
|
224
|
+
* @param signature The signature to verify
|
|
225
|
+
*/
|
|
226
|
+
verify(publicKey, message, signature) {
|
|
227
|
+
const hash = (0, crypto_1.createHash)('sha256').update(message).digest();
|
|
228
|
+
try {
|
|
229
|
+
return secp256k1_js_1.secp256k1.verify(signature, hash, publicKey);
|
|
230
|
+
}
|
|
231
|
+
catch (e) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
exports.EciesCryptoCore = EciesCryptoCore;
|
|
237
|
+
//# sourceMappingURL=crypto-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto-core.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/services/ecies/crypto-core.ts"],"names":[],"mappings":";;;AAAA,0DAOoC;AACpC,+CAAmD;AACnD,iCAA+E;AAC/E,qEAA+D;AAC/D,mCAA8C;AAC9C,sEA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,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;QAC3D,IAAI,CAAC;YACH,OAAO,wBAAS,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF;AApSD,0CAoSC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ECIESService } from './service';
|
|
2
|
+
interface ChunkedFileHeader {
|
|
3
|
+
version: number;
|
|
4
|
+
chunkSize: number;
|
|
5
|
+
totalChunks: number;
|
|
6
|
+
originalSize: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class EciesFileService {
|
|
9
|
+
protected readonly eciesService: ECIESService;
|
|
10
|
+
protected readonly userPrivateKey: Buffer;
|
|
11
|
+
protected readonly config: {
|
|
12
|
+
chunkSize: number;
|
|
13
|
+
headerSize: number;
|
|
14
|
+
};
|
|
15
|
+
constructor(eciesService: ECIESService, userPrivateKey: Buffer, config?: {
|
|
16
|
+
chunkSize: number;
|
|
17
|
+
headerSize: number;
|
|
18
|
+
});
|
|
19
|
+
decryptFile(encryptedData: Buffer): Buffer;
|
|
20
|
+
encryptFileFromPath(filePath: string, recipientPublicKey: Buffer): Buffer;
|
|
21
|
+
decryptFileToPath(encryptedData: Buffer, outputPath: string): void;
|
|
22
|
+
protected serializeHeader(header: ChunkedFileHeader): Buffer;
|
|
23
|
+
protected deserializeHeader(data: Buffer): ChunkedFileHeader;
|
|
24
|
+
protected parseEncryptedFile(encryptedData: Buffer): {
|
|
25
|
+
header: ChunkedFileHeader;
|
|
26
|
+
chunks: Buffer[];
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/services/ecies/file.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,UAAU,iBAAiB;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,gBAAgB;IAC3B,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IAC9C,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAC1C,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;gBAGnE,YAAY,EAAE,YAAY,EAC1B,cAAc,EAAE,MAAM,EACtB,MAAM,GAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAG9C;IAOH,WAAW,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;IAuB1C,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,MAAM;IAyCzE,iBAAiB,CAAC,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAwBlE,SAAS,CAAC,eAAe,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM;IAS5D,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB;IAS5D,SAAS,CAAC,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG;QACnD,MAAM,EAAE,iBAAiB,CAAC;QAC1B,MAAM,EAAE,MAAM,EAAE,CAAC;KAClB;CAiCF"}
|