@jmlq/auth 0.0.1-alpha.1 → 0.0.1-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +259 -306
- package/dist/application/dtos/index.d.ts +3 -0
- package/dist/application/dtos/index.js +19 -0
- package/dist/application/dtos/request/index.d.ts +4 -0
- package/dist/{src/application/dtos → application/dtos/request}/index.js +4 -4
- package/dist/{src/application/dtos/login.dto.d.ts → application/dtos/request/login.request.d.ts} +0 -4
- package/dist/application/dtos/request/logout.request.d.ts +3 -0
- package/dist/application/dtos/request/refresh-token.request.d.ts +3 -0
- package/dist/application/dtos/request/register-user.request.d.ts +6 -0
- package/dist/application/dtos/response/index.d.ts +4 -0
- package/dist/application/dtos/response/index.js +20 -0
- package/dist/application/dtos/response/login.response.d.ts +4 -0
- package/dist/{src/application/dtos/logout.dto.d.ts → application/dtos/response/logout.response.d.ts} +0 -3
- package/dist/{src/application/dtos/refresh-token.dto.d.ts → application/dtos/response/refresh-token.response.d.ts} +0 -3
- package/dist/application/dtos/response/register-user.response.d.ts +7 -0
- package/dist/application/dtos/type/index.d.ts +1 -0
- package/dist/{src/shared/constants → application/dtos/type}/index.js +1 -1
- package/dist/application/dtos/type/user-role.type.d.ts +4 -0
- package/dist/application/factories/auth-service.factory.d.ts +11 -0
- package/dist/application/factories/auth-service.factory.js +40 -0
- package/dist/{src/application → application}/index.d.ts +1 -0
- package/dist/{src/application → application}/index.js +1 -0
- package/dist/application/types/auth-service-factory-options.type.d.ts +5 -0
- package/dist/application/types/index.d.ts +1 -0
- package/dist/{src/infrastructure/jwt/factory → application/types}/index.js +1 -1
- package/dist/{src/application → application}/use-cases/login-with-password.use-case.d.ts +2 -2
- package/dist/{src/application → application}/use-cases/login-with-password.use-case.js +6 -5
- package/dist/{src/application → application}/use-cases/logout.use-case.d.ts +2 -2
- package/dist/{src/application → application}/use-cases/logout.use-case.js +2 -2
- package/dist/{src/application → application}/use-cases/refresh-token.use-case.d.ts +2 -2
- package/dist/{src/application → application}/use-cases/refresh-token.use-case.js +2 -2
- package/dist/application/use-cases/register-user.use-case.d.ts +12 -0
- package/dist/{src/application → application}/use-cases/register-user.use-case.js +27 -1
- package/dist/{src/domain → domain}/errors/auth.errors.d.ts +1 -14
- package/dist/{src/domain → domain}/errors/auth.errors.js +1 -15
- package/dist/{src/domain → domain}/index.d.ts +0 -1
- package/dist/{src/domain → domain}/index.js +0 -1
- package/dist/domain/ports/auth/index.d.ts +2 -0
- package/dist/domain/ports/auth/index.js +18 -0
- package/dist/{src/domain/ports/auth/password-hasher.d.ts → domain/ports/auth/password-hasher.port.d.ts} +1 -1
- package/dist/{src/domain → domain}/ports/auth/password-policy.port.d.ts +1 -1
- package/dist/domain/ports/index.d.ts +4 -0
- package/dist/{src/infrastructure/jwt → domain/ports}/index.js +3 -2
- package/dist/domain/ports/jwt/index.d.ts +1 -0
- package/dist/{src/shared/types → domain/ports/jwt}/index.js +1 -1
- package/dist/domain/ports/jwt/payload/index.d.ts +1 -0
- package/dist/domain/ports/jwt/payload/index.js +17 -0
- package/dist/{src/domain → domain}/ports/repository/credential.repository.d.ts +1 -1
- package/dist/{src/domain → domain}/ports/repository/index.d.ts +1 -1
- package/dist/{src/domain → domain}/ports/repository/index.js +1 -1
- package/dist/{src/domain/ports/repository/user.repository.d.ts → domain/ports/repository/user-repository.port.d.ts} +1 -1
- package/dist/domain/ports/token/index.d.ts +2 -0
- package/dist/domain/ports/token/index.js +18 -0
- package/dist/{src/domain → domain}/ports/token/token-session.port.d.ts +2 -2
- package/dist/{src/domain → domain}/ports/token/token.service.port.d.ts +2 -2
- package/dist/{src/domain → domain}/props/jwt/generate-access-token.props.d.ts +0 -2
- package/dist/{src/domain → domain}/props/jwt/generate-refresh-token.props.d.ts +0 -2
- package/dist/{src/domain/props/services → domain/props/jwt}/index.d.ts +1 -0
- package/dist/{src/domain/props/services → domain/props/jwt}/index.js +1 -0
- package/dist/{src/domain → domain}/services/password-policy.service.d.ts +2 -2
- package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-credential.repository.d.ts +2 -2
- package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-credential.repository.js +12 -2
- package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-user.repository.d.ts +2 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.js +11 -1
- package/dist/infrastructure/index.js +1 -0
- package/dist/{src/infrastructure → infrastructure}/security/bcrypt-password-hasher.d.ts +7 -2
- package/dist/{src/infrastructure → infrastructure}/security/bcrypt-password-hasher.js +7 -2
- package/dist/{src/infrastructure → infrastructure}/services/index.d.ts +0 -1
- package/dist/{src/infrastructure → infrastructure}/services/index.js +0 -1
- package/dist/infrastructure/services/token-session.service.d.ts +22 -0
- package/dist/{src/infrastructure/services/default-token-session.service.js → infrastructure/services/token-session.service.js} +30 -31
- package/dist/infrastructure/types/auth-service-container.d.ts +14 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/{src/infrastructure/repositories → shared}/index.js +1 -1
- package/package.json +5 -8
- package/dist/examples/bcrypt-password-hasher.example.d.ts +0 -3
- package/dist/examples/bcrypt-password-hasher.example.js +0 -78
- package/dist/examples/entity-object.example.d.ts +0 -39
- package/dist/examples/entity-object.example.js +0 -411
- package/dist/examples/factory-auth-service-example.d.ts +0 -3
- package/dist/examples/factory-auth-service-example.js +0 -84
- package/dist/examples/index.example.d.ts +0 -12
- package/dist/examples/index.example.js +0 -171
- package/dist/examples/jwt-algoritm.example.d.ts +0 -47
- package/dist/examples/jwt-algoritm.example.js +0 -447
- package/dist/examples/jwt-token-generator.example.d.ts +0 -6
- package/dist/examples/jwt-token-generator.example.js +0 -49
- package/dist/examples/jwt-verifier.example.d.ts +0 -3
- package/dist/examples/jwt-verifier.example.js +0 -80
- package/dist/examples/password-policy.example.d.ts +0 -7
- package/dist/examples/password-policy.example.js +0 -57
- package/dist/examples/service-jwt-token.example.d.ts +0 -3
- package/dist/examples/service-jwt-token.example.js +0 -154
- package/dist/examples/service-token-session.example.d.ts +0 -3
- package/dist/examples/service-token-session.example.js +0 -139
- package/dist/examples/use-case-login-with-password.example.d.ts +0 -6
- package/dist/examples/use-case-login-with-password.example.js +0 -105
- package/dist/examples/use-case-logout.example.d.ts +0 -7
- package/dist/examples/use-case-logout.example.js +0 -134
- package/dist/examples/use-case-refresh-token.example.d.ts +0 -11
- package/dist/examples/use-case-refresh-token.example.js +0 -164
- package/dist/examples/use-case-register-user.example.d.ts +0 -9
- package/dist/examples/use-case-register-user.example.js +0 -110
- package/dist/src/application/dtos/index.d.ts +0 -4
- package/dist/src/application/dtos/register-user.dto.d.ts +0 -16
- package/dist/src/application/factories/auth-service.factory.d.ts +0 -5
- package/dist/src/application/factories/auth-service.factory.js +0 -51
- package/dist/src/application/use-cases/register-user.use-case.d.ts +0 -10
- package/dist/src/domain/errors/auth-domain-error.d.ts +0 -82
- package/dist/src/domain/errors/auth-domain-error.js +0 -112
- package/dist/src/domain/ports/auth/password-policy-config.port.js +0 -10
- package/dist/src/domain/ports/config/auth-config.port.d.ts +0 -19
- package/dist/src/domain/ports/config/auth-config.port.js +0 -3
- package/dist/src/domain/ports/index.d.ts +0 -9
- package/dist/src/domain/ports/index.js +0 -25
- package/dist/src/domain/ports/jwt/factory/signature-strategy-factory.port.d.ts +0 -14
- package/dist/src/domain/ports/jwt/signature-strategy-factory.port.d.ts +0 -14
- package/dist/src/domain/ports/jwt/signature-strategy.d.ts +0 -30
- package/dist/src/domain/ports/jwt/signature-strategy.js +0 -4
- package/dist/src/domain/ports/jwt/signature-strategy.port.d.ts +0 -31
- package/dist/src/domain/ports/jwt/signature-strategy.port.js +0 -4
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.d.ts +0 -31
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.js +0 -4
- package/dist/src/domain/props/create-payload-props.port.d.ts +0 -0
- package/dist/src/domain/props/create-payload-props.port.js +0 -8
- package/dist/src/domain/props/jwt/create-payload.props.d.ts +0 -9
- package/dist/src/domain/props/jwt/generate-token.props.d.ts +0 -10
- package/dist/src/domain/props/jwt/generate-token.props.js +0 -2
- package/dist/src/domain/props/jwt/index.d.ts +0 -5
- package/dist/src/domain/props/jwt/index.js +0 -21
- package/dist/src/domain/props/jwt/jwt-subject.d.ts +0 -7
- package/dist/src/domain/props/jwt/jwt-subject.js +0 -2
- package/dist/src/domain/props/services/generate-access-token.props.d.ts +0 -8
- package/dist/src/domain/props/services/generate-refresh-token.props.d.ts +0 -8
- package/dist/src/domain/services/token.service.port.d.ts +0 -9
- package/dist/src/index.d.ts +0 -78
- package/dist/src/index.js +0 -94
- package/dist/src/infrastructure/index.d.ts +0 -5
- package/dist/src/infrastructure/index.js +0 -21
- package/dist/src/infrastructure/jwt/factory/index.d.ts +0 -1
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.d.ts +0 -21
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.js +0 -61
- package/dist/src/infrastructure/jwt/index.d.ts +0 -3
- package/dist/src/infrastructure/jwt/signature-strategy.factory.d.ts +0 -21
- package/dist/src/infrastructure/jwt/signature-strategy.factory.js +0 -61
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.js +0 -124
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.js +0 -124
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.d.ts +0 -54
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.js +0 -129
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.d.ts +0 -54
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.js +0 -129
- package/dist/src/infrastructure/jwt/strategies/index.d.ts +0 -3
- package/dist/src/infrastructure/jwt/strategies/index.js +0 -19
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.js +0 -124
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.js +0 -124
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.d.ts +0 -57
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.js +0 -123
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.d.ts +0 -59
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.js +0 -100
- package/dist/src/infrastructure/jwt/token/index.d.ts +0 -5
- package/dist/src/infrastructure/jwt/token/index.js +0 -21
- package/dist/src/infrastructure/jwt/token/jwt-signer.d.ts +0 -33
- package/dist/src/infrastructure/jwt/token/jwt-signer.js +0 -46
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.d.ts +0 -29
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.js +0 -57
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.d.ts +0 -32
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.js +0 -77
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.d.ts +0 -33
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.js +0 -46
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.d.ts +0 -30
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.js +0 -57
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.d.ts +0 -32
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.js +0 -77
- package/dist/src/infrastructure/repositories/index.d.ts +0 -1
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.d.ts +0 -67
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.js +0 -128
- package/dist/src/infrastructure/services/default-token-session.service.d.ts +0 -18
- package/dist/src/infrastructure/services/jwt-token.service.d.ts +0 -15
- package/dist/src/infrastructure/services/jwt-token.service.js +0 -44
- package/dist/src/infrastructure/services/simple-jwt-token.service.d.ts +0 -15
- package/dist/src/infrastructure/services/simple-jwt-token.service.js +0 -46
- package/dist/src/infrastructure/services/token-session.service.d.ts +0 -24
- package/dist/src/infrastructure/services/token-session.service.js +0 -131
- package/dist/src/infrastructure/types/auth-service-container.d.ts +0 -14
- package/dist/src/shared/constants/index.d.ts +0 -1
- package/dist/src/shared/constants/jwt-algorithms.d.ts +0 -17
- package/dist/src/shared/constants/jwt-algorithms.js +0 -23
- package/dist/src/shared/encoders/base64-url-encoder.d.ts +0 -29
- package/dist/src/shared/encoders/base64-url-encoder.js +0 -45
- package/dist/src/shared/encoders/index.d.ts +0 -1
- package/dist/src/shared/encoders/index.js +0 -17
- package/dist/src/shared/index.d.ts +0 -4
- package/dist/src/shared/index.js +0 -20
- package/dist/src/shared/types/index.d.ts +0 -1
- package/dist/src/shared/types/jwt.d.ts +0 -25
- package/dist/src/shared/types/jwt.js +0 -2
- package/dist/src/shared/types/jwt.types.d.ts +0 -39
- package/dist/src/shared/types/jwt.types.js +0 -2
- package/dist/tests/application/factory/auth-service-factory.spec.d.ts +0 -1
- package/dist/tests/application/factory/auth-service-factory.spec.js +0 -97
- package/dist/tests/application/use-cases/login-with-password.integration.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/login-with-password.integration.spec.js +0 -140
- package/dist/tests/application/use-cases/logout-use-case.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/logout-use-case.spec.js +0 -40
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.js +0 -116
- package/dist/tests/application/use-cases/register-user.usecase.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/register-user.usecase.spec.js +0 -151
- package/dist/tests/domain/entities/credential.spec.d.ts +0 -1
- package/dist/tests/domain/entities/credential.spec.js +0 -93
- package/dist/tests/domain/entities/user.spec.d.ts +0 -1
- package/dist/tests/domain/entities/user.spec.js +0 -93
- package/dist/tests/domain/object-values/email.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/email.spec.js +0 -77
- package/dist/tests/domain/object-values/hashed-password.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/hashed-password.spec.js +0 -54
- package/dist/tests/domain/object-values/id.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/id.spec.js +0 -48
- package/dist/tests/domain/object-values/permission.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/permission.spec.js +0 -75
- package/dist/tests/domain/object-values/role.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/role.spec.js +0 -139
- package/dist/tests/domain/services/default-password-policy.spec.d.ts +0 -1
- package/dist/tests/domain/services/default-password-policy.spec.js +0 -69
- package/dist/tests/doman/entities/credential.spec.d.ts +0 -1
- package/dist/tests/doman/entities/credential.spec.js +0 -93
- package/dist/tests/doman/entities/user.spec.d.ts +0 -1
- package/dist/tests/doman/entities/user.spec.js +0 -93
- package/dist/tests/doman/object-values/email.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/email.spec.js +0 -77
- package/dist/tests/doman/object-values/hashed-password.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/hashed-password.spec.js +0 -54
- package/dist/tests/doman/object-values/id.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/id.spec.js +0 -48
- package/dist/tests/doman/object-values/permission.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/permission.spec.js +0 -75
- package/dist/tests/doman/object-values/role.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/role.spec.js +0 -139
- package/dist/tests/helpers/make-jwt-subject.d.ts +0 -7
- package/dist/tests/helpers/make-jwt-subject.js +0 -16
- package/dist/tests/helpers/make-jwt-user.d.ts +0 -7
- package/dist/tests/helpers/make-jwt-user.js +0 -16
- package/dist/tests/helpers/make-user.d.ts +0 -2
- package/dist/tests/helpers/make-user.js +0 -15
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.js +0 -127
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.js +0 -157
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.js +0 -150
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.js +0 -156
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.js +0 -179
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.js +0 -142
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.js +0 -125
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.js +0 -116
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.js +0 -88
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.js +0 -126
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.js +0 -116
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.js +0 -88
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.d.ts +0 -1
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.js +0 -37
- package/dist/tests/infrastructure/services/jwt-token-service.spec.d.ts +0 -1
- package/dist/tests/infrastructure/services/jwt-token-service.spec.js +0 -145
- package/dist/tests/infrastructure/services/token-session.service.spec.d.ts +0 -1
- package/dist/tests/infrastructure/services/token-session.service.spec.js +0 -269
- package/dist/tests/shared/constants/jwt-algorithms.spec.d.ts +0 -1
- package/dist/tests/shared/constants/jwt-algorithms.spec.js +0 -27
- package/dist/tests/shared/encoders/base64-url-encoder.spec.d.ts +0 -1
- package/dist/tests/shared/encoders/base64-url-encoder.spec.js +0 -70
- package/dist/tests/shared/utils/time-parser.spec.d.ts +0 -1
- package/dist/tests/shared/utils/time-parser.spec.js +0 -80
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -17
- package/dist/utils/time-parser.d.ts +0 -28
- package/dist/utils/time-parser.js +0 -76
- /package/dist/{src/application/dtos/login.dto.js → application/dtos/request/login.request.js} +0 -0
- /package/dist/{src/application/dtos/logout.dto.js → application/dtos/request/logout.request.js} +0 -0
- /package/dist/{src/application/dtos/refresh-token.dto.js → application/dtos/request/refresh-token.request.js} +0 -0
- /package/dist/{src/application/dtos/register-user.dto.js → application/dtos/request/register-user.request.js} +0 -0
- /package/dist/{src/domain/ports/auth/password-hasher.js → application/dtos/response/login.response.js} +0 -0
- /package/dist/{src/domain/ports/auth/password-policy.port.js → application/dtos/response/logout.response.js} +0 -0
- /package/dist/{src/domain/ports/jwt/factory/signature-strategy-factory.port.js → application/dtos/response/refresh-token.response.js} +0 -0
- /package/dist/{src/domain/ports/jwt/payload/jwt-payload.port.js → application/dtos/response/register-user.response.js} +0 -0
- /package/dist/{src/domain/ports/jwt/signature-strategy-factory.port.js → application/dtos/type/user-role.type.js} +0 -0
- /package/dist/{src/application → application}/factories/index.d.ts +0 -0
- /package/dist/{src/application → application}/factories/index.js +0 -0
- /package/dist/{src/domain/ports/repository/credential.repository.js → application/types/auth-service-factory-options.type.js} +0 -0
- /package/dist/{src/application → application}/use-cases/index.d.ts +0 -0
- /package/dist/{src/application → application}/use-cases/index.js +0 -0
- /package/dist/{src/domain → domain}/entities/credential.entity.d.ts +0 -0
- /package/dist/{src/domain → domain}/entities/credential.entity.js +0 -0
- /package/dist/{src/domain → domain}/entities/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/entities/index.js +0 -0
- /package/dist/{src/domain → domain}/entities/user.entity.d.ts +0 -0
- /package/dist/{src/domain → domain}/entities/user.entity.js +0 -0
- /package/dist/{src/domain → domain}/errors/identity.errors.d.ts +0 -0
- /package/dist/{src/domain → domain}/errors/identity.errors.js +0 -0
- /package/dist/{src/domain → domain}/errors/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/errors/index.js +0 -0
- /package/dist/{src/domain → domain}/object-values/email.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/email.js +0 -0
- /package/dist/{src/domain → domain}/object-values/hashed-password.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/hashed-password.js +0 -0
- /package/dist/{src/domain → domain}/object-values/id.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/id.js +0 -0
- /package/dist/{src/domain → domain}/object-values/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/index.js +0 -0
- /package/dist/{src/domain → domain}/object-values/permission.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/permission.js +0 -0
- /package/dist/{src/domain → domain}/object-values/role.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/role.js +0 -0
- /package/dist/{src/domain/ports/repository/user.repository.js → domain/ports/auth/password-hasher.port.js} +0 -0
- /package/dist/{src/domain/ports/token/token-session.port.js → domain/ports/auth/password-policy.port.js} +0 -0
- /package/dist/{src/domain → domain}/ports/jwt/payload/jwt-payload.port.d.ts +0 -0
- /package/dist/{src/domain/ports/token/token.service.port.js → domain/ports/jwt/payload/jwt-payload.port.js} +0 -0
- /package/dist/{src/domain/props/entities/credential.props.js → domain/ports/repository/credential.repository.js} +0 -0
- /package/dist/{src/domain/props/entities/user.props.js → domain/ports/repository/user-repository.port.js} +0 -0
- /package/dist/{src/domain/props/jwt/create-payload.props.js → domain/ports/token/token-session.port.js} +0 -0
- /package/dist/{src/domain/services → domain/ports/token}/token.service.port.js +0 -0
- /package/dist/{src/domain → domain}/props/entities/credential.props.d.ts +0 -0
- /package/dist/{src/domain/props/jwt/generate-access-token.props.js → domain/props/entities/credential.props.js} +0 -0
- /package/dist/{src/domain → domain}/props/entities/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/props/entities/index.js +0 -0
- /package/dist/{src/domain → domain}/props/entities/user.props.d.ts +0 -0
- /package/dist/{src/domain/props/jwt/generate-refresh-token.props.js → domain/props/entities/user.props.js} +0 -0
- /package/dist/{src/domain → domain}/props/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/props/index.js +0 -0
- /package/dist/{src/domain/props/services → domain/props/jwt}/generate-access-token.props.js +0 -0
- /package/dist/{src/domain/props/services → domain/props/jwt}/generate-refresh-token.props.js +0 -0
- /package/dist/{src/domain → domain}/props/jwt/jwt-user.d.ts +0 -0
- /package/dist/{src/domain → domain}/props/jwt/jwt-user.js +0 -0
- /package/dist/{src/domain → domain}/services/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/services/index.js +0 -0
- /package/dist/{src/domain → domain}/services/password-policy.service.js +0 -0
- /package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-user.repository.js +0 -0
- /package/dist/{src/infrastructure/repositories/test → in-memory}/index.d.ts +0 -0
- /package/dist/{src/infrastructure/repositories/test → in-memory}/index.js +0 -0
- /package/dist/{src/domain/ports/auth/password-policy-config.port.d.ts → infrastructure/index.d.ts} +0 -0
- /package/dist/{src/infrastructure → infrastructure}/security/index.d.ts +0 -0
- /package/dist/{src/infrastructure → infrastructure}/security/index.js +0 -0
- /package/dist/{src/infrastructure → infrastructure}/types/auth-service-container.js +0 -0
- /package/dist/{src/infrastructure → infrastructure}/types/index.d.ts +0 -0
- /package/dist/{src/infrastructure → infrastructure}/types/index.js +0 -0
- /package/dist/{src/shared → shared}/utils/index.d.ts +0 -0
- /package/dist/{src/shared → shared}/utils/index.js +0 -0
- /package/dist/{src/shared → shared}/utils/time-parser.d.ts +0 -0
- /package/dist/{src/shared → shared}/utils/time-parser.js +0 -0
package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-user.repository.d.ts
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Email, Id,
|
|
2
|
-
export declare class InMemoryUserRepository implements
|
|
1
|
+
import { Email, Id, IUserRepositoryPort, User } from "../domain";
|
|
2
|
+
export declare class InMemoryUserRepository implements IUserRepositoryPort {
|
|
3
3
|
private users;
|
|
4
4
|
save(user: User): Promise<void>;
|
|
5
5
|
findById(id: Id): Promise<User | null>;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// src/index.ts
|
|
2
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
4
|
if (k2 === undefined) k2 = k;
|
|
4
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -14,4 +15,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
16
|
};
|
|
16
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
+
// Entry point principal
|
|
19
|
+
__exportStar(require("./application/factories"), exports);
|
|
20
|
+
// Contratos (ports) + config
|
|
21
|
+
__exportStar(require("./domain/ports"), exports);
|
|
22
|
+
// Errores públicos
|
|
23
|
+
__exportStar(require("./domain/errors"), exports);
|
|
24
|
+
// DTOs (solo types)
|
|
25
|
+
__exportStar(require("./application/dtos"), exports);
|
|
26
|
+
// adapters útiles para tests/demos
|
|
27
|
+
// export * from "./infrastructure/repositories/in-memory";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { IPasswordHasherPort } from "../../domain/ports";
|
|
2
|
+
/**
|
|
3
|
+
* Hasher bcrypt configurable.
|
|
4
|
+
* Evita hardcode de rounds para que sea controlable por config.
|
|
5
|
+
*/
|
|
6
|
+
export declare class BcryptPasswordHasher implements IPasswordHasherPort {
|
|
3
7
|
private readonly saltRounds;
|
|
8
|
+
constructor(saltRounds?: number);
|
|
4
9
|
hash(password: string): Promise<string>;
|
|
5
10
|
compare(plainPassword: string, hashedPassword: string): Promise<boolean>;
|
|
6
11
|
}
|
|
@@ -4,10 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BcryptPasswordHasher = void 0;
|
|
7
|
+
// src/infrastructure/security/bcrypt-password-hasher.ts
|
|
7
8
|
const bcryptjs_1 = __importDefault(require("bcryptjs"));
|
|
9
|
+
/**
|
|
10
|
+
* Hasher bcrypt configurable.
|
|
11
|
+
* Evita hardcode de rounds para que sea controlable por config.
|
|
12
|
+
*/
|
|
8
13
|
class BcryptPasswordHasher {
|
|
9
|
-
constructor() {
|
|
10
|
-
this.saltRounds =
|
|
14
|
+
constructor(saltRounds = 10) {
|
|
15
|
+
this.saltRounds = saltRounds;
|
|
11
16
|
}
|
|
12
17
|
async hash(password) {
|
|
13
18
|
return bcryptjs_1.default.hash(password, this.saltRounds);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Credential, ICredentialRepositoryPort, ITokenServicePort, ITokenSessionPort, IUserRepositoryPort, User } from "../../domain";
|
|
2
|
+
/**
|
|
3
|
+
* Servicio de sesiones de usuario (rotación de refresh token).
|
|
4
|
+
*
|
|
5
|
+
* Este servicio NO debe conocer detalles crypto.
|
|
6
|
+
* Solo orquesta:
|
|
7
|
+
* - generación/verificación de tokens vía ITokenService
|
|
8
|
+
* - persistencia de credenciales
|
|
9
|
+
* - recuperación de usuario
|
|
10
|
+
*/
|
|
11
|
+
export declare class TokenSessionService implements ITokenSessionPort {
|
|
12
|
+
private readonly tokenService;
|
|
13
|
+
private readonly userRepository;
|
|
14
|
+
private readonly credentialRepository;
|
|
15
|
+
private readonly accessTokenExpiration;
|
|
16
|
+
private readonly refreshTokenExpiration;
|
|
17
|
+
constructor(tokenService: ITokenServicePort, userRepository: IUserRepositoryPort, credentialRepository: ICredentialRepositoryPort, accessTokenExpiration?: string, refreshTokenExpiration?: string);
|
|
18
|
+
createSession(user: User): Promise<Credential>;
|
|
19
|
+
refreshSession(refreshToken: string): Promise<Credential>;
|
|
20
|
+
validateSession(accessToken: string): Promise<User | null>;
|
|
21
|
+
revokeSession(refreshToken: string): Promise<void>;
|
|
22
|
+
}
|
|
@@ -1,62 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TokenSessionService = void 0;
|
|
4
|
+
// src/infrastructure/services/token-session.service.ts
|
|
4
5
|
const domain_1 = require("../../domain");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Servicio de sesiones de usuario (rotación de refresh token).
|
|
8
|
+
*
|
|
9
|
+
* Este servicio NO debe conocer detalles crypto.
|
|
10
|
+
* Solo orquesta:
|
|
11
|
+
* - generación/verificación de tokens vía ITokenService
|
|
12
|
+
* - persistencia de credenciales
|
|
13
|
+
* - recuperación de usuario
|
|
14
|
+
*/
|
|
15
|
+
class TokenSessionService {
|
|
16
|
+
constructor(tokenService, userRepository, credentialRepository,
|
|
17
|
+
// Expiraciones humanas opcionales (si las quieres como string)
|
|
18
|
+
accessTokenExpiration = "15m", refreshTokenExpiration = "7d") {
|
|
8
19
|
this.tokenService = tokenService;
|
|
9
20
|
this.userRepository = userRepository;
|
|
10
21
|
this.credentialRepository = credentialRepository;
|
|
11
22
|
this.accessTokenExpiration = accessTokenExpiration;
|
|
12
23
|
this.refreshTokenExpiration = refreshTokenExpiration;
|
|
13
|
-
this.accessTokenSecret = accessTokenSecret;
|
|
14
|
-
this.refreshTokenSecret = refreshTokenSecret;
|
|
15
|
-
try {
|
|
16
|
-
this.accessMs = shared_1.TimeParser.parseToMilliseconds(accessTokenExpiration);
|
|
17
|
-
this.refreshMs = shared_1.TimeParser.parseToMilliseconds(refreshTokenExpiration);
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
throw new Error(`Invalid token expiration configuration: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
buildJwtConfig() {
|
|
24
|
-
return {
|
|
25
|
-
accessTokenExpirationMs: this.accessMs,
|
|
26
|
-
refreshTokenExpirationMs: this.refreshMs,
|
|
27
|
-
accessTokenSecret: this.accessTokenSecret,
|
|
28
|
-
refreshTokenSecret: this.refreshTokenSecret,
|
|
29
|
-
};
|
|
30
24
|
}
|
|
25
|
+
// Crear una nueva sesión
|
|
31
26
|
async createSession(user) {
|
|
32
|
-
const config = this.buildJwtConfig();
|
|
33
27
|
const accessToken = await this.tokenService.generateAccessToken({
|
|
34
28
|
user: {
|
|
35
29
|
id: user.id.toString(),
|
|
36
30
|
email: user.email.toString(),
|
|
37
|
-
roles: user.roles.map((
|
|
31
|
+
roles: user.roles.map((r) => r.getValuePublic()),
|
|
38
32
|
},
|
|
39
33
|
expiresIn: this.accessTokenExpiration,
|
|
40
|
-
config,
|
|
41
34
|
});
|
|
42
35
|
const refreshToken = await this.tokenService.generateRefreshToken({
|
|
43
36
|
user: {
|
|
44
37
|
id: user.id.toString(),
|
|
45
38
|
email: user.email.toString(),
|
|
46
|
-
roles: user.roles.map((
|
|
39
|
+
roles: user.roles.map((r) => r.getValuePublic()),
|
|
47
40
|
},
|
|
48
41
|
expiresIn: this.refreshTokenExpiration,
|
|
49
|
-
config,
|
|
50
42
|
});
|
|
51
|
-
|
|
43
|
+
// Obtener expiración desde el token (más robusto)
|
|
44
|
+
const expiresAt = await this.tokenService.getTokenExpiration(accessToken);
|
|
45
|
+
const credential = domain_1.Credential.create(user.id, accessToken, refreshToken, expiresAt);
|
|
52
46
|
await this.credentialRepository.save(credential);
|
|
53
47
|
return credential;
|
|
54
48
|
}
|
|
49
|
+
// Rotación de refresh token
|
|
55
50
|
async refreshSession(refreshToken) {
|
|
56
51
|
const existing = await this.credentialRepository.findByRefreshToken(refreshToken);
|
|
57
|
-
if (!existing)
|
|
52
|
+
if (!existing)
|
|
58
53
|
throw new domain_1.InvalidOrExpiredRefreshTokenError();
|
|
59
|
-
|
|
54
|
+
// Verifica refresh token (firma + exp + issuer/aud si están configurados)
|
|
60
55
|
const payload = await this.tokenService
|
|
61
56
|
.verifyRefreshToken(refreshToken)
|
|
62
57
|
.catch(() => {
|
|
@@ -67,10 +62,13 @@ class DefaultTokenSessionService {
|
|
|
67
62
|
throw new domain_1.UserNotFoundError();
|
|
68
63
|
if (!user.canLogin())
|
|
69
64
|
throw new domain_1.UserDisabledError();
|
|
65
|
+
// Crea nueva sesión
|
|
70
66
|
const newCredential = await this.createSession(user);
|
|
71
|
-
|
|
67
|
+
// Borra credencial anterior (rotación)
|
|
68
|
+
await this.credentialRepository.deleteByRefreshToken(refreshToken);
|
|
72
69
|
return newCredential;
|
|
73
70
|
}
|
|
71
|
+
// Validación de sesión via access token
|
|
74
72
|
async validateSession(accessToken) {
|
|
75
73
|
try {
|
|
76
74
|
const payload = await this.tokenService.verifyAccessToken(accessToken);
|
|
@@ -81,8 +79,9 @@ class DefaultTokenSessionService {
|
|
|
81
79
|
return null;
|
|
82
80
|
}
|
|
83
81
|
}
|
|
82
|
+
// Revocar sesión por refresh token
|
|
84
83
|
async revokeSession(refreshToken) {
|
|
85
84
|
await this.credentialRepository.deleteByRefreshToken(refreshToken);
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
|
-
exports.
|
|
87
|
+
exports.TokenSessionService = TokenSessionService;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ICredentialRepositoryPort, IPasswordHasherPort, IPasswordPolicyPort, ITokenServicePort, ITokenSessionPort, IUserRepositoryPort } from "../../domain/ports";
|
|
2
|
+
import { LoginWithPasswordUseCase, LogoutUseCase, RefreshTokenUseCase, RegisterUserUseCase } from "../../application/use-cases";
|
|
3
|
+
export interface IAuthServiceContainer {
|
|
4
|
+
userRepository: IUserRepositoryPort;
|
|
5
|
+
credentialRepository: ICredentialRepositoryPort;
|
|
6
|
+
passwordHasher: IPasswordHasherPort;
|
|
7
|
+
tokenService: ITokenServicePort;
|
|
8
|
+
passwordPolicy: IPasswordPolicyPort;
|
|
9
|
+
tokenSession: ITokenSessionPort;
|
|
10
|
+
registerUserUseCase: RegisterUserUseCase;
|
|
11
|
+
loginWithPasswordUseCase: LoginWithPasswordUseCase;
|
|
12
|
+
refreshTokenUseCase: RefreshTokenUseCase;
|
|
13
|
+
logoutUseCase: LogoutUseCase;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./utils";
|
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./utils"), exports);
|
package/package.json
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jmlq/auth",
|
|
3
3
|
"description": "JWT authentication package with clean architecture",
|
|
4
|
-
"version": "0.0.1-alpha.
|
|
4
|
+
"version": "0.0.1-alpha.2",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"
|
|
8
|
+
"dev": "rimraf dist && mkdir dist && tsc -p tsconfig.json",
|
|
9
|
+
"build": "rimraf dist && mkdir dist && tsc -p tsconfig.build.json",
|
|
9
10
|
"prepublishOnly": "npm run build",
|
|
10
11
|
"test": "jest --passWithNoTests",
|
|
11
12
|
"test:watch": "jest --watch",
|
|
12
13
|
"test:coverage": "jest --coverage",
|
|
13
14
|
"example:help": "tsx examples/index.example.ts help",
|
|
14
15
|
"example:all": "tsx examples/index.example.ts",
|
|
15
|
-
"example:jwt": "tsx examples/index.example.ts jwt",
|
|
16
|
-
"example:entity": "tsx examples/index.example.ts entity",
|
|
17
|
-
"example:generate-token": "tsx examples/index.example.ts generate-token",
|
|
18
|
-
"example:validate-token": "tsx examples/index.example.ts validate-token",
|
|
19
|
-
"example:validate-password": "tsx examples/index.example.ts validate-password",
|
|
20
16
|
"example:use-cases": "tsx examples/index.example.ts use-cases",
|
|
21
17
|
"example:services": "tsx examples/index.example.ts services",
|
|
22
18
|
"example:factories": "tsx examples/index.example.ts factories"
|
|
@@ -30,7 +26,8 @@
|
|
|
30
26
|
"author": "MLahuasi",
|
|
31
27
|
"license": "MIT",
|
|
32
28
|
"dependencies": {
|
|
33
|
-
"bcryptjs": "^2.4.3"
|
|
29
|
+
"bcryptjs": "^2.4.3",
|
|
30
|
+
"rimraf": "^6.1.2"
|
|
34
31
|
},
|
|
35
32
|
"devDependencies": {
|
|
36
33
|
"@swc/core": "^1.3.95",
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BcryptPasswordHasherExample = void 0;
|
|
4
|
-
const bcrypt_password_hasher_1 = require("../src/infrastructure/security/bcrypt-password-hasher");
|
|
5
|
-
class BcryptPasswordHasherExample {
|
|
6
|
-
static async Main() {
|
|
7
|
-
console.log("=== 🔐 Ejemplo de uso: BcryptPasswordHasher ===\n");
|
|
8
|
-
// 1️⃣ Contraseñas de prueba
|
|
9
|
-
const realPassword = "MyStrongPass#123";
|
|
10
|
-
const wrongPassword = "NotTheRightPass!";
|
|
11
|
-
const anotherWrong = "123456";
|
|
12
|
-
console.log("🧾 Password real de prueba:", realPassword);
|
|
13
|
-
console.log("🧾 Password equivocada 1:", wrongPassword);
|
|
14
|
-
console.log("🧾 Password equivocada 2:", anotherWrong, "\n");
|
|
15
|
-
// 2️⃣ Instanciamos el hasher
|
|
16
|
-
const hasher = new bcrypt_password_hasher_1.BcryptPasswordHasher();
|
|
17
|
-
// 3️⃣ Generar hash bcrypt desde el password real
|
|
18
|
-
const hash = await hasher.hash(realPassword);
|
|
19
|
-
console.log("🔑 Hash generado (bcrypt):");
|
|
20
|
-
console.log(hash, "\n");
|
|
21
|
-
// 4️⃣ Verificar el hash con la contraseña correcta
|
|
22
|
-
const isValid = await hasher.compare(realPassword, hash);
|
|
23
|
-
console.log("✅ ¿La contraseña REAL coincide con el hash?");
|
|
24
|
-
console.log(" Resultado:", isValid, "\n");
|
|
25
|
-
// 5️⃣ Verificar el hash con contraseñas incorrectas
|
|
26
|
-
const isValidWrong1 = await hasher.compare(wrongPassword, hash);
|
|
27
|
-
const isValidWrong2 = await hasher.compare(anotherWrong, hash);
|
|
28
|
-
console.log("❌ ¿Una contraseña equivocada coincide con el hash?");
|
|
29
|
-
console.log(` "${wrongPassword}" ->`, isValidWrong1);
|
|
30
|
-
console.log(` "${anotherWrong}" ->`, isValidWrong2, "\n");
|
|
31
|
-
// 6️⃣ Demostrar que NO se puede obtener el password original desde el hash
|
|
32
|
-
console.log("=== 🔒 Demostración: el hash es unidireccional ===");
|
|
33
|
-
console.log("Intentando 'recuperar' la contraseña solo a partir del hash...\n");
|
|
34
|
-
console.log("⚠️ Importante: no existe ninguna función como hasher.reverse(hash).");
|
|
35
|
-
console.log("Solo podemos PROBAR contraseñas candidatas y comparar.\n");
|
|
36
|
-
// Simulamos un pequeño ataque por diccionario
|
|
37
|
-
const candidatePasswords = [
|
|
38
|
-
"password",
|
|
39
|
-
"admin",
|
|
40
|
-
"qwerty",
|
|
41
|
-
"123456",
|
|
42
|
-
wrongPassword,
|
|
43
|
-
anotherWrong,
|
|
44
|
-
// Nota: aquí a propósito NO incluimos realPassword
|
|
45
|
-
];
|
|
46
|
-
console.log("📚 Diccionario de prueba:");
|
|
47
|
-
console.log(candidatePasswords, "\n");
|
|
48
|
-
let recovered = null;
|
|
49
|
-
let attempts = 0;
|
|
50
|
-
for (const candidate of candidatePasswords) {
|
|
51
|
-
attempts++;
|
|
52
|
-
const matches = await hasher.compare(candidate, hash);
|
|
53
|
-
console.log(` 🔎 Probando candidato #${attempts}: "${candidate}" -> ${matches ? "COINCIDE" : "no coincide"}`);
|
|
54
|
-
if (matches) {
|
|
55
|
-
recovered = candidate;
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
console.log("");
|
|
60
|
-
if (recovered) {
|
|
61
|
-
console.log("⚠️ El diccionario CONTENÍA la contraseña real.");
|
|
62
|
-
console.log("Se pudo descubrir porque estaba en la lista de candidatos.\n");
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
console.log("✅ El diccionario NO contenía la contraseña real.");
|
|
66
|
-
console.log("No fue posible recuperar el valor original solo con el hash y este conjunto de candidatos.\n");
|
|
67
|
-
}
|
|
68
|
-
console.log("💡 Conclusión:");
|
|
69
|
-
console.log("- Bcrypt es una función de hash unidireccional: no se puede 'deshashear' para obtener el texto plano.");
|
|
70
|
-
console.log("- Lo único que se puede hacer es probar contraseñas candidatas con compare(password, hash).");
|
|
71
|
-
console.log("- Si la contraseña no está en el conjunto que pruebas (diccionario/fuerza bruta), no hay forma práctica de conocerla.");
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.BcryptPasswordHasherExample = BcryptPasswordHasherExample;
|
|
75
|
-
// Para ejecutar este ejemplo directamente con Node (compilado a JS):
|
|
76
|
-
// (async () => {
|
|
77
|
-
// await BcryptPasswordHasherExample.Main();
|
|
78
|
-
// })();
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export declare class EntityObjectExamples {
|
|
2
|
-
static Main(): Promise<void>;
|
|
3
|
-
/**
|
|
4
|
-
* Ejemplo demostrativo de uso de la clase Email.
|
|
5
|
-
* Muestra validaciones, comparaciones y manejo de errores.
|
|
6
|
-
*/
|
|
7
|
-
static RunEmailExample(): Promise<void>;
|
|
8
|
-
/**
|
|
9
|
-
* Ejemplo demostrativo de uso de la clase HashedPassword.
|
|
10
|
-
* Muestra validación de formato, comparación de hashes y manejo de errores.
|
|
11
|
-
*/
|
|
12
|
-
static RunHashedPasswordExample(): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* Ejemplo demostrativo de uso de la clase Id.
|
|
15
|
-
* Muestra generación, comparación e instanciación manual de identificadores.
|
|
16
|
-
*/
|
|
17
|
-
static RunIdExample(): Promise<void>;
|
|
18
|
-
/**
|
|
19
|
-
* Ejemplo demostrativo de uso de la clase Permission.
|
|
20
|
-
* Muestra creación, comparación, coincidencias y manejo de errores.
|
|
21
|
-
*/
|
|
22
|
-
static RunPermissionExample(): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Ejemplo demostrativo de uso de la clase Role.
|
|
25
|
-
* Muestra creación de roles, validación de roles permitidos, manejo de permisos,
|
|
26
|
-
* uso de comodines, y verificación de acciones específicas.
|
|
27
|
-
*/
|
|
28
|
-
static RunRoleExample(): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Ejemplo demostrativo de uso de la entidad User.
|
|
31
|
-
* Muestra la creación, activación, desactivación y verificación de login.
|
|
32
|
-
*/
|
|
33
|
-
static RunUserExample(): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Ejemplo demostrativo de uso de la entidad Credential.
|
|
36
|
-
* Muestra cómo crear, validar y reconstruir credenciales dentro del dominio.
|
|
37
|
-
*/
|
|
38
|
-
static RunCredentialExample(): Promise<void>;
|
|
39
|
-
}
|