@digitaldefiance/node-ecies-lib 4.4.9 → 4.4.12
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 +191 -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,496 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EciesMultiRecipient = void 0;
|
|
4
|
+
const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
const single_recipient_1 = require("./single-recipient");
|
|
7
|
+
/**
|
|
8
|
+
* Multiple recipient encryption/decryption functions for ECIES
|
|
9
|
+
*/
|
|
10
|
+
class EciesMultiRecipient {
|
|
11
|
+
cryptoCore;
|
|
12
|
+
singleRecipientCore;
|
|
13
|
+
constructor(cryptoCore) {
|
|
14
|
+
this.cryptoCore = cryptoCore;
|
|
15
|
+
this.singleRecipientCore = new single_recipient_1.EciesSingleRecipientCore(cryptoCore.config);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get the size of the header for a given encryption type
|
|
19
|
+
* @param recipientCount The number of recipients
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getHeaderSize(recipientCount) {
|
|
23
|
+
return (this.cryptoCore.consts.VERSION_SIZE +
|
|
24
|
+
this.cryptoCore.consts.CIPHER_SUITE_SIZE +
|
|
25
|
+
this.cryptoCore.consts.ENCRYPTION_TYPE_SIZE +
|
|
26
|
+
this.cryptoCore.consts.PUBLIC_KEY_LENGTH + // Shared ephemeral public key
|
|
27
|
+
this.cryptoCore.consts.MULTIPLE.DATA_LENGTH_SIZE +
|
|
28
|
+
this.cryptoCore.consts.MULTIPLE.RECIPIENT_COUNT_SIZE +
|
|
29
|
+
recipientCount * this.cryptoCore.consts.MULTIPLE.RECIPIENT_ID_SIZE +
|
|
30
|
+
recipientCount * this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Encrypt a message symmetric key with a public key
|
|
34
|
+
* @param receiverPublicKey The public key of the receiver
|
|
35
|
+
* @param messageSymmetricKey The message to encrypt
|
|
36
|
+
* @param ephemeralPrivateKey The ephemeral private key to use for encryption
|
|
37
|
+
* @param aad Additional Authenticated Data (optional)
|
|
38
|
+
* @returns The encrypted message
|
|
39
|
+
*/
|
|
40
|
+
encryptKey(receiverPublicKey, messageSymmetricKey, ephemeralPrivateKey, aad) {
|
|
41
|
+
// Compute shared secret
|
|
42
|
+
let sharedSecret;
|
|
43
|
+
try {
|
|
44
|
+
// Make sure we normalize the receiver's public key
|
|
45
|
+
const normalizedReceiverPublicKey = this.cryptoCore.normalizePublicKey(receiverPublicKey);
|
|
46
|
+
// Create ECDH instance with the ephemeral private key
|
|
47
|
+
const ecdh = (0, crypto_1.createECDH)(this.cryptoCore.config.curveName);
|
|
48
|
+
ecdh.setPrivateKey(ephemeralPrivateKey);
|
|
49
|
+
// Ensure we're using the properly formatted public key (with 0x04 prefix)
|
|
50
|
+
sharedSecret = ecdh.computeSecret(normalizedReceiverPublicKey);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.error('[ERROR][encrypt] Failed to compute shared secret:', error);
|
|
54
|
+
if (error instanceof Error) {
|
|
55
|
+
if ('code' in error &&
|
|
56
|
+
error.code === 'ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY') {
|
|
57
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidRecipientPublicKey, undefined, undefined, {
|
|
58
|
+
nodeError: error.code,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.SecretComputationFailed, undefined, undefined, {
|
|
62
|
+
error: error.message,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.SecretComputationFailed);
|
|
66
|
+
}
|
|
67
|
+
// Use HKDF to derive the key
|
|
68
|
+
const symKey = this.cryptoCore.deriveSharedKey(sharedSecret, Buffer.alloc(0), // No salt
|
|
69
|
+
Buffer.from('ecies-v2-key-derivation'), // Info
|
|
70
|
+
this.cryptoCore.consts.SYMMETRIC.KEY_SIZE);
|
|
71
|
+
const iv = (0, crypto_1.randomBytes)(this.cryptoCore.consts.IV_SIZE);
|
|
72
|
+
// Create cipher with the derived symmetric key
|
|
73
|
+
const cipher = (0, crypto_1.createCipheriv)(this.cryptoCore.consts.SYMMETRIC_ALGORITHM_CONFIGURATION, symKey, iv);
|
|
74
|
+
// Ensure auto padding is enabled
|
|
75
|
+
cipher.setAutoPadding(true);
|
|
76
|
+
// Set AAD if provided
|
|
77
|
+
if (aad) {
|
|
78
|
+
cipher.setAAD(aad);
|
|
79
|
+
}
|
|
80
|
+
// Encrypt the message
|
|
81
|
+
let encrypted = cipher.update(messageSymmetricKey);
|
|
82
|
+
encrypted = Buffer.concat([encrypted, cipher.final()]);
|
|
83
|
+
// Get and explicitly set the authentication tag to max tag length for consistency
|
|
84
|
+
const authTag = cipher.getAuthTag();
|
|
85
|
+
// Format: iv (16) | authTag (16) | encryptedData (32)
|
|
86
|
+
// Note: Ephemeral public key is now in the main header, not per-recipient
|
|
87
|
+
return Buffer.concat([iv, authTag, encrypted]);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Decrypts symmetric key encrypted with ECIES using a header
|
|
91
|
+
* @param privateKey The private key to decrypt the data
|
|
92
|
+
* @param encryptedKey The data to decrypt
|
|
93
|
+
* @param ephemeralPublicKey The ephemeral public key from the header
|
|
94
|
+
* @param aad Additional Authenticated Data (optional)
|
|
95
|
+
* @returns The decrypted data buffer
|
|
96
|
+
*/
|
|
97
|
+
decryptKey(privateKey, encryptedKey, ephemeralPublicKey, aad) {
|
|
98
|
+
if (encryptedKey.length !== this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE) {
|
|
99
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptedKeyLength, undefined, undefined, {
|
|
100
|
+
expected: String(this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE),
|
|
101
|
+
actual: String(encryptedKey.length),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
const iv = encryptedKey.subarray(0, this.cryptoCore.consts.IV_SIZE);
|
|
105
|
+
const authTag = encryptedKey.subarray(this.cryptoCore.consts.IV_SIZE, this.cryptoCore.consts.IV_SIZE + this.cryptoCore.consts.AUTH_TAG_SIZE);
|
|
106
|
+
const encrypted = encryptedKey.subarray(this.cryptoCore.consts.IV_SIZE + this.cryptoCore.consts.AUTH_TAG_SIZE);
|
|
107
|
+
// Normalize the public key (ensuring 0x04 prefix)
|
|
108
|
+
const normalizedKey = this.cryptoCore.normalizePublicKey(ephemeralPublicKey);
|
|
109
|
+
// Compute shared secret
|
|
110
|
+
const ecdh = (0, crypto_1.createECDH)(this.cryptoCore.config.curveName);
|
|
111
|
+
ecdh.setPrivateKey(privateKey);
|
|
112
|
+
const sharedSecret = ecdh.computeSecret(normalizedKey);
|
|
113
|
+
// Use HKDF to derive the key
|
|
114
|
+
const symKey = this.cryptoCore.deriveSharedKey(sharedSecret, Buffer.alloc(0), // No salt
|
|
115
|
+
Buffer.from('ecies-v2-key-derivation'), // Info
|
|
116
|
+
this.cryptoCore.consts.SYMMETRIC.KEY_SIZE);
|
|
117
|
+
// Decrypt
|
|
118
|
+
const decipher = (0, crypto_1.createDecipheriv)(this.cryptoCore.consts.SYMMETRIC_ALGORITHM_CONFIGURATION, symKey, iv);
|
|
119
|
+
decipher.setAuthTag(authTag);
|
|
120
|
+
if (aad) {
|
|
121
|
+
decipher.setAAD(aad);
|
|
122
|
+
}
|
|
123
|
+
const decrypted = decipher.update(encrypted);
|
|
124
|
+
const final = decipher.final();
|
|
125
|
+
const decryptedMessage = Buffer.concat([decrypted, final]);
|
|
126
|
+
if (decryptedMessage.length !== this.cryptoCore.consts.SYMMETRIC.KEY_SIZE) {
|
|
127
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength, undefined, undefined, {
|
|
128
|
+
expected: String(this.cryptoCore.consts.SYMMETRIC.KEY_SIZE),
|
|
129
|
+
actual: String(decryptedMessage.length),
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return decryptedMessage;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Encrypts a message for multiple recipients.
|
|
136
|
+
* @param recipients The recipients to encrypt the message for.
|
|
137
|
+
* @param message The message to encrypt.
|
|
138
|
+
* @param preamble Optional preamble to include in the encrypted message.
|
|
139
|
+
* @param senderPrivateKey Optional sender private key for signing.
|
|
140
|
+
* @returns The encrypted message.
|
|
141
|
+
* @throws EciesError if the number of recipients is greater than 65535.
|
|
142
|
+
*/
|
|
143
|
+
encryptMultiple(recipients, message, preamble, senderPrivateKey) {
|
|
144
|
+
if (recipients.length > ecies_lib_1.Constants.UINT16_MAX) {
|
|
145
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.TooManyRecipients);
|
|
146
|
+
}
|
|
147
|
+
// Sign-then-Encrypt: If sender key provided, sign the message and prepend signature
|
|
148
|
+
let messageToEncrypt = message;
|
|
149
|
+
if (senderPrivateKey) {
|
|
150
|
+
const signature = this.cryptoCore.sign(senderPrivateKey, message);
|
|
151
|
+
messageToEncrypt = Buffer.concat([signature, message]);
|
|
152
|
+
}
|
|
153
|
+
if (messageToEncrypt.length > this.cryptoCore.consts.MAX_RAW_DATA_SIZE) {
|
|
154
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.FileSizeTooLarge);
|
|
155
|
+
}
|
|
156
|
+
const messageTypeBuffer = Buffer.alloc(1);
|
|
157
|
+
messageTypeBuffer.writeUint8(ecies_lib_1.EciesEncryptionTypeEnum.Multiple);
|
|
158
|
+
// Generate a random symmetric key
|
|
159
|
+
const symmetricKey = (0, crypto_1.randomBytes)(this.cryptoCore.consts.SYMMETRIC.KEY_SIZE);
|
|
160
|
+
// Generate ONE ephemeral key pair for all recipients
|
|
161
|
+
const ecdh = (0, crypto_1.createECDH)(this.cryptoCore.config.curveName);
|
|
162
|
+
ecdh.generateKeys();
|
|
163
|
+
const ephemeralPrivateKey = ecdh.getPrivateKey();
|
|
164
|
+
let ephemeralPublicKey = ecdh.getPublicKey(null, 'compressed');
|
|
165
|
+
// Ensure public key has 0x04 prefix
|
|
166
|
+
if (ephemeralPublicKey.length === this.cryptoCore.consts.RAW_PUBLIC_KEY_LENGTH) {
|
|
167
|
+
ephemeralPublicKey = Buffer.concat([
|
|
168
|
+
Buffer.from([this.cryptoCore.consts.PUBLIC_KEY_MAGIC]),
|
|
169
|
+
ephemeralPublicKey,
|
|
170
|
+
]);
|
|
171
|
+
}
|
|
172
|
+
const encryptionResults = recipients.map((member) => ({
|
|
173
|
+
id: member.id,
|
|
174
|
+
encryptedKey: this.encryptKey(member.publicKey, symmetricKey, ephemeralPrivateKey, member.id // Use Recipient ID as AAD
|
|
175
|
+
),
|
|
176
|
+
}));
|
|
177
|
+
const recipientIds = encryptionResults.map(({ id }) => id);
|
|
178
|
+
const recipientKeys = encryptionResults.map(({ encryptedKey }) => encryptedKey);
|
|
179
|
+
// Calculate header size
|
|
180
|
+
const headerSize = this.calculateECIESMultipleRecipientOverhead(recipients.length, false, recipientKeys);
|
|
181
|
+
// Build the header to use as AAD for message encryption
|
|
182
|
+
// We need to construct a temporary object to build the header
|
|
183
|
+
const tempHeaderData = {
|
|
184
|
+
dataLength: messageToEncrypt.length,
|
|
185
|
+
recipientCount: recipients.length,
|
|
186
|
+
recipientIds,
|
|
187
|
+
recipientKeys,
|
|
188
|
+
encryptedMessage: Buffer.alloc(0), // Placeholder
|
|
189
|
+
headerSize,
|
|
190
|
+
ephemeralPublicKey,
|
|
191
|
+
};
|
|
192
|
+
const headerBytes = this.buildECIESMultipleRecipientHeader(tempHeaderData);
|
|
193
|
+
// Encrypt the message with the symmetric key and Header as AAD
|
|
194
|
+
const iv = (0, crypto_1.randomBytes)(this.cryptoCore.consts.IV_SIZE);
|
|
195
|
+
const cipher = (0, crypto_1.createCipheriv)(this.cryptoCore.consts.SYMMETRIC_ALGORITHM_CONFIGURATION, symmetricKey, iv);
|
|
196
|
+
cipher.setAAD(headerBytes);
|
|
197
|
+
const encrypted = cipher.update(messageToEncrypt);
|
|
198
|
+
const final = cipher.final();
|
|
199
|
+
const authTag = cipher.getAuthTag();
|
|
200
|
+
const encryptedMessage = Buffer.concat([encrypted, final]);
|
|
201
|
+
const storedMessage = Buffer.concat([
|
|
202
|
+
preamble ?? Buffer.alloc(0),
|
|
203
|
+
iv,
|
|
204
|
+
authTag,
|
|
205
|
+
encryptedMessage,
|
|
206
|
+
]);
|
|
207
|
+
// Verify the encrypted message size (just the encrypted content)
|
|
208
|
+
if (encryptedMessage.length !== messageToEncrypt.length) {
|
|
209
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.MessageLengthMismatch);
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
dataLength: messageToEncrypt.length,
|
|
213
|
+
recipientCount: recipients.length,
|
|
214
|
+
recipientIds,
|
|
215
|
+
recipientKeys,
|
|
216
|
+
encryptedMessage: storedMessage,
|
|
217
|
+
headerSize,
|
|
218
|
+
ephemeralPublicKey,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Decrypts a message encrypted with multiple ECIE for a recipient.
|
|
223
|
+
* @param encryptedData The encrypted data.
|
|
224
|
+
* @param recipient The recipient.
|
|
225
|
+
* @param senderPublicKey Optional sender public key for verification.
|
|
226
|
+
* @returns The decrypted message.
|
|
227
|
+
*/
|
|
228
|
+
decryptMultipleECIEForRecipient(encryptedData, recipient, senderPublicKey) {
|
|
229
|
+
if (recipient.privateKey === undefined) {
|
|
230
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.PrivateKeyNotLoaded);
|
|
231
|
+
}
|
|
232
|
+
// Find this recipient's encrypted key
|
|
233
|
+
const recipientIndex = encryptedData.recipientIds.findIndex((id) => id.equals(recipient.id));
|
|
234
|
+
if (recipientIndex === -1) {
|
|
235
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.RecipientNotFound);
|
|
236
|
+
}
|
|
237
|
+
const encryptedKey = encryptedData.recipientKeys[recipientIndex];
|
|
238
|
+
if (!encryptedData.ephemeralPublicKey) {
|
|
239
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEphemeralPublicKey);
|
|
240
|
+
}
|
|
241
|
+
// Decrypt the symmetric key using the detected encryption type
|
|
242
|
+
const symmetricKey = this.decryptKey(Buffer.from(recipient.privateKey.value), encryptedKey, encryptedData.ephemeralPublicKey, recipient.id // Use Recipient ID as AAD
|
|
243
|
+
);
|
|
244
|
+
// Rebuild header to use as AAD
|
|
245
|
+
const headerBytes = this.buildECIESMultipleRecipientHeader(encryptedData);
|
|
246
|
+
// Extract the IV and auth tag from the encrypted message
|
|
247
|
+
const iv = encryptedData.encryptedMessage.subarray(0, this.cryptoCore.consts.IV_SIZE);
|
|
248
|
+
const authTag = encryptedData.encryptedMessage.subarray(this.cryptoCore.consts.IV_SIZE, this.cryptoCore.consts.IV_SIZE + this.cryptoCore.consts.AUTH_TAG_SIZE);
|
|
249
|
+
// Extract the encrypted content (no CRC, AES-GCM provides authentication)
|
|
250
|
+
const encrypted = encryptedData.encryptedMessage.subarray(this.cryptoCore.consts.IV_SIZE + this.cryptoCore.consts.AUTH_TAG_SIZE);
|
|
251
|
+
// Decrypt the content with the symmetric key
|
|
252
|
+
const decipher = (0, crypto_1.createDecipheriv)(this.cryptoCore.consts.SYMMETRIC_ALGORITHM_CONFIGURATION, symmetricKey, iv);
|
|
253
|
+
decipher.setAuthTag(authTag);
|
|
254
|
+
decipher.setAAD(headerBytes);
|
|
255
|
+
const decrypted = decipher.update(encrypted);
|
|
256
|
+
const final = decipher.final();
|
|
257
|
+
const decryptedMessage = Buffer.concat([decrypted, final]);
|
|
258
|
+
// The decrypted message should match the original data length
|
|
259
|
+
if (decryptedMessage.length !== encryptedData.dataLength) {
|
|
260
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength);
|
|
261
|
+
}
|
|
262
|
+
// If sender public key is provided, verify signature
|
|
263
|
+
if (senderPublicKey) {
|
|
264
|
+
// Expect [Signature (64)][Message]
|
|
265
|
+
if (decryptedMessage.length < 64) {
|
|
266
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidSignature);
|
|
267
|
+
}
|
|
268
|
+
const signature = decryptedMessage.subarray(0, 64);
|
|
269
|
+
const message = decryptedMessage.subarray(64);
|
|
270
|
+
const isValid = this.cryptoCore.verify(senderPublicKey, message, signature);
|
|
271
|
+
if (!isValid) {
|
|
272
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidSignature);
|
|
273
|
+
}
|
|
274
|
+
return message;
|
|
275
|
+
}
|
|
276
|
+
return decryptedMessage;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Calculate the overhead for a message encrypted for multiple recipients
|
|
280
|
+
* @param recipientCount number of recipients
|
|
281
|
+
* @param includeMessageOverhead whether to include the overhead for the encrypted message
|
|
282
|
+
* @param encryptedKeys optional array of encrypted keys to calculate actual size
|
|
283
|
+
* @returns the overhead size in bytes
|
|
284
|
+
*/
|
|
285
|
+
calculateECIESMultipleRecipientOverhead(recipientCount, includeMessageOverhead, encryptedKeys) {
|
|
286
|
+
if (recipientCount < 1) {
|
|
287
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidRecipientCount);
|
|
288
|
+
}
|
|
289
|
+
// Calculate encrypted keys size
|
|
290
|
+
let encryptedKeysSize;
|
|
291
|
+
if (encryptedKeys) {
|
|
292
|
+
encryptedKeysSize = encryptedKeys.reduce((total, key) => total + key.length, 0);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
// Default assumption: all keys use Simple encryption type (more efficient)
|
|
296
|
+
encryptedKeysSize =
|
|
297
|
+
recipientCount * this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE;
|
|
298
|
+
}
|
|
299
|
+
const baseOverhead = this.cryptoCore.consts.VERSION_SIZE +
|
|
300
|
+
this.cryptoCore.consts.CIPHER_SUITE_SIZE +
|
|
301
|
+
this.cryptoCore.consts.ENCRYPTION_TYPE_SIZE +
|
|
302
|
+
this.cryptoCore.consts.MULTIPLE.DATA_LENGTH_SIZE +
|
|
303
|
+
this.cryptoCore.consts.MULTIPLE.RECIPIENT_COUNT_SIZE +
|
|
304
|
+
recipientCount * this.cryptoCore.consts.MULTIPLE.RECIPIENT_ID_SIZE + // recipient ids (dynamic based on ID provider)
|
|
305
|
+
encryptedKeysSize; // actual encrypted keys size
|
|
306
|
+
return includeMessageOverhead
|
|
307
|
+
? baseOverhead + this.cryptoCore.consts.MULTIPLE.FIXED_OVERHEAD_SIZE
|
|
308
|
+
: baseOverhead;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Builds the header for a message encrypted for multiple recipients
|
|
312
|
+
* @param data The encrypted message data including recipients and encrypted keys
|
|
313
|
+
* @returns The header buffer for the message
|
|
314
|
+
* @throws EciesError if the number of recipients is greater than the maximum allowed
|
|
315
|
+
* @throws EciesError if the number of encrypted keys does not match the number of recipients
|
|
316
|
+
*/
|
|
317
|
+
buildECIESMultipleRecipientHeader(data) {
|
|
318
|
+
if (data.recipientIds.length > this.cryptoCore.consts.MULTIPLE.MAX_RECIPIENTS) {
|
|
319
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.TooManyRecipients);
|
|
320
|
+
}
|
|
321
|
+
else if (data.recipientIds.length !== data.recipientKeys.length) {
|
|
322
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.RecipientKeyCountMismatch);
|
|
323
|
+
}
|
|
324
|
+
else if (data.dataLength < 0 ||
|
|
325
|
+
data.dataLength > this.cryptoCore.consts.MAX_RAW_DATA_SIZE) {
|
|
326
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.FileSizeTooLarge);
|
|
327
|
+
}
|
|
328
|
+
if (!data.ephemeralPublicKey) {
|
|
329
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEphemeralPublicKey);
|
|
330
|
+
}
|
|
331
|
+
// Create version buffer
|
|
332
|
+
const versionBuffer = Buffer.alloc(this.cryptoCore.consts.VERSION_SIZE);
|
|
333
|
+
versionBuffer.writeUInt8(ecies_lib_1.EciesVersionEnum.V1);
|
|
334
|
+
// Create cipher suite buffer
|
|
335
|
+
const cipherSuiteBuffer = Buffer.alloc(this.cryptoCore.consts.CIPHER_SUITE_SIZE);
|
|
336
|
+
cipherSuiteBuffer.writeUInt8(ecies_lib_1.EciesCipherSuiteEnum.Secp256k1_Aes256Gcm_Sha256);
|
|
337
|
+
// Create encryption type buffer
|
|
338
|
+
const encryptionTypeBuffer = Buffer.alloc(this.cryptoCore.consts.ENCRYPTION_TYPE_SIZE);
|
|
339
|
+
encryptionTypeBuffer.writeUInt8(ecies_lib_1.EciesEncryptionTypeEnum.Multiple);
|
|
340
|
+
// Create data length buffer
|
|
341
|
+
// We use the most significant byte (MSB) to store the recipient ID size
|
|
342
|
+
const recipientIdSize = this.cryptoCore.consts.MULTIPLE.RECIPIENT_ID_SIZE;
|
|
343
|
+
if (recipientIdSize > 255) {
|
|
344
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidRecipientCount);
|
|
345
|
+
}
|
|
346
|
+
const dataLengthBigInt = BigInt(data.dataLength);
|
|
347
|
+
const recipientIdSizeBigInt = BigInt(recipientIdSize);
|
|
348
|
+
const combinedLength = (recipientIdSizeBigInt << 56n) | dataLengthBigInt;
|
|
349
|
+
const dataLengthBuffer = Buffer.alloc(this.cryptoCore.consts.MULTIPLE.DATA_LENGTH_SIZE);
|
|
350
|
+
dataLengthBuffer.writeBigUInt64BE(combinedLength);
|
|
351
|
+
// Create recipient count buffer
|
|
352
|
+
const recipientCountBuffer = Buffer.alloc(this.cryptoCore.consts.MULTIPLE.RECIPIENT_COUNT_SIZE);
|
|
353
|
+
recipientCountBuffer.writeUInt16BE(data.recipientIds.length);
|
|
354
|
+
// Create recipients buffer
|
|
355
|
+
const recipientsBuffer = Buffer.alloc(data.recipientIds.length *
|
|
356
|
+
this.cryptoCore.consts.MULTIPLE.RECIPIENT_ID_SIZE);
|
|
357
|
+
data.recipientIds.forEach((recipientId, index) => {
|
|
358
|
+
recipientsBuffer.set(recipientId, index * this.cryptoCore.consts.MULTIPLE.RECIPIENT_ID_SIZE);
|
|
359
|
+
});
|
|
360
|
+
// Validate encrypted key lengths based on their encryption type
|
|
361
|
+
data.recipientKeys.forEach((encryptedKey) => {
|
|
362
|
+
if (encryptedKey.length === 0) {
|
|
363
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptedKeyLength);
|
|
364
|
+
}
|
|
365
|
+
if (encryptedKey.length !==
|
|
366
|
+
this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE) {
|
|
367
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptedKeyLength, undefined, undefined, {
|
|
368
|
+
expected: String(this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE),
|
|
369
|
+
actual: String(encryptedKey.length),
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
// Create encrypted keys buffer with variable-length keys
|
|
374
|
+
const encryptedKeysBuffer = Buffer.concat(data.recipientKeys);
|
|
375
|
+
// Combine all buffers to form the header
|
|
376
|
+
return Buffer.concat([
|
|
377
|
+
versionBuffer,
|
|
378
|
+
cipherSuiteBuffer,
|
|
379
|
+
encryptionTypeBuffer,
|
|
380
|
+
data.ephemeralPublicKey,
|
|
381
|
+
dataLengthBuffer,
|
|
382
|
+
recipientCountBuffer,
|
|
383
|
+
recipientsBuffer,
|
|
384
|
+
encryptedKeysBuffer,
|
|
385
|
+
]);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Parses a multi-encrypted header.
|
|
389
|
+
* @param data - The data to parse.
|
|
390
|
+
* @returns The parsed header.
|
|
391
|
+
*/
|
|
392
|
+
parseMultiEncryptedHeader(data) {
|
|
393
|
+
// Ensure there's enough data to read headers
|
|
394
|
+
// minimum: 1 (ver) + 1 (suite) + 1 (type) + 33 (pubkey) + 8 (len) + 2 (count) = 46
|
|
395
|
+
if (data.length < 46) {
|
|
396
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength);
|
|
397
|
+
}
|
|
398
|
+
let offset = 0;
|
|
399
|
+
// Read Version
|
|
400
|
+
const version = data.readUInt8(offset);
|
|
401
|
+
offset += this.cryptoCore.consts.VERSION_SIZE;
|
|
402
|
+
if (version !== ecies_lib_1.EciesVersionEnum.V1) {
|
|
403
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidVersion, undefined, undefined, { version: String(version) });
|
|
404
|
+
}
|
|
405
|
+
// Read CipherSuite
|
|
406
|
+
const cipherSuite = data.readUInt8(offset);
|
|
407
|
+
offset += this.cryptoCore.consts.CIPHER_SUITE_SIZE;
|
|
408
|
+
if (cipherSuite !== ecies_lib_1.EciesCipherSuiteEnum.Secp256k1_Aes256Gcm_Sha256) {
|
|
409
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidCipherSuite, undefined, undefined, { cipherSuite: String(cipherSuite) });
|
|
410
|
+
}
|
|
411
|
+
// Read Encryption Type
|
|
412
|
+
const encryptionType = data.readUInt8(offset);
|
|
413
|
+
offset += this.cryptoCore.consts.ENCRYPTION_TYPE_SIZE;
|
|
414
|
+
if (encryptionType !== ecies_lib_1.EciesEncryptionTypeEnum.Multiple) {
|
|
415
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidEncryptionType, undefined, undefined, { encryptionType: encryptionType.toString(16) });
|
|
416
|
+
}
|
|
417
|
+
// Read Ephemeral Public Key
|
|
418
|
+
const ephemeralPublicKey = data.subarray(offset, offset + this.cryptoCore.consts.PUBLIC_KEY_LENGTH);
|
|
419
|
+
offset += this.cryptoCore.consts.PUBLIC_KEY_LENGTH;
|
|
420
|
+
// Read data length and recipient ID size
|
|
421
|
+
const combinedLength = data.readBigUInt64BE(offset);
|
|
422
|
+
offset += this.cryptoCore.consts.MULTIPLE.DATA_LENGTH_SIZE; // 8 bytes
|
|
423
|
+
// Extract recipient ID size from MSB (top 8 bits)
|
|
424
|
+
const storedRecipientIdSize = Number(combinedLength >> 56n);
|
|
425
|
+
// Extract data length from lower 56 bits
|
|
426
|
+
const dataLength = Number(combinedLength & 0x00ffffffffffffffn);
|
|
427
|
+
if (dataLength <= 0 ||
|
|
428
|
+
dataLength > this.cryptoCore.consts.MAX_RAW_DATA_SIZE) {
|
|
429
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength);
|
|
430
|
+
}
|
|
431
|
+
// Use stored recipient ID size if available (non-legacy), otherwise fallback to config
|
|
432
|
+
const recipientIdSize = storedRecipientIdSize > 0
|
|
433
|
+
? storedRecipientIdSize
|
|
434
|
+
: this.cryptoCore.consts.MULTIPLE.RECIPIENT_ID_SIZE;
|
|
435
|
+
// Read recipient count
|
|
436
|
+
const recipientCount = data.readUInt16BE(offset);
|
|
437
|
+
if (recipientCount <= 0 ||
|
|
438
|
+
recipientCount > this.cryptoCore.consts.MULTIPLE.MAX_RECIPIENTS) {
|
|
439
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidRecipientCount);
|
|
440
|
+
}
|
|
441
|
+
offset += this.cryptoCore.consts.MULTIPLE.RECIPIENT_COUNT_SIZE; // 2 bytes
|
|
442
|
+
// Ensure there's enough data for all recipients
|
|
443
|
+
// Note: We can't use calculateECIESMultipleRecipientOverhead here easily because it assumes fixed ID size
|
|
444
|
+
// But we can calculate manually
|
|
445
|
+
const remainingHeaderSize = recipientCount * recipientIdSize +
|
|
446
|
+
recipientCount * this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE;
|
|
447
|
+
if (data.length < offset + remainingHeaderSize) {
|
|
448
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength);
|
|
449
|
+
}
|
|
450
|
+
// Read recipient IDs
|
|
451
|
+
const recipientIds = [];
|
|
452
|
+
for (let i = 0; i < recipientCount; i++) {
|
|
453
|
+
recipientIds.push(data.subarray(offset, offset + recipientIdSize));
|
|
454
|
+
offset += recipientIdSize;
|
|
455
|
+
}
|
|
456
|
+
// Read encrypted keys with variable lengths based on encryption type
|
|
457
|
+
const recipientKeys = [];
|
|
458
|
+
for (let i = 0; i < recipientCount; i++) {
|
|
459
|
+
if (offset >= data.length) {
|
|
460
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength);
|
|
461
|
+
}
|
|
462
|
+
if (offset + this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE >
|
|
463
|
+
data.length) {
|
|
464
|
+
throw new ecies_lib_1.ECIESError(ecies_lib_1.ECIESErrorTypeEnum.InvalidDataLength, undefined, undefined, {
|
|
465
|
+
required: String(this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE),
|
|
466
|
+
available: String(data.length - offset),
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
recipientKeys.push(data.subarray(offset, offset + this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE));
|
|
470
|
+
offset += this.cryptoCore.consts.MULTIPLE.ENCRYPTED_KEY_SIZE;
|
|
471
|
+
}
|
|
472
|
+
return {
|
|
473
|
+
dataLength,
|
|
474
|
+
recipientCount,
|
|
475
|
+
recipientIds,
|
|
476
|
+
recipientKeys,
|
|
477
|
+
headerSize: offset,
|
|
478
|
+
ephemeralPublicKey,
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Parses a multi-encrypted buffer into its components.
|
|
483
|
+
* @param data - The multi-encrypted buffer to parse.
|
|
484
|
+
* @returns The parsed multi-encrypted buffer.
|
|
485
|
+
*/
|
|
486
|
+
parseMultiEncryptedBuffer(data) {
|
|
487
|
+
const header = this.parseMultiEncryptedHeader(data);
|
|
488
|
+
const encryptedMessage = data.subarray(header.headerSize);
|
|
489
|
+
return {
|
|
490
|
+
...header,
|
|
491
|
+
encryptedMessage,
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
exports.EciesMultiRecipient = EciesMultiRecipient;
|
|
496
|
+
//# sourceMappingURL=multi-recipient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-recipient.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/services/ecies/multi-recipient.ts"],"names":[],"mappings":";;;AAAA,0DAOoC;AACpC,mCAKgB;AAOhB,yDAA8D;AAE9D;;GAEG;AACH,MAAa,mBAAmB;IACX,UAAU,CAAkB;IAC5B,mBAAmB,CAA2B;IAEjE,YAAY,UAA2B;QACrC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,mBAAmB,GAAG,IAAI,2CAAwB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC7E,CAAC;IAED;;;;OAIG;IACI,aAAa,CAAC,cAAsB;QACzC,OAAO,CACL,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY;YACnC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,iBAAiB;YACxC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,oBAAoB;YAC3C,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,iBAAiB,GAAG,8BAA8B;YACzE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB;YAChD,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB;YACpD,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB;YAClE,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CACpE,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACI,UAAU,CACf,iBAAyB,EACzB,mBAA2B,EAC3B,mBAA2B,EAC3B,GAAY;QA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pD,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAE1D,OAAO;YACL,GAAG,MAAM;YACT,gBAAgB;SACjB,CAAC;IACJ,CAAC;CACF;AApvBD,kDAovBC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { EciesEncryptionType, EciesEncryptionTypeEnum, HexString, IECIESConfig, IECIESConstants, SecureString } from '@digitaldefiance/ecies-lib';
|
|
2
|
+
import { Wallet } from '@ethereumjs/wallet';
|
|
3
|
+
import type { IMember } from '../../interfaces/member';
|
|
4
|
+
import type { IMultiEncryptedMessage } from '../../interfaces/multi-encrypted-message';
|
|
5
|
+
import type { IMultiEncryptedParsedHeader } from '../../interfaces/multi-encrypted-parsed-header';
|
|
6
|
+
import type { ISingleEncryptedParsedHeader } from '../../interfaces/single-encrypted-parsed-header';
|
|
7
|
+
import type { IWalletSeed } from '../../interfaces/wallet-seed';
|
|
8
|
+
import { SignatureBuffer, SignatureString } from '../../types';
|
|
9
|
+
import { EciesCryptoCore } from './crypto-core';
|
|
10
|
+
import { EciesMultiRecipient } from './multi-recipient';
|
|
11
|
+
import { EciesSignature } from './signature';
|
|
12
|
+
import { EciesSingleRecipientCore } from './single-recipient';
|
|
13
|
+
import { EciesUtilities } from './utilities';
|
|
14
|
+
/**
|
|
15
|
+
* Unified ECIES service that integrates all the modular components
|
|
16
|
+
*/
|
|
17
|
+
export declare class ECIESService {
|
|
18
|
+
protected readonly _config: IECIESConfig;
|
|
19
|
+
protected readonly cryptoCore: EciesCryptoCore;
|
|
20
|
+
protected readonly signature: EciesSignature;
|
|
21
|
+
protected readonly singleRecipient: EciesSingleRecipientCore;
|
|
22
|
+
protected readonly multiRecipient: EciesMultiRecipient;
|
|
23
|
+
protected readonly utilities: EciesUtilities;
|
|
24
|
+
constructor(config?: Partial<IECIESConfig>, eciesParams?: IECIESConstants);
|
|
25
|
+
get core(): EciesCryptoCore;
|
|
26
|
+
get config(): IECIESConfig;
|
|
27
|
+
/**
|
|
28
|
+
* The name of the elliptic curve used for ECIES encryption/decryption
|
|
29
|
+
*/
|
|
30
|
+
get curveName(): string;
|
|
31
|
+
generateNewMnemonic(): SecureString;
|
|
32
|
+
walletFromSeed(seed: Buffer): Wallet;
|
|
33
|
+
walletAndSeedFromMnemonic(mnemonic: SecureString): IWalletSeed;
|
|
34
|
+
walletToSimpleKeyPairBuffer(wallet: Wallet): import("../..").ISimpleKeyPairBuffer;
|
|
35
|
+
seedToSimpleKeyPairBuffer(seed: Buffer): import("../..").ISimpleKeyPairBuffer;
|
|
36
|
+
mnemonicToSimpleKeyPairBuffer(mnemonic: SecureString): import("../..").ISimpleKeyPairBuffer;
|
|
37
|
+
mnemonicToSimpleKeyPair(mnemonic: SecureString): import("../..").ISimpleKeyPairBuffer;
|
|
38
|
+
encryptSimpleOrSingle(encryptSimple: boolean, receiverPublicKey: Buffer, message: Buffer, preamble?: Buffer): Buffer;
|
|
39
|
+
parseSingleEncryptedHeader(encryptionType: EciesEncryptionTypeEnum, data: Buffer, preambleSize?: number, options?: {
|
|
40
|
+
dataLength?: number;
|
|
41
|
+
}): ISingleEncryptedParsedHeader;
|
|
42
|
+
decryptSimpleOrSingleWithHeader(decryptSimple: boolean, privateKey: Buffer, encryptedData: Buffer, preambleSize?: number, options?: {
|
|
43
|
+
dataLength?: number;
|
|
44
|
+
}): Buffer;
|
|
45
|
+
decryptSimpleOrSingleWithHeaderEx(encryptionType: EciesEncryptionTypeEnum, privateKey: Buffer, encryptedData: Buffer, preambleSize?: number, options?: {
|
|
46
|
+
dataLength?: number;
|
|
47
|
+
}): {
|
|
48
|
+
decrypted: Buffer;
|
|
49
|
+
consumedBytes: number;
|
|
50
|
+
};
|
|
51
|
+
decryptSingleWithComponents(privateKey: Buffer, ephemeralPublicKey: Buffer, iv: Buffer, authTag: Buffer, encrypted: Buffer, aad?: Buffer): {
|
|
52
|
+
decrypted: Buffer;
|
|
53
|
+
ciphertextLength?: number;
|
|
54
|
+
};
|
|
55
|
+
signMessage(privateKey: Buffer, data: Buffer): SignatureBuffer;
|
|
56
|
+
verifyMessage(publicKey: Buffer, data: Buffer, signature: SignatureBuffer): boolean;
|
|
57
|
+
signatureStringToSignatureBuffer(signatureString: HexString): SignatureBuffer;
|
|
58
|
+
signatureBufferToSignatureString(signatureBuffer: SignatureBuffer): SignatureString;
|
|
59
|
+
encryptMultiple(recipients: Array<IMember>, message: Buffer, preamble?: Buffer): Promise<IMultiEncryptedMessage>;
|
|
60
|
+
decryptMultipleECIEForRecipient(encryptedData: IMultiEncryptedMessage, recipient: IMember): Buffer;
|
|
61
|
+
calculateECIESMultipleRecipientOverhead(recipientCount: number, includeMessageOverhead: boolean): number;
|
|
62
|
+
buildECIESMultipleRecipientHeader(data: IMultiEncryptedMessage): Buffer;
|
|
63
|
+
parseMultiEncryptedHeader(data: Buffer): IMultiEncryptedParsedHeader;
|
|
64
|
+
parseMultiEncryptedBuffer(data: Buffer): IMultiEncryptedMessage;
|
|
65
|
+
computeEncryptedLengthFromDataLength(dataLength: number, encryptionMode: EciesEncryptionType, recipientCount?: number): number;
|
|
66
|
+
computeDecryptedLengthFromEncryptedDataLength(encryptedDataLength: number, padding?: number): number;
|
|
67
|
+
encrypt(encryptionType: EciesEncryptionType, recipient: IMember, message: Buffer, preamble?: Buffer): Buffer;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/services/ecies/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EACnB,uBAAuB,EAGvB,SAAS,EACT,YAAY,EACZ,eAAe,EACf,YAAY,EACb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAI5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB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