33
loading...
This website collects cookies to deliver better user experience
# Gemfile.rb
gem 'lockbox'
bundle install
to complete your installation.It's very important to try this on your local machine first, then on a staging server, then finally on your production server, to avoid loss of (sometimes irrecoverable) data - @kudapara
rails console
and run the following code to generate the key that will be used to encrypt your records.Lockbox.generate_key
# "daa846ef907a5b44a6b83ac6991a9ff63126b869b2f97afc43d8329b46328abe"
lockbox:
master_key: daa846ef907a5b44a6b83ac6991a9ff63126b869b2f97afc43d8329b46328abe
config/initializers/lockbox.rb
with something likelockbox_master_key = Rails.application.credentials.lockbox[:master_key]
Lockbox.master_key = lockbox_master_key
lockbox_master_key
could be coming from rails credentials or a key management service like VaultProject.LOCKBOX_MASTER_KEY="daa846ef907a5b44a6b83ac6991a9ff63126b869b2f97afc43d8329b46328abe"
class AddSeedCiphertextToAccounts < ActiveRecord::Migration[6.1]
def change
add_column :accounts, :seed_ciphertext, :text
# add this line if you are encrypting an existing column
Lockbox.migrate(User)
end
end
class Account < ApplicationRecord
encrypts :seed, migrating: true
# for existing columns. remove this line after dropping seed column
self.ignored_columns = ["seed"]
end
migrating:true
. That is to ensure you encrypt an existing column without downtime. If you are adding a new sensitive column to your model, you can ignore it.class DropSeedFromAccounts < ActiveRecord::Migration[6.1]
def change
remove_column :accounts, :seed
end
end
current_user.accounts.create(address: blockchain_account.address, seed: blockchain_account.seed, account_type: 'regular')
Stellar::KeyPair.from_seed(current_user.accounts.regular.first.seed)
Thank you for reading, If you enjoyed this content you can donate some Stellar Lumens (XLM) or USDC to my stellar wallet