diff --git a/apps/explorer/lib/encrypt.ex b/apps/explorer/lib/encrypt.ex index 64d8b29f46..976f2a7de6 100644 --- a/apps/explorer/lib/encrypt.ex +++ b/apps/explorer/lib/encrypt.ex @@ -8,14 +8,15 @@ defmodule Mix.Tasks.Encrypt do Explorer.Account.Identity |> Explorer.Repo.Account.all() - |> Enum.map(fn identity -> - identity + |> Enum.map(fn element -> + element |> Ecto.Changeset.change(%{ - encrypted_uid: identity.uid, - encrypted_email: identity.email, - encrypted_name: identity.name, - encrypted_nickname: identity.nickname, - encrypted_avatar: identity.avatar + encrypted_uid: element.uid, + encrypted_email: element.email, + encrypted_name: element.name, + encrypted_nickname: element.nickname, + encrypted_avatar: element.avatar, + uid_hash: Cloak.Ecto.SHA256.hash(element.uid) }) |> Explorer.Repo.Account.update!() end) @@ -26,7 +27,8 @@ defmodule Mix.Tasks.Encrypt do element |> Ecto.Changeset.change(%{ encrypted_name: element.name, - encrypted_address_hash: element.address_hash + encrypted_address_hash: element.address_hash, + address_hash_hash: Cloak.Ecto.SHA256.hash(to_string(element.address_hash)) }) |> Explorer.Repo.Account.update!() end) @@ -37,7 +39,8 @@ defmodule Mix.Tasks.Encrypt do element |> Ecto.Changeset.change(%{ encrypted_name: element.name, - encrypted_tx_hash: element.tx_hash + encrypted_tx_hash: element.tx_hash, + tx_hash_hash: Cloak.Ecto.SHA256.hash(to_string(element.tx_hash)) }) |> Explorer.Repo.Account.update!() end) @@ -48,7 +51,8 @@ defmodule Mix.Tasks.Encrypt do element |> Ecto.Changeset.change(%{ encrypted_name: element.name, - encrypted_address_hash: element.address_hash + encrypted_address_hash: element.address_hash, + address_hash_hash: Cloak.Ecto.SHA256.hash(to_string(element.address_hash)) }) |> Explorer.Repo.Account.update!() end) @@ -59,7 +63,8 @@ defmodule Mix.Tasks.Encrypt do element |> Ecto.Changeset.change(%{ encrypted_name: element.name, - encrypted_address_hash: element.address_hash + encrypted_address_hash: element.address_hash, + address_hash_hash: Cloak.Ecto.SHA256.hash(to_string(element.address_hash)) }) |> Explorer.Repo.Account.update!() end) @@ -73,7 +78,11 @@ defmodule Mix.Tasks.Encrypt do encrypted_from_address_hash: element.from_address_hash, encrypted_to_address_hash: element.to_address_hash, encrypted_transaction_hash: element.transaction_hash, - encrypted_subject: element.subject + encrypted_subject: element.subject, + from_address_hash_hash: Cloak.Ecto.SHA256.hash(to_string(element.from_address_hash)), + to_address_hash_hash: Cloak.Ecto.SHA256.hash(to_string(element.to_address_hash)), + transaction_hash_hash: Cloak.Ecto.SHA256.hash(to_string(element.transaction_hash)), + subject_hash: Cloak.Ecto.SHA256.hash(element.subject) }) |> Explorer.Repo.Account.update!() end) diff --git a/apps/explorer/lib/explorer/account/custom_abi.ex b/apps/explorer/lib/explorer/account/custom_abi.ex index 4a9705a5e1..ec22ac17ce 100644 --- a/apps/explorer/lib/explorer/account/custom_abi.ex +++ b/apps/explorer/lib/explorer/account/custom_abi.ex @@ -18,12 +18,16 @@ defmodule Explorer.Account.CustomABI do field(:abi, {:array, :map}) field(:given_abi, :string, virtual: true) field(:abi_validating_error, :string, virtual: true) - # field(:name, :string) - # field(:address_hash, Hash.Address, null: false) - # field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false) - # field(:encrypted_name, Explorer.Encrypted.Binary) - field(:address_hash, Explorer.Encrypted.AddressHash, null: false) - field(:name, Explorer.Encrypted.Binary) + + field(:name, :string) + field(:address_hash, Hash.Address, null: false) + + field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false) + field(:encrypted_name, Explorer.Encrypted.Binary) + field(:address_hash_hash, Cloak.Ecto.SHA256) + + # field(:address_hash, Explorer.Encrypted.AddressHash, null: false) + # field(:name, Explorer.Encrypted.Binary) belongs_to(:identity, Identity) diff --git a/apps/explorer/lib/explorer/account/identity.ex b/apps/explorer/lib/explorer/account/identity.ex index 0348fec4a0..15cc0271e1 100644 --- a/apps/explorer/lib/explorer/account/identity.ex +++ b/apps/explorer/lib/explorer/account/identity.ex @@ -11,23 +11,25 @@ defmodule Explorer.Account.Identity do alias Explorer.Account.{TagAddress, Watchlist} schema "account_identities" do - # field(:uid, :string) - # field(:email, :string) - # field(:name, :string) - # field(:nickname, :string) - # field(:avatar, :string) - - # field(:encrypted_uid, Explorer.Encrypted.Binary) - # field(:encrypted_email, Explorer.Encrypted.Binary) - # field(:encrypted_name, Explorer.Encrypted.Binary) - # field(:encrypted_nickname, Explorer.Encrypted.Binary) - # field(:encrypted_avatar, Explorer.Encrypted.Binary) - - field(:uid, Explorer.Encrypted.Binary) - field(:email, Explorer.Encrypted.Binary) - field(:name, Explorer.Encrypted.Binary) - field(:nickname, Explorer.Encrypted.Binary) - field(:avatar, Explorer.Encrypted.Binary) + field(:uid, :string) + field(:email, :string) + field(:name, :string) + field(:nickname, :string) + field(:avatar, :string) + + field(:encrypted_uid, Explorer.Encrypted.Binary) + field(:encrypted_email, Explorer.Encrypted.Binary) + field(:encrypted_name, Explorer.Encrypted.Binary) + field(:encrypted_nickname, Explorer.Encrypted.Binary) + field(:encrypted_avatar, Explorer.Encrypted.Binary) + + field(:uid_hash, Cloak.Ecto.SHA256) + + # field(:uid, Explorer.Encrypted.Binary) + # field(:email, Explorer.Encrypted.Binary) + # field(:name, Explorer.Encrypted.Binary) + # field(:nickname, Explorer.Encrypted.Binary) + # field(:avatar, Explorer.Encrypted.Binary) has_many(:tag_addresses, TagAddress) has_many(:watchlists, Watchlist) diff --git a/apps/explorer/lib/explorer/account/tag_address.ex b/apps/explorer/lib/explorer/account/tag_address.ex index 02c3887984..0006f59b26 100644 --- a/apps/explorer/lib/explorer/account/tag_address.ex +++ b/apps/explorer/lib/explorer/account/tag_address.ex @@ -15,13 +15,15 @@ defmodule Explorer.Account.TagAddress do @max_tag_address_per_account 15 schema "account_tag_addresses" do - # field(:name, :string) - # field(:address_hash, Hash.Address, null: false) - # field(:encrypted_name, Explorer.Encrypted.Binary) - # field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false) + field(:name, :string) + field(:address_hash, Hash.Address, null: false) + field(:encrypted_name, Explorer.Encrypted.Binary) + field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false) - field(:name, Explorer.Encrypted.Binary) - field(:address_hash, Explorer.Encrypted.AddressHash, null: false) + field(:address_hash_hash, Cloak.Ecto.SHA256) + + # field(:name, Explorer.Encrypted.Binary) + # field(:address_hash, Explorer.Encrypted.AddressHash, null: false) belongs_to(:identity, Identity) diff --git a/apps/explorer/lib/explorer/account/tag_transaction.ex b/apps/explorer/lib/explorer/account/tag_transaction.ex index 10cba87479..8050fed0d9 100644 --- a/apps/explorer/lib/explorer/account/tag_transaction.ex +++ b/apps/explorer/lib/explorer/account/tag_transaction.ex @@ -15,13 +15,15 @@ defmodule Explorer.Account.TagTransaction do @max_tag_transaction_per_account 15 schema "account_tag_transactions" do - # field(:name, :string) - # field(:tx_hash, Hash.Full, null: false) - # field(:encrypted_name, Explorer.Encrypted.Binary) - # field(:encrypted_tx_hash, Explorer.Encrypted.TransactionHash, null: false) + field(:name, :string) + field(:tx_hash, Hash.Full, null: false) - field(:name, Explorer.Encrypted.Binary) - field(:tx_hash, Explorer.Encrypted.TransactionHash, null: false) + field(:encrypted_name, Explorer.Encrypted.Binary) + field(:encrypted_tx_hash, Explorer.Encrypted.TransactionHash, null: false) + field(:tx_hash_hash, Cloak.Ecto.SHA256) + + # field(:name, Explorer.Encrypted.Binary) + # field(:tx_hash, Explorer.Encrypted.TransactionHash, null: false) belongs_to(:identity, Identity) diff --git a/apps/explorer/lib/explorer/account/watchlist_address.ex b/apps/explorer/lib/explorer/account/watchlist_address.ex index f793add2f5..0ef77e2ac3 100644 --- a/apps/explorer/lib/explorer/account/watchlist_address.ex +++ b/apps/explorer/lib/explorer/account/watchlist_address.ex @@ -16,13 +16,15 @@ defmodule Explorer.Account.WatchlistAddress do @max_watchlist_addresses_per_account 10 schema "account_watchlist_addresses" do - # field(:name, :string) - # field(:address_hash, Hash.Address, null: false) - # field(:encrypted_name, Explorer.Encrypted.Binary) - # field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false) + field(:name, :string) + field(:address_hash, Hash.Address, null: false) + field(:encrypted_name, Explorer.Encrypted.Binary) + field(:encrypted_address_hash, Explorer.Encrypted.AddressHash, null: false) - field(:name, Explorer.Encrypted.Binary) - field(:address_hash, Explorer.Encrypted.AddressHash, null: false) + field(:address_hash_hash, Cloak.Ecto.SHA256) + + # field(:name, Explorer.Encrypted.Binary) + # field(:address_hash, Explorer.Encrypted.AddressHash, null: false) belongs_to(:watchlist, Watchlist) diff --git a/apps/explorer/lib/explorer/account/watchlist_notification.ex b/apps/explorer/lib/explorer/account/watchlist_notification.ex index 101893abd6..f7996990d6 100644 --- a/apps/explorer/lib/explorer/account/watchlist_notification.ex +++ b/apps/explorer/lib/explorer/account/watchlist_notification.ex @@ -16,30 +16,38 @@ defmodule Explorer.Account.WatchlistNotification do field(:block_number, :integer) field(:direction, :string) field(:method, :string) - # field(:name, :string) - # field(:subject, :string) field(:tx_fee, :decimal) field(:type, :string) field(:viewed_at, :integer) - # field(:encrypted_name, Explorer.Encrypted.Binary) - # field(:encrypted_subject, Explorer.Encrypted.Binary) - field(:name, Explorer.Encrypted.Binary) - field(:subject, Explorer.Encrypted.Binary) + field(:name, :string) + field(:subject, :string) + + field(:encrypted_name, Explorer.Encrypted.Binary) + field(:encrypted_subject, Explorer.Encrypted.Binary) + + # field(:name, Explorer.Encrypted.Binary) + # field(:subject, Explorer.Encrypted.Binary) + + field(:subject_hash, Cloak.Ecto.SHA256) belongs_to(:watchlist_address, WatchlistAddress) - # field(:encrypted_from_address_hash, Explorer.Encrypted.AddressHash) - # field(:encrypted_to_address_hash, Explorer.Encrypted.AddressHash) - # field(:encrypted_transaction_hash, Explorer.Encrypted.TransactionHash) + field(:encrypted_from_address_hash, Explorer.Encrypted.AddressHash) + field(:encrypted_to_address_hash, Explorer.Encrypted.AddressHash) + field(:encrypted_transaction_hash, Explorer.Encrypted.TransactionHash) + + field(:from_address_hash, Hash.Address) + field(:to_address_hash, Hash.Address) + field(:transaction_hash, Hash.Full) - # field(:from_address_hash, Hash.Address) - # field(:to_address_hash, Hash.Address) - # field(:transaction_hash, Hash.Full) + # field(:from_address_hash, Explorer.Encrypted.AddressHash) + # field(:to_address_hash, Explorer.Encrypted.AddressHash) + # field(:transaction_hash, Explorer.Encrypted.TransactionHash) - field(:from_address_hash, Explorer.Encrypted.AddressHash) - field(:to_address_hash, Explorer.Encrypted.AddressHash) - field(:transaction_hash, Explorer.Encrypted.TransactionHash) + field(:from_address_hash_hash, Cloak.Ecto.SHA256) + field(:to_address_hash_hash, Cloak.Ecto.SHA256) + field(:transaction_hash_hash, Cloak.Ecto.SHA256) timestamps() end diff --git a/apps/explorer/priv/account/migrations/20220706114430_encrypt_account_data.exs b/apps/explorer/priv/account/migrations/20220706114430_encrypt_account_data.exs index be4ff49967..4811b2db0f 100644 --- a/apps/explorer/priv/account/migrations/20220706114430_encrypt_account_data.exs +++ b/apps/explorer/priv/account/migrations/20220706114430_encrypt_account_data.exs @@ -4,6 +4,7 @@ defmodule Explorer.Repo.Account.Migrations.EncryptAccountData do def change do alter table(:account_identities) do add(:encrypted_uid, :binary) + add(:uid_hash, :binary) add(:encrypted_email, :binary) add(:encrypted_name, :binary) add(:encrypted_nickname, :binary, null: true) @@ -15,21 +16,25 @@ defmodule Explorer.Repo.Account.Migrations.EncryptAccountData do # end alter table(:account_custom_abis) do + add(:address_hash_hash, :binary) add(:encrypted_address_hash, :binary) add(:encrypted_name, :binary) end alter table(:account_tag_addresses) do + add(:address_hash_hash, :binary) add(:encrypted_name, :binary) add(:encrypted_address_hash, :binary) end alter table(:account_tag_transactions) do + add(:tx_hash_hash, :binary) add(:encrypted_name, :binary) add(:encrypted_tx_hash, :binary) end alter table(:account_watchlist_addresses) do + add(:address_hash_hash, :binary) add(:encrypted_name, :binary) add(:encrypted_address_hash, :binary) end @@ -40,6 +45,10 @@ defmodule Explorer.Repo.Account.Migrations.EncryptAccountData do add(:encrypted_from_address_hash, :binary) add(:encrypted_to_address_hash, :binary) add(:encrypted_transaction_hash, :binary) + add(:subject_hash, :binary, null: true) + add(:from_address_hash_hash, :binary, null: true) + add(:to_address_hash_hash, :binary, null: true) + add(:transaction_hash_hash, :binary, null: true) end end end diff --git a/apps/explorer/priv/account/migrations/20220706211444_set_new_indexes.exs b/apps/explorer/priv/account/migrations/20220706211444_set_new_indexes.exs new file mode 100644 index 0000000000..ef80adea47 --- /dev/null +++ b/apps/explorer/priv/account/migrations/20220706211444_set_new_indexes.exs @@ -0,0 +1,37 @@ +defmodule Explorer.Repo.Account.Migrations.SetNewIndexes do + use Ecto.Migration + + def change do + drop_if_exists(unique_index(:account_tag_addresses, [:identity_id, :address_hash])) + drop_if_exists(unique_index(:account_tag_transactions, [:identity_id, :tx_hash])) + drop_if_exists(unique_index(:account_watchlist_addresses, [:watchlist_id, :address_hash])) + drop_if_exists(unique_index(:account_custom_abis, [:identity_id, :address_hash])) + + drop_if_exists(index(:account_watchlist_notifications, [:transaction_hash])) + drop_if_exists(index(:account_watchlist_notifications, [:from_address_hash])) + drop_if_exists(index(:account_watchlist_notifications, [:to_address_hash])) + + drop_if_exists(unique_index(:account_identities, [:uid])) + + drop_if_exists(index(:account_tag_addresses, [:address_hash])) + drop_if_exists(index(:account_tag_transactions, [:tx_hash])) + + drop_if_exists(index(:account_watchlist_addresses, [:address_hash])) + + create(unique_index(:account_tag_addresses, [:identity_id, :address_hash_hash])) + create(unique_index(:account_tag_transactions, [:identity_id, :tx_hash_hash])) + create(unique_index(:account_watchlist_addresses, [:watchlist_id, :address_hash_hash])) + create(unique_index(:account_custom_abis, [:identity_id, :address_hash_hash])) + + create(index(:account_watchlist_notifications, [:transaction_hash_hash])) + create(index(:account_watchlist_notifications, [:from_address_hash_hash])) + create(index(:account_watchlist_notifications, [:to_address_hash_hash])) + + create(unique_index(:account_identities, [:uid_hash])) + + create(index(:account_tag_addresses, [:address_hash_hash])) + create(index(:account_tag_transactions, [:tx_hash_hash])) + + create(index(:account_watchlist_addresses, [:address_hash_hash])) + end +end diff --git a/apps/explorer/priv/repo/migrations/20220706211444_set_new_indexes.exs b/apps/explorer/priv/repo/migrations/20220706211444_set_new_indexes.exs new file mode 100644 index 0000000000..b2fdc60a01 --- /dev/null +++ b/apps/explorer/priv/repo/migrations/20220706211444_set_new_indexes.exs @@ -0,0 +1,6 @@ +defmodule Explorer.Repo.Migrations.SetNewIndexes do + use Ecto.Migration + + def change do + end +end