@carlonicora/nestjs-neo4jsonapi 1.39.0 → 1.40.0
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/dist/config/base.config.d.ts.map +1 -1
- package/dist/config/base.config.js +9 -0
- package/dist/config/base.config.js.map +1 -1
- package/dist/config/interfaces/base.config.interface.d.ts +2 -0
- package/dist/config/interfaces/base.config.interface.d.ts.map +1 -1
- package/dist/config/interfaces/config.two.factor.interface.d.ts +27 -0
- package/dist/config/interfaces/config.two.factor.interface.d.ts.map +1 -0
- package/dist/config/interfaces/config.two.factor.interface.js +3 -0
- package/dist/config/interfaces/config.two.factor.interface.js.map +1 -0
- package/dist/config/interfaces/index.d.ts +1 -0
- package/dist/config/interfaces/index.d.ts.map +1 -1
- package/dist/config/interfaces/index.js +1 -0
- package/dist/config/interfaces/index.js.map +1 -1
- package/dist/core/jsonapi/services/jsonapi.service.d.ts.map +1 -1
- package/dist/core/jsonapi/services/jsonapi.service.js +3 -1
- package/dist/core/jsonapi/services/jsonapi.service.js.map +1 -1
- package/dist/core/llm/services/vision.llm.service.d.ts.map +1 -1
- package/dist/core/llm/services/vision.llm.service.js +0 -1
- package/dist/core/llm/services/vision.llm.service.js.map +1 -1
- package/dist/core/security/services/security.service.d.ts +27 -0
- package/dist/core/security/services/security.service.d.ts.map +1 -1
- package/dist/core/security/services/security.service.js +37 -0
- package/dist/core/security/services/security.service.js.map +1 -1
- package/dist/foundations/auth/auth.module.d.ts.map +1 -1
- package/dist/foundations/auth/auth.module.js +6 -0
- package/dist/foundations/auth/auth.module.js.map +1 -1
- package/dist/foundations/auth/entities/pending-auth.entity.d.ts +16 -0
- package/dist/foundations/auth/entities/pending-auth.entity.d.ts.map +1 -0
- package/dist/foundations/auth/entities/pending-auth.entity.js +3 -0
- package/dist/foundations/auth/entities/pending-auth.entity.js.map +1 -0
- package/dist/foundations/auth/entities/pending-auth.map.d.ts +6 -0
- package/dist/foundations/auth/entities/pending-auth.map.d.ts.map +1 -0
- package/dist/foundations/auth/entities/pending-auth.map.js +20 -0
- package/dist/foundations/auth/entities/pending-auth.map.js.map +1 -0
- package/dist/foundations/auth/entities/pending-auth.meta.d.ts +3 -0
- package/dist/foundations/auth/entities/pending-auth.meta.d.ts.map +1 -0
- package/dist/foundations/auth/entities/pending-auth.meta.js +10 -0
- package/dist/foundations/auth/entities/pending-auth.meta.js.map +1 -0
- package/dist/foundations/auth/entities/pending-auth.model.d.ts +9 -0
- package/dist/foundations/auth/entities/pending-auth.model.d.ts.map +1 -0
- package/dist/foundations/auth/entities/pending-auth.model.js +19 -0
- package/dist/foundations/auth/entities/pending-auth.model.js.map +1 -0
- package/dist/foundations/auth/serialisers/pending-auth.serialiser.d.ts +18 -0
- package/dist/foundations/auth/serialisers/pending-auth.serialiser.d.ts.map +1 -0
- package/dist/foundations/auth/serialisers/pending-auth.serialiser.js +49 -0
- package/dist/foundations/auth/serialisers/pending-auth.serialiser.js.map +1 -0
- package/dist/foundations/auth/services/auth.service.d.ts +12 -1
- package/dist/foundations/auth/services/auth.service.d.ts.map +1 -1
- package/dist/foundations/auth/services/auth.service.js +60 -6
- package/dist/foundations/auth/services/auth.service.js.map +1 -1
- package/dist/foundations/foundations.modules.d.ts.map +1 -1
- package/dist/foundations/foundations.modules.js +2 -0
- package/dist/foundations/foundations.modules.js.map +1 -1
- package/dist/foundations/index.d.ts +1 -0
- package/dist/foundations/index.d.ts.map +1 -1
- package/dist/foundations/index.js +1 -0
- package/dist/foundations/index.js.map +1 -1
- package/dist/foundations/stripe/services/billing.service.d.ts +3 -4
- package/dist/foundations/stripe/services/billing.service.d.ts.map +1 -1
- package/dist/foundations/stripe/services/billing.service.js +1 -1
- package/dist/foundations/stripe/services/billing.service.js.map +1 -1
- package/dist/foundations/stripe-invoice/services/stripe-invoice-admin.service.d.ts +1 -1
- package/dist/foundations/stripe-invoice/services/stripe-invoice-admin.service.js +1 -1
- package/dist/foundations/stripe-invoice/services/stripe-invoice-api.service.d.ts +1 -1
- package/dist/foundations/stripe-invoice/services/stripe-invoice-api.service.d.ts.map +1 -1
- package/dist/foundations/stripe-invoice/services/stripe-invoice-api.service.js +2 -2
- package/dist/foundations/stripe-invoice/services/stripe-invoice-api.service.js.map +1 -1
- package/dist/foundations/stripe-subscription/controllers/stripe-subscription.controller.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/controllers/stripe-subscription.controller.js +0 -3
- package/dist/foundations/stripe-subscription/controllers/stripe-subscription.controller.js.map +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-admin.service.d.ts +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-admin.service.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-admin.service.js +1 -3
- package/dist/foundations/stripe-subscription/services/stripe-subscription-admin.service.js.map +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-api.service.d.ts +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-api.service.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-api.service.js +1 -5
- package/dist/foundations/stripe-subscription/services/stripe-subscription-api.service.js.map +1 -1
- package/dist/foundations/two-factor/controllers/passkey.controller.d.ts +52 -0
- package/dist/foundations/two-factor/controllers/passkey.controller.d.ts.map +1 -0
- package/dist/foundations/two-factor/controllers/passkey.controller.js +155 -0
- package/dist/foundations/two-factor/controllers/passkey.controller.js.map +1 -0
- package/dist/foundations/two-factor/controllers/totp.controller.d.ts +47 -0
- package/dist/foundations/two-factor/controllers/totp.controller.d.ts.map +1 -0
- package/dist/foundations/two-factor/controllers/totp.controller.js +132 -0
- package/dist/foundations/two-factor/controllers/totp.controller.js.map +1 -0
- package/dist/foundations/two-factor/controllers/two-factor.controller.d.ts +124 -0
- package/dist/foundations/two-factor/controllers/two-factor.controller.d.ts.map +1 -0
- package/dist/foundations/two-factor/controllers/two-factor.controller.js +352 -0
- package/dist/foundations/two-factor/controllers/two-factor.controller.js.map +1 -0
- package/dist/foundations/two-factor/dtos/passkey-options.dto.d.ts +42 -0
- package/dist/foundations/two-factor/dtos/passkey-options.dto.d.ts.map +1 -0
- package/dist/foundations/two-factor/dtos/passkey-options.dto.js +77 -0
- package/dist/foundations/two-factor/dtos/passkey-options.dto.js.map +1 -0
- package/dist/foundations/two-factor/dtos/passkey-verify.dto.d.ts +120 -0
- package/dist/foundations/two-factor/dtos/passkey-verify.dto.d.ts.map +1 -0
- package/dist/foundations/two-factor/dtos/passkey-verify.dto.js +226 -0
- package/dist/foundations/two-factor/dtos/passkey-verify.dto.js.map +1 -0
- package/dist/foundations/two-factor/dtos/totp-setup.dto.d.ts +32 -0
- package/dist/foundations/two-factor/dtos/totp-setup.dto.d.ts.map +1 -0
- package/dist/foundations/two-factor/dtos/totp-setup.dto.js +67 -0
- package/dist/foundations/two-factor/dtos/totp-setup.dto.js.map +1 -0
- package/dist/foundations/two-factor/dtos/totp-verify.dto.d.ts +62 -0
- package/dist/foundations/two-factor/dtos/totp-verify.dto.d.ts.map +1 -0
- package/dist/foundations/two-factor/dtos/totp-verify.dto.js +118 -0
- package/dist/foundations/two-factor/dtos/totp-verify.dto.js.map +1 -0
- package/dist/foundations/two-factor/dtos/two-factor-verify.dto.d.ts +83 -0
- package/dist/foundations/two-factor/dtos/two-factor-verify.dto.d.ts.map +1 -0
- package/dist/foundations/two-factor/dtos/two-factor-verify.dto.js +161 -0
- package/dist/foundations/two-factor/dtos/two-factor-verify.dto.js.map +1 -0
- package/dist/foundations/two-factor/entities/backup-code.d.ts +22 -0
- package/dist/foundations/two-factor/entities/backup-code.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/backup-code.js +25 -0
- package/dist/foundations/two-factor/entities/backup-code.js.map +1 -0
- package/dist/foundations/two-factor/entities/backup-code.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/backup-code.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/backup-code.meta.js +10 -0
- package/dist/foundations/two-factor/entities/backup-code.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.d.ts +18 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.js +19 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.js.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.meta.js +10 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.d.ts +19 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.js +20 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.js.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.meta.js +10 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.d.ts +19 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.js +20 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.js.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.meta.js +10 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.d.ts +19 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.js +20 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.js.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.meta.js +10 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/passkey.d.ts +27 -0
- package/dist/foundations/two-factor/entities/passkey.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/passkey.js +30 -0
- package/dist/foundations/two-factor/entities/passkey.js.map +1 -0
- package/dist/foundations/two-factor/entities/passkey.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/passkey.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/passkey.meta.js +10 -0
- package/dist/foundations/two-factor/entities/passkey.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.d.ts +24 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.js +27 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.js.map +1 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.meta.js +10 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.d.ts +24 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.js +27 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.js.map +1 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.meta.js +10 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/totp-setup.d.ts +20 -0
- package/dist/foundations/two-factor/entities/totp-setup.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/totp-setup.js +21 -0
- package/dist/foundations/two-factor/entities/totp-setup.js.map +1 -0
- package/dist/foundations/two-factor/entities/totp-setup.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/totp-setup.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/totp-setup.meta.js +10 -0
- package/dist/foundations/two-factor/entities/totp-setup.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.d.ts +21 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.js +22 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.meta.js +10 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-config.d.ts +21 -0
- package/dist/foundations/two-factor/entities/two-factor-config.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-config.js +23 -0
- package/dist/foundations/two-factor/entities/two-factor-config.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-config.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/two-factor-config.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-config.meta.js +10 -0
- package/dist/foundations/two-factor/entities/two-factor-config.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-status.d.ts +25 -0
- package/dist/foundations/two-factor/entities/two-factor-status.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-status.js +22 -0
- package/dist/foundations/two-factor/entities/two-factor-status.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-status.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/two-factor-status.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-status.meta.js +10 -0
- package/dist/foundations/two-factor/entities/two-factor-status.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.d.ts +19 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.js +20 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.meta.js +10 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.meta.js.map +1 -0
- package/dist/foundations/two-factor/guards/pending-auth.guard.d.ts +35 -0
- package/dist/foundations/two-factor/guards/pending-auth.guard.d.ts.map +1 -0
- package/dist/foundations/two-factor/guards/pending-auth.guard.js +70 -0
- package/dist/foundations/two-factor/guards/pending-auth.guard.js.map +1 -0
- package/dist/foundations/two-factor/index.d.ts +47 -0
- package/dist/foundations/two-factor/index.d.ts.map +1 -0
- package/dist/foundations/two-factor/index.js +134 -0
- package/dist/foundations/two-factor/index.js.map +1 -0
- package/dist/foundations/two-factor/repositories/backup-code.repository.d.ts +34 -0
- package/dist/foundations/two-factor/repositories/backup-code.repository.d.ts.map +1 -0
- package/dist/foundations/two-factor/repositories/backup-code.repository.js +107 -0
- package/dist/foundations/two-factor/repositories/backup-code.repository.js.map +1 -0
- package/dist/foundations/two-factor/repositories/passkey.repository.d.ts +51 -0
- package/dist/foundations/two-factor/repositories/passkey.repository.d.ts.map +1 -0
- package/dist/foundations/two-factor/repositories/passkey.repository.js +159 -0
- package/dist/foundations/two-factor/repositories/passkey.repository.js.map +1 -0
- package/dist/foundations/two-factor/repositories/pending-two-factor.repository.d.ts +47 -0
- package/dist/foundations/two-factor/repositories/pending-two-factor.repository.d.ts.map +1 -0
- package/dist/foundations/two-factor/repositories/pending-two-factor.repository.js +159 -0
- package/dist/foundations/two-factor/repositories/pending-two-factor.repository.js.map +1 -0
- package/dist/foundations/two-factor/repositories/totp-authenticator.repository.d.ts +51 -0
- package/dist/foundations/two-factor/repositories/totp-authenticator.repository.d.ts.map +1 -0
- package/dist/foundations/two-factor/repositories/totp-authenticator.repository.js +156 -0
- package/dist/foundations/two-factor/repositories/totp-authenticator.repository.js.map +1 -0
- package/dist/foundations/two-factor/repositories/two-factor-config.repository.d.ts +32 -0
- package/dist/foundations/two-factor/repositories/two-factor-config.repository.d.ts.map +1 -0
- package/dist/foundations/two-factor/repositories/two-factor-config.repository.js +105 -0
- package/dist/foundations/two-factor/repositories/two-factor-config.repository.js.map +1 -0
- package/dist/foundations/two-factor/services/backup-code.service.d.ts +95 -0
- package/dist/foundations/two-factor/services/backup-code.service.d.ts.map +1 -0
- package/dist/foundations/two-factor/services/backup-code.service.js +216 -0
- package/dist/foundations/two-factor/services/backup-code.service.js.map +1 -0
- package/dist/foundations/two-factor/services/index.d.ts +6 -0
- package/dist/foundations/two-factor/services/index.d.ts.map +1 -0
- package/dist/foundations/two-factor/services/index.js +14 -0
- package/dist/foundations/two-factor/services/index.js.map +1 -0
- package/dist/foundations/two-factor/services/passkey.service.d.ts +132 -0
- package/dist/foundations/two-factor/services/passkey.service.d.ts.map +1 -0
- package/dist/foundations/two-factor/services/passkey.service.js +400 -0
- package/dist/foundations/two-factor/services/passkey.service.js.map +1 -0
- package/dist/foundations/two-factor/services/totp-encryption.service.d.ts +42 -0
- package/dist/foundations/two-factor/services/totp-encryption.service.d.ts.map +1 -0
- package/dist/foundations/two-factor/services/totp-encryption.service.js +136 -0
- package/dist/foundations/two-factor/services/totp-encryption.service.js.map +1 -0
- package/dist/foundations/two-factor/services/totp.service.d.ts +132 -0
- package/dist/foundations/two-factor/services/totp.service.d.ts.map +1 -0
- package/dist/foundations/two-factor/services/totp.service.js +324 -0
- package/dist/foundations/two-factor/services/totp.service.js.map +1 -0
- package/dist/foundations/two-factor/services/two-factor.service.d.ts +165 -0
- package/dist/foundations/two-factor/services/two-factor.service.d.ts.map +1 -0
- package/dist/foundations/two-factor/services/two-factor.service.js +468 -0
- package/dist/foundations/two-factor/services/two-factor.service.js.map +1 -0
- package/dist/foundations/two-factor/two-factor.module.d.ts +23 -0
- package/dist/foundations/two-factor/two-factor.module.d.ts.map +1 -0
- package/dist/foundations/two-factor/two-factor.module.js +132 -0
- package/dist/foundations/two-factor/two-factor.module.js.map +1 -0
- package/dist/foundations/user/repositories/user.repository.d.ts +8 -0
- package/dist/foundations/user/repositories/user.repository.d.ts.map +1 -1
- package/dist/foundations/user/repositories/user.repository.js +28 -1
- package/dist/foundations/user/repositories/user.repository.js.map +1 -1
- package/dist/foundations/waitlist/controllers/waitlist.controller.d.ts.map +1 -1
- package/dist/foundations/waitlist/controllers/waitlist.controller.js +0 -4
- package/dist/foundations/waitlist/controllers/waitlist.controller.js.map +1 -1
- package/dist/foundations/waitlist/repositories/waitlist.repository.d.ts.map +1 -1
- package/dist/foundations/waitlist/repositories/waitlist.repository.js +0 -2
- package/dist/foundations/waitlist/repositories/waitlist.repository.js.map +1 -1
- package/dist/foundations/waitlist/services/waitlist.service.d.ts +1 -0
- package/dist/foundations/waitlist/services/waitlist.service.d.ts.map +1 -1
- package/dist/foundations/waitlist/services/waitlist.service.js +6 -7
- package/dist/foundations/waitlist/services/waitlist.service.js.map +1 -1
- package/dist/scripts/generate-module/generator.js +13 -13
- package/dist/scripts/generate-module/generator.js.map +1 -1
- package/dist/scripts/generate-module/index.js +6 -6
- package/dist/scripts/generate-module/index.js.map +1 -1
- package/dist/scripts/generate-module/utils/file-writer.js +2 -2
- package/dist/scripts/generate-module/utils/file-writer.js.map +1 -1
- package/dist/scripts/generate-module/utils/module-registrar.js +7 -7
- package/dist/scripts/generate-module/utils/module-registrar.js.map +1 -1
- package/dist/tools/migrate-entity/index.js +3 -3
- package/dist/tools/migrate-entity/lib/descriptor-generator.js +6 -6
- package/dist/tools/migrate-entity/lib/entity-migrator.js +13 -13
- package/package.json +5 -1
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.PasskeyService = void 0;
|
|
46
|
+
const common_1 = require("@nestjs/common");
|
|
47
|
+
const server_1 = require("@simplewebauthn/server");
|
|
48
|
+
const crypto = __importStar(require("crypto"));
|
|
49
|
+
const base_config_1 = require("../../../config/base.config");
|
|
50
|
+
const jsonapi_service_1 = require("../../../core/jsonapi/services/jsonapi.service");
|
|
51
|
+
const passkey_1 = require("../entities/passkey");
|
|
52
|
+
const passkey_authentication_options_1 = require("../entities/passkey-authentication-options");
|
|
53
|
+
const passkey_registration_options_1 = require("../entities/passkey-registration-options");
|
|
54
|
+
const passkey_repository_1 = require("../repositories/passkey.repository");
|
|
55
|
+
const pending_two_factor_repository_1 = require("../repositories/pending-two-factor.repository");
|
|
56
|
+
/**
|
|
57
|
+
* Passkey Service
|
|
58
|
+
*
|
|
59
|
+
* Manages WebAuthn passkey registration and authentication for two-factor authentication.
|
|
60
|
+
* Provides passkey enrollment, verification, and management capabilities.
|
|
61
|
+
*/
|
|
62
|
+
let PasskeyService = class PasskeyService {
|
|
63
|
+
constructor(jsonApiService, passkeyRepository, pendingTwoFactorRepository) {
|
|
64
|
+
this.jsonApiService = jsonApiService;
|
|
65
|
+
this.passkeyRepository = passkeyRepository;
|
|
66
|
+
this.pendingTwoFactorRepository = pendingTwoFactorRepository;
|
|
67
|
+
this.challengeTtlSeconds = 300; // 5 minutes
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get WebAuthn Relying Party configuration from environment.
|
|
71
|
+
*/
|
|
72
|
+
getRpConfig() {
|
|
73
|
+
return {
|
|
74
|
+
rpId: base_config_1.baseConfig.twoFactor.webauthnRpId,
|
|
75
|
+
rpName: base_config_1.baseConfig.twoFactor.webauthnRpName,
|
|
76
|
+
origin: base_config_1.baseConfig.twoFactor.webauthnOrigin,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Generate registration options for creating a new passkey.
|
|
81
|
+
*
|
|
82
|
+
* @param params.userId - The user's ID
|
|
83
|
+
* @param params.userName - The user's email or username
|
|
84
|
+
* @param params.userDisplayName - The user's display name
|
|
85
|
+
* @returns JSON:API response with registration options
|
|
86
|
+
*/
|
|
87
|
+
async generateRegistrationOptions(params) {
|
|
88
|
+
const { rpId, rpName } = this.getRpConfig();
|
|
89
|
+
// Get existing passkeys to exclude them from registration
|
|
90
|
+
const existingPasskeys = await this.passkeyRepository.findAllByUserIdWithCredentials({
|
|
91
|
+
userId: params.userId,
|
|
92
|
+
});
|
|
93
|
+
const excludeCredentials = existingPasskeys.map((passkey) => ({
|
|
94
|
+
id: passkey.credentialId,
|
|
95
|
+
type: "public-key",
|
|
96
|
+
transports: this.parseTransports(passkey.transports),
|
|
97
|
+
}));
|
|
98
|
+
const options = await (0, server_1.generateRegistrationOptions)({
|
|
99
|
+
rpName,
|
|
100
|
+
rpID: rpId,
|
|
101
|
+
userName: params.userName,
|
|
102
|
+
userDisplayName: params.userDisplayName,
|
|
103
|
+
// Use base64url-encoded user ID for WebAuthn
|
|
104
|
+
userID: new TextEncoder().encode(params.userId),
|
|
105
|
+
attestationType: "none", // We don't need attestation for 2FA
|
|
106
|
+
excludeCredentials,
|
|
107
|
+
authenticatorSelection: {
|
|
108
|
+
residentKey: "preferred",
|
|
109
|
+
userVerification: "preferred",
|
|
110
|
+
// Allow both platform (Touch ID, Windows Hello) and cross-platform (USB keys)
|
|
111
|
+
authenticatorAttachment: undefined,
|
|
112
|
+
},
|
|
113
|
+
timeout: 60000, // 60 seconds
|
|
114
|
+
});
|
|
115
|
+
// Store the challenge for verification
|
|
116
|
+
const pendingId = crypto.randomUUID();
|
|
117
|
+
const expiration = new Date(Date.now() + this.challengeTtlSeconds * 1000);
|
|
118
|
+
await this.pendingTwoFactorRepository.createForUser({
|
|
119
|
+
pendingId,
|
|
120
|
+
userId: params.userId,
|
|
121
|
+
challenge: options.challenge,
|
|
122
|
+
challengeType: "passkey-registration",
|
|
123
|
+
expiration,
|
|
124
|
+
});
|
|
125
|
+
return this.jsonApiService.buildSingle(passkey_registration_options_1.PasskeyRegistrationOptionsDescriptor.model, {
|
|
126
|
+
id: pendingId,
|
|
127
|
+
pendingId,
|
|
128
|
+
options,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Verify a passkey registration response and create the passkey.
|
|
133
|
+
*
|
|
134
|
+
* @param params.pendingId - The pending challenge ID from generateRegistrationOptions
|
|
135
|
+
* @param params.name - A friendly name for this passkey
|
|
136
|
+
* @param params.response - The WebAuthn credential response from the client
|
|
137
|
+
* @returns JSON:API response with the created passkey
|
|
138
|
+
*/
|
|
139
|
+
async verifyRegistration(params) {
|
|
140
|
+
const { rpId, origin } = this.getRpConfig();
|
|
141
|
+
// Get the pending challenge
|
|
142
|
+
const pendingData = await this.pendingTwoFactorRepository.findByIdWithUser({
|
|
143
|
+
pendingId: params.pendingId,
|
|
144
|
+
});
|
|
145
|
+
if (!pendingData) {
|
|
146
|
+
throw new common_1.NotFoundException("Registration challenge not found or expired");
|
|
147
|
+
}
|
|
148
|
+
const { pending, userId } = pendingData;
|
|
149
|
+
// Validate challenge type
|
|
150
|
+
if (pending.challengeType !== "passkey-registration") {
|
|
151
|
+
throw new common_1.BadRequestException("Invalid challenge type");
|
|
152
|
+
}
|
|
153
|
+
// Check expiration
|
|
154
|
+
if (new Date() > pending.expiration) {
|
|
155
|
+
await this.pendingTwoFactorRepository.deletePending({ pendingId: params.pendingId });
|
|
156
|
+
throw new common_1.BadRequestException("Registration challenge has expired");
|
|
157
|
+
}
|
|
158
|
+
// Verify the registration response
|
|
159
|
+
let verification;
|
|
160
|
+
try {
|
|
161
|
+
verification = await (0, server_1.verifyRegistrationResponse)({
|
|
162
|
+
response: params.response,
|
|
163
|
+
expectedChallenge: pending.challenge,
|
|
164
|
+
expectedOrigin: origin,
|
|
165
|
+
expectedRPID: rpId,
|
|
166
|
+
requireUserVerification: false, // Allow UV to be optional for broader device support
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
throw new common_1.BadRequestException(`Registration verification failed: ${error.message}`);
|
|
171
|
+
}
|
|
172
|
+
if (!verification.verified || !verification.registrationInfo) {
|
|
173
|
+
throw new common_1.BadRequestException("Registration verification failed");
|
|
174
|
+
}
|
|
175
|
+
const { credential, credentialBackedUp } = verification.registrationInfo;
|
|
176
|
+
// Create the passkey in the database
|
|
177
|
+
const passkeyId = crypto.randomUUID();
|
|
178
|
+
const passkey = await this.passkeyRepository.createForUser({
|
|
179
|
+
passkeyId,
|
|
180
|
+
userId,
|
|
181
|
+
name: params.name,
|
|
182
|
+
credentialId: this.uint8ArrayToBase64Url(credential.id),
|
|
183
|
+
publicKey: this.uint8ArrayToBase64Url(credential.publicKey),
|
|
184
|
+
counter: credential.counter,
|
|
185
|
+
transports: params.response.response.transports || [],
|
|
186
|
+
backedUp: credentialBackedUp,
|
|
187
|
+
});
|
|
188
|
+
// Delete the pending challenge
|
|
189
|
+
await this.pendingTwoFactorRepository.deletePending({ pendingId: params.pendingId });
|
|
190
|
+
return this.jsonApiService.buildSingle(passkey_1.PasskeyDescriptor.model, passkey);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Generate authentication options for passkey sign-in.
|
|
194
|
+
*
|
|
195
|
+
* @param params.userId - The user's ID
|
|
196
|
+
* @returns JSON:API response with authentication options
|
|
197
|
+
*/
|
|
198
|
+
async generateAuthenticationOptions(params) {
|
|
199
|
+
const { rpId } = this.getRpConfig();
|
|
200
|
+
// Get user's passkeys
|
|
201
|
+
const passkeys = await this.passkeyRepository.findAllByUserIdWithCredentials({
|
|
202
|
+
userId: params.userId,
|
|
203
|
+
});
|
|
204
|
+
if (passkeys.length === 0) {
|
|
205
|
+
throw new common_1.BadRequestException("User has no registered passkeys");
|
|
206
|
+
}
|
|
207
|
+
const allowCredentials = passkeys.map((passkey) => ({
|
|
208
|
+
id: passkey.credentialId,
|
|
209
|
+
type: "public-key",
|
|
210
|
+
transports: this.parseTransports(passkey.transports),
|
|
211
|
+
}));
|
|
212
|
+
const options = await (0, server_1.generateAuthenticationOptions)({
|
|
213
|
+
rpID: rpId,
|
|
214
|
+
allowCredentials,
|
|
215
|
+
userVerification: "preferred",
|
|
216
|
+
timeout: 60000,
|
|
217
|
+
});
|
|
218
|
+
// Store the challenge for verification
|
|
219
|
+
const pendingId = crypto.randomUUID();
|
|
220
|
+
const expiration = new Date(Date.now() + this.challengeTtlSeconds * 1000);
|
|
221
|
+
await this.pendingTwoFactorRepository.createForUser({
|
|
222
|
+
pendingId,
|
|
223
|
+
userId: params.userId,
|
|
224
|
+
challenge: options.challenge,
|
|
225
|
+
challengeType: "passkey-authentication",
|
|
226
|
+
expiration,
|
|
227
|
+
});
|
|
228
|
+
return this.jsonApiService.buildSingle(passkey_authentication_options_1.PasskeyAuthenticationOptionsDescriptor.model, {
|
|
229
|
+
id: pendingId,
|
|
230
|
+
pendingId,
|
|
231
|
+
options,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Verify a passkey authentication response.
|
|
236
|
+
*
|
|
237
|
+
* @param params.pendingId - The pending challenge ID from generateAuthenticationOptions
|
|
238
|
+
* @param params.response - The WebAuthn assertion response from the client
|
|
239
|
+
* @returns The passkey ID if verification succeeds
|
|
240
|
+
*/
|
|
241
|
+
async verifyAuthentication(params) {
|
|
242
|
+
const { rpId, origin } = this.getRpConfig();
|
|
243
|
+
// Get the pending challenge
|
|
244
|
+
const pendingData = await this.pendingTwoFactorRepository.findByIdWithUser({
|
|
245
|
+
pendingId: params.pendingId,
|
|
246
|
+
});
|
|
247
|
+
if (!pendingData) {
|
|
248
|
+
throw new common_1.NotFoundException("Authentication challenge not found or expired");
|
|
249
|
+
}
|
|
250
|
+
const { pending, userId: _userId } = pendingData;
|
|
251
|
+
// Validate challenge type
|
|
252
|
+
if (pending.challengeType !== "passkey-authentication") {
|
|
253
|
+
throw new common_1.BadRequestException("Invalid challenge type");
|
|
254
|
+
}
|
|
255
|
+
// Check expiration
|
|
256
|
+
if (new Date() > pending.expiration) {
|
|
257
|
+
await this.pendingTwoFactorRepository.deletePending({ pendingId: params.pendingId });
|
|
258
|
+
throw new common_1.BadRequestException("Authentication challenge has expired");
|
|
259
|
+
}
|
|
260
|
+
// Find the passkey by credential ID
|
|
261
|
+
const passkey = await this.passkeyRepository.findByCredentialId({
|
|
262
|
+
credentialId: params.response.id,
|
|
263
|
+
});
|
|
264
|
+
if (!passkey) {
|
|
265
|
+
throw new common_1.BadRequestException("Passkey not found");
|
|
266
|
+
}
|
|
267
|
+
// Verify the authentication response
|
|
268
|
+
let verification;
|
|
269
|
+
try {
|
|
270
|
+
verification = await (0, server_1.verifyAuthenticationResponse)({
|
|
271
|
+
response: params.response,
|
|
272
|
+
expectedChallenge: pending.challenge,
|
|
273
|
+
expectedOrigin: origin,
|
|
274
|
+
expectedRPID: rpId,
|
|
275
|
+
credential: {
|
|
276
|
+
// id is a Base64URL string
|
|
277
|
+
id: passkey.credentialId,
|
|
278
|
+
// publicKey is a Uint8Array
|
|
279
|
+
publicKey: this.base64UrlToUint8Array(passkey.publicKey),
|
|
280
|
+
counter: passkey.counter,
|
|
281
|
+
transports: this.parseTransports(passkey.transports),
|
|
282
|
+
},
|
|
283
|
+
requireUserVerification: false,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
throw new common_1.BadRequestException(`Authentication verification failed: ${error.message}`);
|
|
288
|
+
}
|
|
289
|
+
if (!verification.verified) {
|
|
290
|
+
throw new common_1.BadRequestException("Authentication verification failed");
|
|
291
|
+
}
|
|
292
|
+
// Update the passkey counter and last used time
|
|
293
|
+
await this.passkeyRepository.updatePasskey({
|
|
294
|
+
passkeyId: passkey.id,
|
|
295
|
+
counter: verification.authenticationInfo.newCounter,
|
|
296
|
+
lastUsedAt: new Date(),
|
|
297
|
+
});
|
|
298
|
+
// Delete the pending challenge
|
|
299
|
+
await this.pendingTwoFactorRepository.deletePending({ pendingId: params.pendingId });
|
|
300
|
+
return passkey.id;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* List all passkeys for a user.
|
|
304
|
+
*
|
|
305
|
+
* @param params.userId - The user's ID
|
|
306
|
+
* @returns JSON:API response with list of passkeys
|
|
307
|
+
*/
|
|
308
|
+
async listPasskeys(params) {
|
|
309
|
+
const passkeys = await this.passkeyRepository.findByUserId({
|
|
310
|
+
userId: params.userId,
|
|
311
|
+
});
|
|
312
|
+
return this.jsonApiService.buildList(passkey_1.PasskeyDescriptor.model, passkeys);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Remove a passkey.
|
|
316
|
+
*
|
|
317
|
+
* @param params.passkeyId - The passkey ID to remove
|
|
318
|
+
*/
|
|
319
|
+
async removePasskey(params) {
|
|
320
|
+
const passkey = await this.passkeyRepository.findByIdForUser({
|
|
321
|
+
passkeyId: params.passkeyId,
|
|
322
|
+
});
|
|
323
|
+
if (!passkey) {
|
|
324
|
+
throw new common_1.NotFoundException("Passkey not found");
|
|
325
|
+
}
|
|
326
|
+
await this.passkeyRepository.deletePasskey({
|
|
327
|
+
passkeyId: params.passkeyId,
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Rename a passkey.
|
|
332
|
+
*
|
|
333
|
+
* @param params.passkeyId - The passkey ID to rename
|
|
334
|
+
* @param params.name - The new name for the passkey
|
|
335
|
+
*/
|
|
336
|
+
async renamePasskey(params) {
|
|
337
|
+
const passkey = await this.passkeyRepository.findByIdForUser({
|
|
338
|
+
passkeyId: params.passkeyId,
|
|
339
|
+
});
|
|
340
|
+
if (!passkey) {
|
|
341
|
+
throw new common_1.NotFoundException("Passkey not found");
|
|
342
|
+
}
|
|
343
|
+
if (!params.name || params.name.trim().length === 0) {
|
|
344
|
+
throw new common_1.BadRequestException("Passkey name cannot be empty");
|
|
345
|
+
}
|
|
346
|
+
await this.passkeyRepository.updatePasskey({
|
|
347
|
+
passkeyId: params.passkeyId,
|
|
348
|
+
name: params.name.trim(),
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Check if a user has any registered passkeys.
|
|
353
|
+
*
|
|
354
|
+
* @param params.userId - The user's ID
|
|
355
|
+
* @returns true if the user has at least one passkey
|
|
356
|
+
*/
|
|
357
|
+
async hasPasskeys(params) {
|
|
358
|
+
const count = await this.passkeyRepository.countByUserId({
|
|
359
|
+
userId: params.userId,
|
|
360
|
+
});
|
|
361
|
+
return count > 0;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Parse transports JSON string into array.
|
|
365
|
+
*/
|
|
366
|
+
parseTransports(transportsJson) {
|
|
367
|
+
try {
|
|
368
|
+
return JSON.parse(transportsJson);
|
|
369
|
+
}
|
|
370
|
+
catch {
|
|
371
|
+
return [];
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Convert Uint8Array to base64url string.
|
|
376
|
+
*/
|
|
377
|
+
uint8ArrayToBase64Url(array) {
|
|
378
|
+
return Buffer.from(array).toString("base64url");
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Convert base64url string to Uint8Array.
|
|
382
|
+
* The type assertion ensures compatibility with @simplewebauthn's expected types.
|
|
383
|
+
*/
|
|
384
|
+
base64UrlToUint8Array(base64url) {
|
|
385
|
+
const buffer = Buffer.from(base64url, "base64url");
|
|
386
|
+
// Create a proper ArrayBuffer-backed Uint8Array for WebAuthn compatibility
|
|
387
|
+
const arrayBuffer = new ArrayBuffer(buffer.length);
|
|
388
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
|
389
|
+
buffer.copy(uint8Array);
|
|
390
|
+
return uint8Array;
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
exports.PasskeyService = PasskeyService;
|
|
394
|
+
exports.PasskeyService = PasskeyService = __decorate([
|
|
395
|
+
(0, common_1.Injectable)(),
|
|
396
|
+
__metadata("design:paramtypes", [jsonapi_service_1.JsonApiService,
|
|
397
|
+
passkey_repository_1.PasskeyRepository,
|
|
398
|
+
pending_two_factor_repository_1.PendingTwoFactorRepository])
|
|
399
|
+
], PasskeyService);
|
|
400
|
+
//# sourceMappingURL=passkey.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"passkey.service.js","sourceRoot":"","sources":["../../../../src/foundations/two-factor/services/passkey.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAoF;AACpF,mDAWgC;AAChC,+CAAiC;AACjC,6DAAyD;AACzD,oFAAgF;AAChF,iDAAwD;AACxD,+FAAoG;AACpG,2FAAgG;AAChG,2EAAuE;AACvE,iGAA2F;AAoB3F;;;;;GAKG;AAEI,IAAM,cAAc,GAApB,MAAM,cAAc;IAGzB,YACmB,cAA8B,EAC9B,iBAAoC,EACpC,0BAAsD;QAFtD,mBAAc,GAAd,cAAc,CAAgB;QAC9B,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,+BAA0B,GAA1B,0BAA0B,CAA4B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0B;GAN9D,cAAc,CAuY1B"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TOTP Encryption Service
|
|
3
|
+
*
|
|
4
|
+
* Provides AES-256-GCM encryption/decryption for TOTP secrets.
|
|
5
|
+
* Secrets are encrypted before storage in Neo4j and decrypted for TOTP validation.
|
|
6
|
+
*
|
|
7
|
+
* Format: IV (12 bytes) + AuthTag (16 bytes) + Ciphertext (base64 encoded)
|
|
8
|
+
*/
|
|
9
|
+
export declare class TotpEncryptionService {
|
|
10
|
+
private readonly algorithm;
|
|
11
|
+
private readonly ivLength;
|
|
12
|
+
private readonly authTagLength;
|
|
13
|
+
/**
|
|
14
|
+
* Get the encryption key from config.
|
|
15
|
+
* The key must be exactly 32 bytes (256 bits) for AES-256.
|
|
16
|
+
*/
|
|
17
|
+
private getKey;
|
|
18
|
+
/**
|
|
19
|
+
* Encrypt a TOTP secret using AES-256-GCM.
|
|
20
|
+
*
|
|
21
|
+
* @param plaintext - The TOTP secret to encrypt (typically base32-encoded)
|
|
22
|
+
* @returns The encrypted secret as a base64-encoded string containing IV, auth tag, and ciphertext
|
|
23
|
+
*/
|
|
24
|
+
encrypt(plaintext: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Decrypt a TOTP secret encrypted with AES-256-GCM.
|
|
27
|
+
*
|
|
28
|
+
* @param ciphertext - The base64-encoded encrypted secret (IV + AuthTag + Ciphertext)
|
|
29
|
+
* @returns The decrypted TOTP secret
|
|
30
|
+
* @throws Error if decryption fails (invalid key, corrupted data, or tampered data)
|
|
31
|
+
*/
|
|
32
|
+
decrypt(ciphertext: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Verify that the encryption system is properly configured.
|
|
35
|
+
* Performs a round-trip encryption/decryption test.
|
|
36
|
+
*
|
|
37
|
+
* @returns true if encryption is working correctly
|
|
38
|
+
* @throws Error if encryption is not properly configured
|
|
39
|
+
*/
|
|
40
|
+
verify(): boolean;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=totp-encryption.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"totp-encryption.service.d.ts","sourceRoot":"","sources":["../../../../src/foundations/two-factor/services/totp-encryption.service.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,qBACa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiB;IAC3C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAM;IAC/B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAM;IAEpC;;;OAGG;IACH,OAAO,CAAC,MAAM;IAwBd;;;;;OAKG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAelC;;;;;;OAMG;IACH,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAiBnC;;;;;;OAMG;IACH,MAAM,IAAI,OAAO;CAMlB"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.TotpEncryptionService = void 0;
|
|
43
|
+
const common_1 = require("@nestjs/common");
|
|
44
|
+
const crypto = __importStar(require("crypto"));
|
|
45
|
+
const base_config_1 = require("../../../config/base.config");
|
|
46
|
+
/**
|
|
47
|
+
* TOTP Encryption Service
|
|
48
|
+
*
|
|
49
|
+
* Provides AES-256-GCM encryption/decryption for TOTP secrets.
|
|
50
|
+
* Secrets are encrypted before storage in Neo4j and decrypted for TOTP validation.
|
|
51
|
+
*
|
|
52
|
+
* Format: IV (12 bytes) + AuthTag (16 bytes) + Ciphertext (base64 encoded)
|
|
53
|
+
*/
|
|
54
|
+
let TotpEncryptionService = class TotpEncryptionService {
|
|
55
|
+
constructor() {
|
|
56
|
+
this.algorithm = "aes-256-gcm";
|
|
57
|
+
this.ivLength = 12; // 96 bits for GCM
|
|
58
|
+
this.authTagLength = 16; // 128 bits
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get the encryption key from config.
|
|
62
|
+
* The key must be exactly 32 bytes (256 bits) for AES-256.
|
|
63
|
+
*/
|
|
64
|
+
getKey() {
|
|
65
|
+
const keyString = base_config_1.baseConfig.twoFactor.totpEncryptionKey;
|
|
66
|
+
if (!keyString) {
|
|
67
|
+
throw new Error("TOTP_ENCRYPTION_KEY environment variable is not set");
|
|
68
|
+
}
|
|
69
|
+
// If the key is hex-encoded (64 chars = 32 bytes), decode it
|
|
70
|
+
if (keyString.length === 64 && /^[0-9a-fA-F]+$/.test(keyString)) {
|
|
71
|
+
return Buffer.from(keyString, "hex");
|
|
72
|
+
}
|
|
73
|
+
// If the key is base64-encoded
|
|
74
|
+
if (keyString.length === 44 && keyString.endsWith("=")) {
|
|
75
|
+
const decoded = Buffer.from(keyString, "base64");
|
|
76
|
+
if (decoded.length === 32) {
|
|
77
|
+
return decoded;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Otherwise, derive a 32-byte key using SHA-256
|
|
81
|
+
return crypto.createHash("sha256").update(keyString).digest();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Encrypt a TOTP secret using AES-256-GCM.
|
|
85
|
+
*
|
|
86
|
+
* @param plaintext - The TOTP secret to encrypt (typically base32-encoded)
|
|
87
|
+
* @returns The encrypted secret as a base64-encoded string containing IV, auth tag, and ciphertext
|
|
88
|
+
*/
|
|
89
|
+
encrypt(plaintext) {
|
|
90
|
+
const key = this.getKey();
|
|
91
|
+
const iv = crypto.randomBytes(this.ivLength);
|
|
92
|
+
const cipher = crypto.createCipheriv(this.algorithm, key, iv);
|
|
93
|
+
const encrypted = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
94
|
+
const authTag = cipher.getAuthTag();
|
|
95
|
+
// Combine IV + AuthTag + Ciphertext
|
|
96
|
+
const combined = Buffer.concat([iv, authTag, encrypted]);
|
|
97
|
+
return combined.toString("base64");
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Decrypt a TOTP secret encrypted with AES-256-GCM.
|
|
101
|
+
*
|
|
102
|
+
* @param ciphertext - The base64-encoded encrypted secret (IV + AuthTag + Ciphertext)
|
|
103
|
+
* @returns The decrypted TOTP secret
|
|
104
|
+
* @throws Error if decryption fails (invalid key, corrupted data, or tampered data)
|
|
105
|
+
*/
|
|
106
|
+
decrypt(ciphertext) {
|
|
107
|
+
const key = this.getKey();
|
|
108
|
+
const combined = Buffer.from(ciphertext, "base64");
|
|
109
|
+
// Extract IV, AuthTag, and encrypted data
|
|
110
|
+
const iv = combined.subarray(0, this.ivLength);
|
|
111
|
+
const authTag = combined.subarray(this.ivLength, this.ivLength + this.authTagLength);
|
|
112
|
+
const encrypted = combined.subarray(this.ivLength + this.authTagLength);
|
|
113
|
+
const decipher = crypto.createDecipheriv(this.algorithm, key, iv);
|
|
114
|
+
decipher.setAuthTag(authTag);
|
|
115
|
+
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
116
|
+
return decrypted.toString("utf8");
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Verify that the encryption system is properly configured.
|
|
120
|
+
* Performs a round-trip encryption/decryption test.
|
|
121
|
+
*
|
|
122
|
+
* @returns true if encryption is working correctly
|
|
123
|
+
* @throws Error if encryption is not properly configured
|
|
124
|
+
*/
|
|
125
|
+
verify() {
|
|
126
|
+
const testData = "test-secret-" + crypto.randomBytes(8).toString("hex");
|
|
127
|
+
const encrypted = this.encrypt(testData);
|
|
128
|
+
const decrypted = this.decrypt(encrypted);
|
|
129
|
+
return decrypted === testData;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
exports.TotpEncryptionService = TotpEncryptionService;
|
|
133
|
+
exports.TotpEncryptionService = TotpEncryptionService = __decorate([
|
|
134
|
+
(0, common_1.Injectable)()
|
|
135
|
+
], TotpEncryptionService);
|
|
136
|
+
//# sourceMappingURL=totp-encryption.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"totp-encryption.service.js","sourceRoot":"","sources":["../../../../src/foundations/two-factor/services/totp-encryption.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAAiC;AACjC,6DAAyD;AAEzD;;;;;;;GAOG;AAEI,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAA3B;QACY,cAAS,GAAG,aAAa,CAAC;QAC1B,aAAQ,GAAG,EAAE,CAAC,CAAC,kBAAkB;QACjC,kBAAa,GAAG,EAAE,CAAC,CAAC,WAAW;IAwFlD,CAAC;IAtFC;;;OAGG;IACK,MAAM;QACZ,MAAM,SAAS,GAAG,wBAAU,CAAC,SAAS,CAAC,iBAAiB,CAAC;QAEzD,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;QAED,6DAA6D;QAC7D,IAAI,SAAS,CAAC,MAAM,KAAK,EAAE,IAAI,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAChE,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACvC,CAAC;QAED,+BAA+B;QAC/B,IAAI,SAAS,CAAC,MAAM,KAAK,EAAE,IAAI,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACvD,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YACjD,IAAI,OAAO,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;gBAC1B,OAAO,O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