Ready to migrate and encrypt

account
Никита Поздняков 2 years ago committed by Viktor Baranov
parent e1a2f54f81
commit 2fbb4ed1de
  1. 23
      apps/explorer/lib/encrypt.ex
  2. 14
      apps/explorer/lib/explorer/account/custom_abi.ex
  3. 32
      apps/explorer/lib/explorer/account/identity.ex
  4. 7
      apps/explorer/lib/explorer/account/public_tags_request.ex
  5. 12
      apps/explorer/lib/explorer/account/tag_address.ex
  6. 14
      apps/explorer/lib/explorer/account/tag_transaction.ex
  7. 15
      apps/explorer/lib/explorer/account/watchlist_address.ex
  8. 32
      apps/explorer/lib/explorer/account/watchlist_notification.ex
  9. 4
      apps/explorer/lib/explorer/third_party_integrations/airtable.ex
  10. 6
      apps/explorer/priv/account/migrations/20220706114430_encrypt_account_data.exs
  11. 9
      apps/explorer/priv/account/migrations/20220706153506_remove_unencrypted_fields.exs

@ -3,7 +3,17 @@ defmodule Mix.Tasks.Encrypt do
use Mix.Task use Mix.Task
alias Ecto.Changeset alias Ecto.Changeset
alias Explorer.Account.{CustomABI, Identity, TagAddress, TagTransaction, WatchlistAddress, WatchlistNotification}
alias Explorer.Account.{
CustomABI,
Identity,
PublicTagsRequest,
TagAddress,
TagTransaction,
WatchlistAddress,
WatchlistNotification
}
alias Explorer.Repo.Account alias Explorer.Repo.Account
alias Mix.Task alias Mix.Task
@ -91,5 +101,16 @@ defmodule Mix.Tasks.Encrypt do
}) })
|> Account.update!() |> Account.update!()
end) end)
PublicTagsRequest
|> Account.all()
|> Enum.each(fn element ->
element
|> Changeset.change(%{
encrypted_full_name: element.full_name,
encrypted_email: element.email
})
|> Account.update!()
end)
end end
end end

@ -8,7 +8,7 @@ defmodule Explorer.Account.CustomABI do
alias Ecto.Changeset alias Ecto.Changeset
alias Explorer.Account.Identity alias Explorer.Account.Identity
alias Explorer.{Chain, Repo} alias Explorer.{Chain, Repo}
# alias Explorer.Chain.Hash alias Explorer.Chain.Hash
import Explorer.Chain, only: [hash_to_lower_case_string: 1] import Explorer.Chain, only: [hash_to_lower_case_string: 1]
import Ecto.Changeset import Ecto.Changeset
@ -20,16 +20,16 @@ defmodule Explorer.Account.CustomABI do
field(:given_abi, :string, virtual: true) field(:given_abi, :string, virtual: true)
field(:abi_validating_error, :string, virtual: true) field(:abi_validating_error, :string, virtual: true)
# field(:name, :string) field(:name, :string)
# field(:address_hash, Hash.Address, null: false) field(:address_hash, Hash.Address, null: false)
# field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false) field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false)
# field(:encrypted_name, Explorer.Encrypted.Binary) field(:encrypted_name, Explorer.Encrypted.Binary)
field(:address_hash_hash, Cloak.Ecto.SHA256) field(:address_hash_hash, Cloak.Ecto.SHA256)
field(:address_hash, Explorer.Encrypted.AddressHash, null: false) # field(:address_hash, Explorer.Encrypted.AddressHash, null: false)
field(:name, Explorer.Encrypted.Binary) # field(:name, Explorer.Encrypted.Binary)
belongs_to(:identity, Identity) belongs_to(:identity, Identity)

@ -11,25 +11,25 @@ defmodule Explorer.Account.Identity do
alias Explorer.Account.{TagAddress, Watchlist} alias Explorer.Account.{TagAddress, Watchlist}
schema "account_identities" do schema "account_identities" do
# field(:uid, :string) field(:uid, :string)
# field(:email, :string) field(:email, :string)
# field(:name, :string) field(:name, :string)
# field(:nickname, :string) field(:nickname, :string)
# field(:avatar, :string) field(:avatar, :string)
# field(:encrypted_uid, Explorer.Encrypted.Binary) field(:encrypted_uid, Explorer.Encrypted.Binary)
# field(:encrypted_email, Explorer.Encrypted.Binary) field(:encrypted_email, Explorer.Encrypted.Binary)
# field(:encrypted_name, Explorer.Encrypted.Binary) field(:encrypted_name, Explorer.Encrypted.Binary)
# field(:encrypted_nickname, Explorer.Encrypted.Binary) field(:encrypted_nickname, Explorer.Encrypted.Binary)
# field(:encrypted_avatar, Explorer.Encrypted.Binary) field(:encrypted_avatar, Explorer.Encrypted.Binary)
field(:uid_hash, Cloak.Ecto.SHA256) field(:uid_hash, Cloak.Ecto.SHA256)
field(:uid, Explorer.Encrypted.Binary) # field(:uid, Explorer.Encrypted.Binary)
field(:email, Explorer.Encrypted.Binary) # field(:email, Explorer.Encrypted.Binary)
field(:name, Explorer.Encrypted.Binary) # field(:name, Explorer.Encrypted.Binary)
field(:nickname, Explorer.Encrypted.Binary) # field(:nickname, Explorer.Encrypted.Binary)
field(:avatar, Explorer.Encrypted.Binary) # field(:avatar, Explorer.Encrypted.Binary)
has_many(:tag_addresses, TagAddress) has_many(:tag_addresses, TagAddress)
has_many(:watchlists, Watchlist) has_many(:watchlists, Watchlist)

@ -22,6 +22,7 @@ defmodule Explorer.Account.PublicTagsRequest do
schema("account_public_tags_requests") do schema("account_public_tags_requests") do
field(:full_name, :string) field(:full_name, :string)
field(:email, :string) field(:email, :string)
field(:company, :string) field(:company, :string)
field(:website, :string) field(:website, :string)
field(:tags, :string) field(:tags, :string)
@ -33,6 +34,12 @@ defmodule Explorer.Account.PublicTagsRequest do
field(:remove_reason, :string) field(:remove_reason, :string)
field(:request_id, :string) field(:request_id, :string)
field(:encrypted_full_name, Explorer.Encrypted.Binary)
field(:encrypted_email, Explorer.Encrypted.Binary)
# field(:full_name, Explorer.Encrypted.Binary)
# field(:email, Explorer.Encrypted.Binary)
belongs_to(:identity, Identity) belongs_to(:identity, Identity)
timestamps() timestamps()

@ -17,15 +17,15 @@ defmodule Explorer.Account.TagAddress do
@max_tag_address_per_account 15 @max_tag_address_per_account 15
schema "account_tag_addresses" do schema "account_tag_addresses" do
# field(:name, :string) field(:name, :string)
# field(:address_hash, Hash.Address, null: false) field(:address_hash, Hash.Address, null: false)
# field(:encrypted_name, Explorer.Encrypted.Binary) field(:encrypted_name, Explorer.Encrypted.Binary)
# field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false) field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false)
field(:address_hash_hash, Cloak.Ecto.SHA256) field(:address_hash_hash, Cloak.Ecto.SHA256)
field(:name, Explorer.Encrypted.Binary) # field(:name, Explorer.Encrypted.Binary)
field(:address_hash, Explorer.Encrypted.AddressHash, null: false) # field(:address_hash, Explorer.Encrypted.AddressHash, null: false)
belongs_to(:identity, Identity) belongs_to(:identity, Identity)

@ -10,21 +10,21 @@ defmodule Explorer.Account.TagTransaction do
alias Ecto.Changeset alias Ecto.Changeset
alias Explorer.Account.Identity alias Explorer.Account.Identity
alias Explorer.{Chain, Repo} alias Explorer.{Chain, Repo}
# alias Explorer.Chain.Hash alias Explorer.Chain.Hash
import Explorer.Chain, only: [hash_to_lower_case_string: 1] import Explorer.Chain, only: [hash_to_lower_case_string: 1]
@max_tag_transaction_per_account 15 @max_tag_transaction_per_account 15
schema "account_tag_transactions" do schema "account_tag_transactions" do
# field(:name, :string) field(:name, :string)
# field(:tx_hash, Hash.Full, null: false) field(:tx_hash, Hash.Full, null: false)
# field(:encrypted_name, Explorer.Encrypted.Binary) field(:encrypted_name, Explorer.Encrypted.Binary)
# field(:encrypted_tx_hash, Explorer.Encrypted.TransactionHash, null: false) field(:encrypted_tx_hash, Explorer.Encrypted.TransactionHash, null: false)
field(:tx_hash_hash, Cloak.Ecto.SHA256) field(:tx_hash_hash, Cloak.Ecto.SHA256)
field(:name, Explorer.Encrypted.Binary) # field(:name, Explorer.Encrypted.Binary)
field(:tx_hash, Explorer.Encrypted.TransactionHash, null: false) # field(:tx_hash, Explorer.Encrypted.TransactionHash, null: false)
belongs_to(:identity, Identity) belongs_to(:identity, Identity)

@ -11,23 +11,22 @@ defmodule Explorer.Account.WatchlistAddress do
alias Explorer.Account.Notifier.ForbiddenAddress alias Explorer.Account.Notifier.ForbiddenAddress
alias Explorer.Account.Watchlist alias Explorer.Account.Watchlist
alias Explorer.{Chain, Repo} alias Explorer.{Chain, Repo}
alias Explorer.Chain.{Address, Wei} alias Explorer.Chain.{Address, Wei, Hash}
# , Hash
import Explorer.Chain, only: [hash_to_lower_case_string: 1] import Explorer.Chain, only: [hash_to_lower_case_string: 1]
@max_watchlist_addresses_per_account 10 @max_watchlist_addresses_per_account 10
schema "account_watchlist_addresses" do schema "account_watchlist_addresses" do
# field(:name, :string) field(:name, :string)
# field(:address_hash, Hash.Address, null: false) field(:address_hash, Hash.Address, null: false)
# field(:encrypted_name, Explorer.Encrypted.Binary) field(:encrypted_name, Explorer.Encrypted.Binary)
# field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false) field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false)
field(:address_hash_hash, Cloak.Ecto.SHA256) field(:address_hash_hash, Cloak.Ecto.SHA256)
field(:name, Explorer.Encrypted.Binary) # field(:name, Explorer.Encrypted.Binary)
field(:address_hash, Explorer.Encrypted.AddressHash, null: false) # field(:address_hash, Explorer.Encrypted.AddressHash, null: false)
belongs_to(:watchlist, Watchlist) belongs_to(:watchlist, Watchlist)

@ -10,7 +10,7 @@ defmodule Explorer.Account.WatchlistNotification do
alias Explorer.Account.WatchlistAddress alias Explorer.Account.WatchlistAddress
# alias Explorer.Chain.Hash alias Explorer.Chain.Hash
schema "account_watchlist_notifications" do schema "account_watchlist_notifications" do
field(:amount, :decimal) field(:amount, :decimal)
@ -21,30 +21,30 @@ defmodule Explorer.Account.WatchlistNotification do
field(:type, :string) field(:type, :string)
field(:viewed_at, :integer) field(:viewed_at, :integer)
# field(:name, :string) field(:name, :string)
# field(:subject, :string) field(:subject, :string)
# field(:encrypted_name, Explorer.Encrypted.Binary) field(:encrypted_name, Explorer.Encrypted.Binary)
# field(:encrypted_subject, Explorer.Encrypted.Binary) field(:encrypted_subject, Explorer.Encrypted.Binary)
field(:name, Explorer.Encrypted.Binary) # field(:name, Explorer.Encrypted.Binary)
field(:subject, Explorer.Encrypted.Binary) # field(:subject, Explorer.Encrypted.Binary)
field(:subject_hash, Cloak.Ecto.SHA256) field(:subject_hash, Cloak.Ecto.SHA256)
belongs_to(:watchlist_address, WatchlistAddress) belongs_to(:watchlist_address, WatchlistAddress)
# field(:encrypted_from_address_hash, Explorer.Encrypted.AddressHash) field(:encrypted_from_address_hash, Explorer.Encrypted.AddressHash)
# field(:encrypted_to_address_hash, Explorer.Encrypted.AddressHash) field(:encrypted_to_address_hash, Explorer.Encrypted.AddressHash)
# field(:encrypted_transaction_hash, Explorer.Encrypted.TransactionHash) field(:encrypted_transaction_hash, Explorer.Encrypted.TransactionHash)
# field(:from_address_hash, Hash.Address) field(:from_address_hash, Hash.Address)
# field(:to_address_hash, Hash.Address) field(:to_address_hash, Hash.Address)
# field(:transaction_hash, Hash.Full) field(:transaction_hash, Hash.Full)
field(:from_address_hash, Explorer.Encrypted.AddressHash) # field(:from_address_hash, Explorer.Encrypted.AddressHash)
field(:to_address_hash, Explorer.Encrypted.AddressHash) # field(:to_address_hash, Explorer.Encrypted.AddressHash)
field(:transaction_hash, Explorer.Encrypted.TransactionHash) # field(:transaction_hash, Explorer.Encrypted.TransactionHash)
field(:from_address_hash_hash, Cloak.Ecto.SHA256) field(:from_address_hash_hash, Cloak.Ecto.SHA256)
field(:to_address_hash_hash, Cloak.Ecto.SHA256) field(:to_address_hash_hash, Cloak.Ecto.SHA256)

@ -37,7 +37,9 @@ defmodule Explorer.ThirdPartyIntegrations.AirTable do
input input
_ -> error ->
Logger.error(fn -> ["Error while submitting AirTable entry", inspect(error)] end)
{:error, {:error,
%{ %{
(%PublicTagsRequest{} (%PublicTagsRequest{}

@ -11,6 +11,7 @@ defmodule Explorer.Repo.Account.Migrations.EncryptAccountData do
add(:encrypted_avatar, :binary, null: true) add(:encrypted_avatar, :binary, null: true)
end end
# unused because we dont have personal watchlists, only autogenerated `default` for each identity
# alter table(:account_watchlists) do # alter table(:account_watchlists) do
# add(:encrypted_name, :binary) # add(:encrypted_name, :binary)
# end # end
@ -50,5 +51,10 @@ defmodule Explorer.Repo.Account.Migrations.EncryptAccountData do
add(:to_address_hash_hash, :binary, null: true) add(:to_address_hash_hash, :binary, null: true)
add(:transaction_hash_hash, :binary, null: true) add(:transaction_hash_hash, :binary, null: true)
end end
alter table(:account_public_tags_requests) do
add(:encrypted_email, :binary)
add(:encrypted_full_name, :binary)
end
end end
end end

@ -16,6 +16,7 @@ defmodule Explorer.Repo.Account.Migrations.RemoveUnencryptedFields do
rename(table(:account_identities), :encrypted_nickname, to: :nickname) rename(table(:account_identities), :encrypted_nickname, to: :nickname)
rename(table(:account_identities), :encrypted_avatar, to: :avatar) rename(table(:account_identities), :encrypted_avatar, to: :avatar)
# unused because we dont have personal watchlists, only autogenerated `default` for each identity
# alter table(:account_watchlists) do # alter table(:account_watchlists) do
# remove(:name) # remove(:name)
# end # end
@ -66,5 +67,13 @@ defmodule Explorer.Repo.Account.Migrations.RemoveUnencryptedFields do
rename(table(:account_watchlist_notifications), :encrypted_from_address_hash, to: :from_address_hash) rename(table(:account_watchlist_notifications), :encrypted_from_address_hash, to: :from_address_hash)
rename(table(:account_watchlist_notifications), :encrypted_to_address_hash, to: :to_address_hash) rename(table(:account_watchlist_notifications), :encrypted_to_address_hash, to: :to_address_hash)
rename(table(:account_watchlist_notifications), :encrypted_transaction_hash, to: :transaction_hash) rename(table(:account_watchlist_notifications), :encrypted_transaction_hash, to: :transaction_hash)
alter table(:account_public_tags_requests) do
remove(:full_name)
remove(:email)
end
rename(table(:account_public_tags_requests), :encrypted_full_name, to: :full_name)
rename(table(:account_public_tags_requests), :encrypted_email, to: :email)
end end
end end

Loading…
Cancel
Save