class Sequent::Core::Helpers::Secret

You can use this in Commands to handle for instance passwords safely. It uses BCrypt to encrypt the Secret.

Attributes that are of type Secret are encrypted after successful validation in the CommandService automatically. So there is no need to do this yourself, Sequent will take care of this for you. As a result the CommandHandlers will receive the encrypted values.

Since this is meant to be used in +Command+s based on input you can put in +String+s and +Secret+s.

Example usage:

class CreateUser < Sequent::Command
  attrs email: String, password: Sequent::Secret
end

command = CreateUser.new(
  aggregate_id: Sequent.new_uuid,
  email: 'ben@sequent.io',
  password: 'secret',
)

puts command.password
=> secret

command.valid?
=> true

command = command.parse_attrs_to_correct_types
puts command.password
=> SAasdf239as$%^@#%dasfgasasdf (or something similar :-))

When command validation fails attributes of type Sequent::Secret are cleared.

command.valid?
=> false

puts command.password
=> ''

There is no real need to use this type in Events since there we are only interested in the encrypted String at that point.

Besides the Sequent::Secret type there are also some helper methods available to assist in verifying secrets.

See encrypt_secret See re_encrypt_secret See verify_secret