@digitaldefiance/node-ecies-lib 4.4.9 → 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
package/src/services/pbkdf2.ts
DELETED
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import { PluginI18nEngine, CoreLanguageCode } from '@digitaldefiance/i18n-lib';
|
|
2
|
-
import {
|
|
3
|
-
IPbkdf2Config,
|
|
4
|
-
IPBkdf2Consts,
|
|
5
|
-
Pbkdf2ErrorType,
|
|
6
|
-
} from '@digitaldefiance/ecies-lib';
|
|
7
|
-
import { pbkdf2 as pbkdf2Async, pbkdf2Sync, randomBytes } from 'crypto';
|
|
8
|
-
import { promisify } from 'util';
|
|
9
|
-
import { IConstants } from '../interfaces/constants';
|
|
10
|
-
import { Pbkdf2ProfileEnum } from '../enumerations/pbkdf2-profile';
|
|
11
|
-
import {
|
|
12
|
-
getNodeEciesTranslation,
|
|
13
|
-
NodeEciesStringKey,
|
|
14
|
-
} from '../i18n/ecies-i18n-factory';
|
|
15
|
-
import { IPbkdf2Result } from '../interfaces/pbkdf2-result';
|
|
16
|
-
import { IECIESConsts } from '../interfaces/ecies-consts';
|
|
17
|
-
import { Constants } from '../constants';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Custom PBKDF2 error class that works with the plugin i18n system
|
|
21
|
-
*/
|
|
22
|
-
export class NodePbkdf2Error extends Error {
|
|
23
|
-
constructor(
|
|
24
|
-
message: string,
|
|
25
|
-
public readonly type: Pbkdf2ErrorType,
|
|
26
|
-
) {
|
|
27
|
-
super(message);
|
|
28
|
-
this.name = 'NodePbkdf2Error';
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Service for handling PBKDF2 (Password-Based Key Derivation Function 2) operations.
|
|
34
|
-
* This service provides functionality for:
|
|
35
|
-
* - Generating secure key derivation configurations
|
|
36
|
-
* - Deriving cryptographic keys from passwords
|
|
37
|
-
* - Managing salt and iteration parameters
|
|
38
|
-
* - Both synchronous and asynchronous key derivation
|
|
39
|
-
*/
|
|
40
|
-
export class Pbkdf2Service<
|
|
41
|
-
TLanguage extends CoreLanguageCode = CoreLanguageCode,
|
|
42
|
-
> {
|
|
43
|
-
protected readonly profiles: Record<string, IPbkdf2Config>;
|
|
44
|
-
protected readonly eciesConsts: IECIESConsts;
|
|
45
|
-
protected readonly pbkdf2Consts: IPBkdf2Consts;
|
|
46
|
-
|
|
47
|
-
constructor(
|
|
48
|
-
profiles: Record<string, IPbkdf2Config> = Constants.PBKDF2_PROFILES,
|
|
49
|
-
eciesParams: IECIESConsts = Constants.ECIES,
|
|
50
|
-
pbkdf2Params: IPBkdf2Consts = Constants.PBKDF2,
|
|
51
|
-
) {
|
|
52
|
-
this.profiles = profiles;
|
|
53
|
-
this.eciesConsts = eciesParams;
|
|
54
|
-
this.pbkdf2Consts = pbkdf2Params;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Register a new PBKDF2 profile
|
|
59
|
-
* @param profileName The name of the profile
|
|
60
|
-
* @param config The configuration for the profile
|
|
61
|
-
*/
|
|
62
|
-
public registerProfile(profileName: string, config: IPbkdf2Config): void {
|
|
63
|
-
this.profiles[profileName] = { ...config };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Get all registered profile names
|
|
68
|
-
* @returns Array of profile names
|
|
69
|
-
*/
|
|
70
|
-
public getRegisteredProfiles(): string[] {
|
|
71
|
-
return Object.keys(this.profiles);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Check if a profile is registered
|
|
76
|
-
* @param profileName The name of the profile to check
|
|
77
|
-
* @returns True if the profile exists
|
|
78
|
-
*/
|
|
79
|
-
public hasProfile(profileName: string): boolean {
|
|
80
|
-
return profileName in this.profiles;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Create a Pbkdf2Service instance from IConstants (for backward compatibility)
|
|
85
|
-
* @param constants The constants object
|
|
86
|
-
* @returns A new Pbkdf2Service instance
|
|
87
|
-
*/
|
|
88
|
-
public static fromConstants(constants: IConstants): Pbkdf2Service {
|
|
89
|
-
return new Pbkdf2Service(
|
|
90
|
-
constants.PBKDF2_PROFILES,
|
|
91
|
-
constants.ECIES,
|
|
92
|
-
constants.PBKDF2,
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Get a predefined configuration profile for common use cases
|
|
97
|
-
* @param profile The name of the profile to use
|
|
98
|
-
* @returns Configuration object for the specified profile
|
|
99
|
-
*/
|
|
100
|
-
public getProfileConfig(profile: string): IPbkdf2Config {
|
|
101
|
-
const profileConfig = this.profiles[profile];
|
|
102
|
-
if (!profileConfig) {
|
|
103
|
-
throw new NodePbkdf2Error(
|
|
104
|
-
getNodeEciesTranslation(
|
|
105
|
-
NodeEciesStringKey.Error_Pbkdf2_InvalidSaltLength,
|
|
106
|
-
),
|
|
107
|
-
Pbkdf2ErrorType.InvalidProfile,
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
hashBytes: profileConfig.hashBytes,
|
|
112
|
-
saltBytes: profileConfig.saltBytes,
|
|
113
|
-
iterations: profileConfig.iterations,
|
|
114
|
-
algorithm: profileConfig.algorithm,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Generate an options object for pbkdf2
|
|
120
|
-
* @param iterations Optional number of iterations (defaults to Pbkdf2IterationsPerSecond)
|
|
121
|
-
* @param saltBytes Optional salt size in bytes (defaults to PBKDF2.SALT_BYTES)
|
|
122
|
-
* @param hashBytes Optional hash size in bytes (defaults to ECIES.SYMMETRIC.KEY_SIZE)
|
|
123
|
-
* @param algorithm Optional hash algorithm (defaults to PBKDF2.ALGORITHM)
|
|
124
|
-
* @returns Configuration object for PBKDF2
|
|
125
|
-
*/
|
|
126
|
-
public getConfig(
|
|
127
|
-
iterations?: number,
|
|
128
|
-
saltBytes?: number,
|
|
129
|
-
hashBytes?: number,
|
|
130
|
-
algorithm?: string,
|
|
131
|
-
): IPbkdf2Config {
|
|
132
|
-
// larger numbers mean better security, less
|
|
133
|
-
return {
|
|
134
|
-
// size of the generated hash
|
|
135
|
-
hashBytes: hashBytes ?? this.eciesConsts.SYMMETRIC.KEY_SIZE,
|
|
136
|
-
// larger salt means hashed passwords are more resistant to rainbow table, but
|
|
137
|
-
// you get diminishing returns pretty fast
|
|
138
|
-
saltBytes: saltBytes ?? this.pbkdf2Consts.SALT_BYTES,
|
|
139
|
-
// more iterations means an attacker has to take longer to brute force an
|
|
140
|
-
// individual password, so larger is better. however, larger also means longer
|
|
141
|
-
// to hash the password. tune so that hashing the password takes about a
|
|
142
|
-
// second
|
|
143
|
-
iterations: iterations ?? this.pbkdf2Consts.ITERATIONS_PER_SECOND,
|
|
144
|
-
// hash algorithm
|
|
145
|
-
algorithm: algorithm ?? this.pbkdf2Consts.ALGORITHM,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Given a password, use pbkdf2 to generate an appropriately sized key for AES encryption
|
|
151
|
-
* @param password The password to derive a key from
|
|
152
|
-
* @param salt Optional salt (will be randomly generated if not provided)
|
|
153
|
-
* @param iterations Optional number of iterations
|
|
154
|
-
* @param saltBytes Optional salt size in bytes
|
|
155
|
-
* @param keySize Optional key size in bytes
|
|
156
|
-
* @param algorithm Optional hash algorithm
|
|
157
|
-
* @returns Object containing the derived key, salt, and iteration count
|
|
158
|
-
*/
|
|
159
|
-
public deriveKeyFromPassword(
|
|
160
|
-
password: Buffer,
|
|
161
|
-
salt?: Buffer,
|
|
162
|
-
iterations?: number,
|
|
163
|
-
saltBytes?: number,
|
|
164
|
-
keySize?: number,
|
|
165
|
-
algorithm?: string,
|
|
166
|
-
): IPbkdf2Result {
|
|
167
|
-
const config = this.getConfig(iterations, saltBytes, keySize, algorithm);
|
|
168
|
-
const saltBytes_ = salt ?? randomBytes(config.saltBytes);
|
|
169
|
-
|
|
170
|
-
if (saltBytes_.length !== config.saltBytes) {
|
|
171
|
-
throw new NodePbkdf2Error(
|
|
172
|
-
getNodeEciesTranslation(
|
|
173
|
-
NodeEciesStringKey.Error_Pbkdf2_InvalidSaltLength,
|
|
174
|
-
),
|
|
175
|
-
Pbkdf2ErrorType.InvalidSaltLength,
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const hashBytes = pbkdf2Sync(
|
|
180
|
-
password,
|
|
181
|
-
saltBytes_,
|
|
182
|
-
config.iterations,
|
|
183
|
-
config.hashBytes,
|
|
184
|
-
config.algorithm,
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
if (hashBytes.length !== config.hashBytes) {
|
|
188
|
-
throw new NodePbkdf2Error(
|
|
189
|
-
getNodeEciesTranslation(
|
|
190
|
-
NodeEciesStringKey.Error_Pbkdf2_InvalidHashLength,
|
|
191
|
-
),
|
|
192
|
-
Pbkdf2ErrorType.InvalidHashLength,
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return {
|
|
197
|
-
salt: saltBytes_,
|
|
198
|
-
hash: hashBytes,
|
|
199
|
-
iterations: config.iterations,
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Async version of deriveKeyFromPassword that uses libuv threadpool via crypto.pbkdf2
|
|
205
|
-
* to avoid blocking the event loop during password verification.
|
|
206
|
-
* @param password The password to derive a key from
|
|
207
|
-
* @param salt Optional salt (will be randomly generated if not provided)
|
|
208
|
-
* @param iterations Optional number of iterations
|
|
209
|
-
* @param saltBytes Optional salt size in bytes
|
|
210
|
-
* @param keySize Optional key size in bytes
|
|
211
|
-
* @param algorithm Optional hash algorithm
|
|
212
|
-
* @returns Promise resolving to object containing the derived key, salt, and iteration count
|
|
213
|
-
*/
|
|
214
|
-
public async deriveKeyFromPasswordAsync(
|
|
215
|
-
password: Buffer,
|
|
216
|
-
salt?: Buffer,
|
|
217
|
-
iterations?: number,
|
|
218
|
-
saltBytes?: number,
|
|
219
|
-
keySize?: number,
|
|
220
|
-
algorithm?: string,
|
|
221
|
-
): Promise<IPbkdf2Result> {
|
|
222
|
-
const config = this.getConfig(iterations, saltBytes, keySize, algorithm);
|
|
223
|
-
const saltBytes_ = salt ?? randomBytes(config.saltBytes);
|
|
224
|
-
|
|
225
|
-
if (saltBytes_.length !== config.saltBytes) {
|
|
226
|
-
throw new NodePbkdf2Error(
|
|
227
|
-
getNodeEciesTranslation(
|
|
228
|
-
NodeEciesStringKey.Error_Pbkdf2_InvalidSaltLength,
|
|
229
|
-
),
|
|
230
|
-
Pbkdf2ErrorType.InvalidSaltLength,
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const pbkdf2 = promisify(pbkdf2Async);
|
|
235
|
-
const hashBytes = (await pbkdf2(
|
|
236
|
-
password,
|
|
237
|
-
saltBytes_,
|
|
238
|
-
config.iterations,
|
|
239
|
-
config.hashBytes,
|
|
240
|
-
config.algorithm,
|
|
241
|
-
)) as Buffer;
|
|
242
|
-
|
|
243
|
-
if (hashBytes.length !== config.hashBytes) {
|
|
244
|
-
throw new NodePbkdf2Error(
|
|
245
|
-
getNodeEciesTranslation(
|
|
246
|
-
NodeEciesStringKey.Error_Pbkdf2_InvalidHashLength,
|
|
247
|
-
),
|
|
248
|
-
Pbkdf2ErrorType.InvalidHashLength,
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return {
|
|
253
|
-
salt: saltBytes_,
|
|
254
|
-
hash: hashBytes,
|
|
255
|
-
iterations: config.iterations,
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Derive a key using a predefined configuration profile
|
|
261
|
-
* @param password The password to derive a key from
|
|
262
|
-
* @param profile The configuration profile to use
|
|
263
|
-
* @param salt Optional salt (will be randomly generated if not provided)
|
|
264
|
-
* @returns Object containing the derived key, salt, and iteration count
|
|
265
|
-
*/
|
|
266
|
-
public deriveKeyFromPasswordWithProfile(
|
|
267
|
-
password: Buffer,
|
|
268
|
-
profile: Pbkdf2ProfileEnum,
|
|
269
|
-
salt?: Buffer,
|
|
270
|
-
): IPbkdf2Result {
|
|
271
|
-
const config = this.getProfileConfig(profile);
|
|
272
|
-
return this.deriveKeyFromPassword(
|
|
273
|
-
password,
|
|
274
|
-
salt,
|
|
275
|
-
config.iterations,
|
|
276
|
-
config.saltBytes,
|
|
277
|
-
config.hashBytes,
|
|
278
|
-
config.algorithm,
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Async version of deriveKeyFromPasswordWithProfile
|
|
284
|
-
* @param password The password to derive a key from
|
|
285
|
-
* @param profile The configuration profile to use
|
|
286
|
-
* @param salt Optional salt (will be randomly generated if not provided)
|
|
287
|
-
* @returns Promise resolving to object containing the derived key, salt, and iteration count
|
|
288
|
-
*/
|
|
289
|
-
public async deriveKeyFromPasswordWithProfileAsync(
|
|
290
|
-
password: Buffer,
|
|
291
|
-
profile: Pbkdf2ProfileEnum,
|
|
292
|
-
salt?: Buffer,
|
|
293
|
-
): Promise<IPbkdf2Result> {
|
|
294
|
-
const config = this.getProfileConfig(profile);
|
|
295
|
-
return this.deriveKeyFromPasswordAsync(
|
|
296
|
-
password,
|
|
297
|
-
salt,
|
|
298
|
-
config.iterations,
|
|
299
|
-
config.saltBytes,
|
|
300
|
-
config.hashBytes,
|
|
301
|
-
config.algorithm,
|
|
302
|
-
);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { IStreamProgress } from '../interfaces/stream-progress';
|
|
2
|
-
|
|
3
|
-
export class ProgressTracker {
|
|
4
|
-
private processedBytes = 0;
|
|
5
|
-
private startTime = Date.now();
|
|
6
|
-
private recentSamples: Array<{ bytes: number; timestamp: number }> = [];
|
|
7
|
-
private readonly maxSamples = 5;
|
|
8
|
-
|
|
9
|
-
public update(bytesProcessed: number): IStreamProgress {
|
|
10
|
-
this.processedBytes += bytesProcessed;
|
|
11
|
-
const now = Date.now();
|
|
12
|
-
|
|
13
|
-
this.recentSamples.push({ bytes: bytesProcessed, timestamp: now });
|
|
14
|
-
if (this.recentSamples.length > this.maxSamples) {
|
|
15
|
-
this.recentSamples.shift();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const elapsedMs = now - this.startTime;
|
|
19
|
-
const elapsedSec = elapsedMs / 1000;
|
|
20
|
-
|
|
21
|
-
let throughputBytesPerSec = 0;
|
|
22
|
-
if (this.recentSamples.length >= 2) {
|
|
23
|
-
const firstSample = this.recentSamples[0];
|
|
24
|
-
const lastSample = this.recentSamples[this.recentSamples.length - 1];
|
|
25
|
-
const sampleBytes = this.recentSamples.reduce((sum, s) => sum + s.bytes, 0);
|
|
26
|
-
const sampleTime = (lastSample.timestamp - firstSample.timestamp) / 1000;
|
|
27
|
-
|
|
28
|
-
if (sampleTime > 0) {
|
|
29
|
-
throughputBytesPerSec = sampleBytes / sampleTime;
|
|
30
|
-
}
|
|
31
|
-
} else if (elapsedSec > 0) {
|
|
32
|
-
throughputBytesPerSec = this.processedBytes / elapsedSec;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
processedBytes: this.processedBytes,
|
|
37
|
-
totalBytes: 0,
|
|
38
|
-
percentComplete: 0,
|
|
39
|
-
throughputBytesPerSec,
|
|
40
|
-
estimatedTimeRemainingMs: 0,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
}
|
package/src/test-mocks/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './mock-backend-member';
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EmailString,
|
|
3
|
-
MemberType,
|
|
4
|
-
SecureBuffer,
|
|
5
|
-
SecureString,
|
|
6
|
-
} from '@digitaldefiance/ecies-lib';
|
|
7
|
-
import { Wallet } from '@ethereumjs/wallet';
|
|
8
|
-
import { faker } from '@faker-js/faker';
|
|
9
|
-
import { randomBytes } from 'crypto';
|
|
10
|
-
|
|
11
|
-
import type { IBackendMemberOperational } from '../interfaces/backend-member-operational';
|
|
12
|
-
import { SignatureBuffer } from '../types';
|
|
13
|
-
|
|
14
|
-
const createMockWallet = (): Wallet =>
|
|
15
|
-
({
|
|
16
|
-
getPrivateKey: () =>
|
|
17
|
-
Buffer.from(faker.string.hexadecimal({ length: 64 }), 'hex'),
|
|
18
|
-
getPublicKey: () =>
|
|
19
|
-
Buffer.from(faker.string.hexadecimal({ length: 128 }), 'hex'),
|
|
20
|
-
getAddress: () =>
|
|
21
|
-
Buffer.from(faker.string.hexadecimal({ length: 40 }), 'hex'),
|
|
22
|
-
sign: () => Buffer.from(faker.string.hexadecimal({ length: 128 }), 'hex'),
|
|
23
|
-
} as any);
|
|
24
|
-
|
|
25
|
-
export class MockBackendMember implements IBackendMemberOperational<Buffer> {
|
|
26
|
-
private _id: Buffer;
|
|
27
|
-
private _type: MemberType;
|
|
28
|
-
private _name: string;
|
|
29
|
-
private _email: EmailString;
|
|
30
|
-
private _publicKey: Buffer;
|
|
31
|
-
private _creatorId: Buffer;
|
|
32
|
-
private _dateCreated: Date;
|
|
33
|
-
private _dateUpdated: Date;
|
|
34
|
-
private _privateKey?: SecureBuffer;
|
|
35
|
-
private _wallet?: Wallet;
|
|
36
|
-
private _hasPrivateKey: boolean;
|
|
37
|
-
|
|
38
|
-
constructor(
|
|
39
|
-
data: Partial<{
|
|
40
|
-
id: Buffer;
|
|
41
|
-
type: MemberType;
|
|
42
|
-
name: string;
|
|
43
|
-
email: EmailString;
|
|
44
|
-
publicKey: Buffer;
|
|
45
|
-
privateKey: SecureBuffer;
|
|
46
|
-
wallet: Wallet;
|
|
47
|
-
creatorId: Buffer;
|
|
48
|
-
dateCreated: Date;
|
|
49
|
-
dateUpdated: Date;
|
|
50
|
-
hasPrivateKey: boolean;
|
|
51
|
-
}> = {}
|
|
52
|
-
) {
|
|
53
|
-
this._id = data.id || randomBytes(12);
|
|
54
|
-
this._type = data.type || faker.helpers.enumValue(MemberType);
|
|
55
|
-
this._name = data.name || faker.person.fullName();
|
|
56
|
-
this._email = data.email || new EmailString(faker.internet.email());
|
|
57
|
-
this._publicKey =
|
|
58
|
-
data.publicKey ||
|
|
59
|
-
Buffer.from(faker.string.hexadecimal({ length: 130 }), 'hex');
|
|
60
|
-
this._creatorId = data.creatorId || this._id;
|
|
61
|
-
this._dateCreated = data.dateCreated || faker.date.past();
|
|
62
|
-
this._dateUpdated =
|
|
63
|
-
data.dateUpdated ||
|
|
64
|
-
faker.date.between({ from: this._dateCreated, to: new Date() });
|
|
65
|
-
this._privateKey = data.privateKey;
|
|
66
|
-
this._wallet =
|
|
67
|
-
data.wallet ||
|
|
68
|
-
(data.hasPrivateKey !== false ? createMockWallet() : undefined);
|
|
69
|
-
this._hasPrivateKey = data.hasPrivateKey ?? !!this._privateKey;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
get id(): Buffer {
|
|
73
|
-
return this._id;
|
|
74
|
-
}
|
|
75
|
-
get type(): MemberType {
|
|
76
|
-
return this._type;
|
|
77
|
-
}
|
|
78
|
-
get name(): string {
|
|
79
|
-
return this._name;
|
|
80
|
-
}
|
|
81
|
-
get email(): EmailString {
|
|
82
|
-
return this._email;
|
|
83
|
-
}
|
|
84
|
-
get publicKey(): Uint8Array {
|
|
85
|
-
return this._publicKey;
|
|
86
|
-
}
|
|
87
|
-
get creatorId(): Buffer {
|
|
88
|
-
return this._creatorId;
|
|
89
|
-
}
|
|
90
|
-
get dateCreated(): Date {
|
|
91
|
-
return this._dateCreated;
|
|
92
|
-
}
|
|
93
|
-
get dateUpdated(): Date {
|
|
94
|
-
return this._dateUpdated;
|
|
95
|
-
}
|
|
96
|
-
get privateKey(): SecureBuffer | undefined {
|
|
97
|
-
return this._privateKey;
|
|
98
|
-
}
|
|
99
|
-
get wallet(): Wallet | undefined {
|
|
100
|
-
return this._wallet;
|
|
101
|
-
}
|
|
102
|
-
get hasPrivateKey(): boolean {
|
|
103
|
-
return this._hasPrivateKey;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
unloadPrivateKey(): void {}
|
|
107
|
-
|
|
108
|
-
unloadWallet(): void {}
|
|
109
|
-
|
|
110
|
-
unloadWalletAndPrivateKey(): void {}
|
|
111
|
-
|
|
112
|
-
loadWallet(mnemonic: SecureString): void {}
|
|
113
|
-
|
|
114
|
-
loadPrivateKey(privateKey: SecureBuffer): void {}
|
|
115
|
-
|
|
116
|
-
sign(data: Buffer): SignatureBuffer {
|
|
117
|
-
return Buffer.from(
|
|
118
|
-
faker.string.hexadecimal({ length: 128 }),
|
|
119
|
-
'hex'
|
|
120
|
-
) as SignatureBuffer;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
verify(signature: SignatureBuffer, data: Buffer): boolean {
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
encryptData(data: string | Buffer): Uint8Array {
|
|
128
|
-
return Buffer.from(faker.string.hexadecimal({ length: 256 }), 'hex');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
decryptData(encryptedData: Buffer): Uint8Array {
|
|
132
|
-
return Buffer.from(faker.lorem.paragraph());
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async *encryptDataStream(): AsyncGenerator<any, void, unknown> {
|
|
136
|
-
yield { data: Buffer.from('mock'), header: {} };
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async *decryptDataStream(): AsyncGenerator<Buffer, void, unknown> {
|
|
140
|
-
yield Buffer.from('mock');
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
toJson(): string {
|
|
144
|
-
return JSON.stringify({
|
|
145
|
-
id: this._id.toString('hex'),
|
|
146
|
-
type: this._type,
|
|
147
|
-
name: this._name,
|
|
148
|
-
email: this._email.toString(),
|
|
149
|
-
publicKey: this._publicKey.toString('base64'),
|
|
150
|
-
creatorId: this._creatorId.toString('hex'),
|
|
151
|
-
dateCreated: this._dateCreated.toISOString(),
|
|
152
|
-
dateUpdated: this._dateUpdated.toISOString(),
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
dispose(): void {}
|
|
157
|
-
|
|
158
|
-
static create(
|
|
159
|
-
overrides: Partial<{
|
|
160
|
-
id: Buffer;
|
|
161
|
-
type: MemberType;
|
|
162
|
-
name: string;
|
|
163
|
-
email: EmailString;
|
|
164
|
-
publicKey: Buffer;
|
|
165
|
-
privateKey: SecureBuffer;
|
|
166
|
-
wallet: Wallet;
|
|
167
|
-
creatorId: Buffer;
|
|
168
|
-
dateCreated: Date;
|
|
169
|
-
dateUpdated: Date;
|
|
170
|
-
hasPrivateKey: boolean;
|
|
171
|
-
}> = {}
|
|
172
|
-
): MockBackendMember {
|
|
173
|
-
return new MockBackendMember(overrides);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
static createMultiple(count: number): MockBackendMember[] {
|
|
177
|
-
return Array.from({ length: count }, () => this.create());
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
static createWithPrivateKey(): MockBackendMember {
|
|
181
|
-
return new MockBackendMember({
|
|
182
|
-
privateKey: new SecureBuffer(
|
|
183
|
-
Buffer.from(faker.string.hexadecimal({ length: 64 }), 'hex')
|
|
184
|
-
),
|
|
185
|
-
hasPrivateKey: true,
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
static createWithoutPrivateKey(): MockBackendMember {
|
|
190
|
-
return new MockBackendMember({
|
|
191
|
-
privateKey: undefined,
|
|
192
|
-
hasPrivateKey: false,
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
}
|
package/src/testing.ts
DELETED
package/src/types/id-guards.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type guards and converters for ID types
|
|
3
|
-
* Used to safely convert between Buffer and Uint8Array without unsafe type casts
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Type guard to check if a value is a Buffer
|
|
8
|
-
* @param value - The value to check
|
|
9
|
-
* @returns True if the value is a Buffer
|
|
10
|
-
*/
|
|
11
|
-
export function isBuffer(value: unknown): value is Buffer {
|
|
12
|
-
return Buffer.isBuffer(value);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Type guard to check if a value is a Uint8Array
|
|
17
|
-
* @param value - The value to check
|
|
18
|
-
* @returns True if the value is a Uint8Array
|
|
19
|
-
*/
|
|
20
|
-
export function isUint8Array(value: unknown): value is Uint8Array {
|
|
21
|
-
return value instanceof Uint8Array;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Safely converts an ID value to Buffer
|
|
26
|
-
* @param id - The ID to convert (Buffer, Uint8Array, or string)
|
|
27
|
-
* @returns The ID as a Buffer
|
|
28
|
-
* @throws Error if the ID type is not supported
|
|
29
|
-
*/
|
|
30
|
-
export function toBuffer(id: Buffer | Uint8Array | string): Buffer {
|
|
31
|
-
if (isBuffer(id)) {
|
|
32
|
-
return id;
|
|
33
|
-
}
|
|
34
|
-
if (isUint8Array(id)) {
|
|
35
|
-
return Buffer.from(id);
|
|
36
|
-
}
|
|
37
|
-
if (typeof id === 'string') {
|
|
38
|
-
return Buffer.from(id, 'hex');
|
|
39
|
-
}
|
|
40
|
-
throw new Error(`Cannot convert ID of type ${typeof id} to Buffer`);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Safely converts an ID value to Uint8Array
|
|
45
|
-
* @param id - The ID to convert (Buffer, Uint8Array, or string)
|
|
46
|
-
* @returns The ID as a Uint8Array
|
|
47
|
-
* @throws Error if the ID type is not supported
|
|
48
|
-
*/
|
|
49
|
-
export function toUint8Array(id: Buffer | Uint8Array | string): Uint8Array {
|
|
50
|
-
if (isUint8Array(id)) {
|
|
51
|
-
return id;
|
|
52
|
-
}
|
|
53
|
-
if (isBuffer(id)) {
|
|
54
|
-
return new Uint8Array(id);
|
|
55
|
-
}
|
|
56
|
-
if (typeof id === 'string') {
|
|
57
|
-
return new Uint8Array(Buffer.from(id, 'hex'));
|
|
58
|
-
}
|
|
59
|
-
throw new Error(`Cannot convert ID of type ${typeof id} to Uint8Array`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Generic ID converter that can convert between Buffer, Uint8Array, and string
|
|
64
|
-
* @param id - The ID to convert
|
|
65
|
-
* @param toType - The target type ('Buffer', 'Uint8Array', or 'string')
|
|
66
|
-
* @returns The converted ID
|
|
67
|
-
* @throws Error if the conversion is not supported
|
|
68
|
-
*/
|
|
69
|
-
export function convertId<T extends 'Buffer' | 'Uint8Array' | 'string'>(
|
|
70
|
-
id: Buffer | Uint8Array | string,
|
|
71
|
-
toType: T
|
|
72
|
-
): T extends 'Buffer' ? Buffer : T extends 'Uint8Array' ? Uint8Array : string {
|
|
73
|
-
if (toType === 'Buffer') {
|
|
74
|
-
return toBuffer(id) as any;
|
|
75
|
-
}
|
|
76
|
-
if (toType === 'Uint8Array') {
|
|
77
|
-
return toUint8Array(id) as any;
|
|
78
|
-
}
|
|
79
|
-
if (toType === 'string') {
|
|
80
|
-
if (typeof id === 'string') {
|
|
81
|
-
return id as any;
|
|
82
|
-
}
|
|
83
|
-
if (isBuffer(id)) {
|
|
84
|
-
return id.toString('hex') as any;
|
|
85
|
-
}
|
|
86
|
-
if (isUint8Array(id)) {
|
|
87
|
-
return Buffer.from(id).toString('hex') as any;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
throw new Error(`Cannot convert ID to type ${toType}`);
|
|
91
|
-
}
|
package/src/types/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './id-guards';
|