zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

commit 9a0c54d33e32d11c11018f07429b389a999e6fc3
parent ef4fca40272a531949b008c356f292f8ac52bf18
Author: srfsh <dev@srf.sh>
Date:   Tue, 19 Jul 2022 18:23:55 +0300

vf/person: split pubkeys into separate fields and change type to string

Diffstat:
Msrc/zenflows/vf/person.ex | 50++++++++++++++++++++++++++++----------------------
Msrc/zenflows/vf/person/resolv.ex | 4----
Msrc/zenflows/vf/person/type.ex | 47++++++++++++++++++++++++++++++++++++++++-------
3 files changed, 68 insertions(+), 33 deletions(-)

diff --git a/src/zenflows/vf/person.ex b/src/zenflows/vf/person.ex @@ -30,8 +30,12 @@ alias Zenflows.VF.{SpatialThing, Validate} primary_location: SpatialThing.t() | nil, user: String.t(), email: String.t(), - pubkeys: binary(), - pubkeys_encoded: String.t() | nil, + dilithium_public_key: String.t() | nil, + ecdh_public_key: String.t() | nil, + eddsa_public_key: String.t() | nil, + ethereum_address: String.t() | nil, + reflow_public_key: String.t() | nil, + schnorr_public_key: String.t() | nil, } schema "vf_agent" do @@ -42,13 +46,26 @@ schema "vf_agent" do belongs_to :primary_location, SpatialThing field :user, :string field :email, :string - field :pubkeys, :binary - field :pubkeys_encoded, :string, virtual: true + field :dilithium_public_key, :string + field :ecdh_public_key, :string + field :eddsa_public_key, :string + field :ethereum_address, :string + field :reflow_public_key, :string + field :schnorr_public_key, :string end @insert_reqr ~w[name user email]a -@insert_cast @insert_reqr ++ ~w[pubkeys_encoded image note primary_location_id]a +@insert_cast @insert_reqr ++ ~w[ + image note primary_location_id + dilithium_public_key + ecdh_public_key + eddsa_public_key + ethereum_address + reflow_public_key + schnorr_public_key +]a # TODO: Maybe add email to @update_cast as well? +# TODO: Maybe add the pubkeys to @update_cast as well? @update_cast ~w[name image note primary_location_id user]a # insert changeset @@ -63,8 +80,13 @@ def chgset(params) do |> Validate.name(:email) |> Validate.uri(:image) |> Validate.note(:note) + |> Validate.key(:dilithium_public_key) + |> Validate.key(:ecdh_public_key) + |> Validate.key(:eddsa_public_key) + |> Validate.key(:ethereum_address) + |> Validate.key(:reflow_public_key) + |> Validate.key(:schnorr_public_key) |> check_email() - |> decode_pubkeys() |> Changeset.unique_constraint(:user) |> Changeset.unique_constraint(:name) |> Changeset.unique_constraint(:email) @@ -93,20 +115,4 @@ defp check_email(cset) do # works good enough for now Changeset.validate_format(cset, :email, ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/) end - -@spec decode_pubkeys(Changeset.t()) :: Changeset.t() -defp decode_pubkeys(cset) do - case Changeset.fetch_change(cset, :pubkeys_encoded) do - {:ok, val} -> - case Base.url_decode64(val) do - {:ok, decoded} -> - Changeset.put_change(cset, :pubkeys, decoded) - - :error -> - Changeset.add_error(cset, :pubkeys, "not valid url-safe base64-encoded string") - end - :error -> - cset - end -end end diff --git a/src/zenflows/vf/person/resolv.ex b/src/zenflows/vf/person/resolv.ex @@ -52,8 +52,4 @@ end def primary_location(%Agent{} = agent, args, info) do Agent.Resolv.primary_location(agent, args, info) end - -def pubkeys(%Person{} = per, _args, _info) do - {:ok, Base.url_encode64(per.pubkeys)} -end end diff --git a/src/zenflows/vf/person/type.ex b/src/zenflows/vf/person/type.ex @@ -36,9 +36,12 @@ who have no physical location. """ @user "Username of the agent. Implies uniqueness." @email "Email address of the agent. Implies uniqueness." -@pubkeys """ -A URL-safe, lowercase-Base64-encoded string of a JSON object. -""" +@dilithium_public_key "dilithium public key encoded as base64url string" +@ecdh_public_key "ecdh public key encoded as base64url string" +@eddsa_public_key "eddsa public key encoded as base64url string" +@ethereum_address "ethereum address encoded as base64url string" +@reflow_public_key "reflow public key encoded as base64url string" +@schnorr_public_key "schnorr public key encoded as base64url string" @desc "A natural person." object :person do @@ -65,8 +68,23 @@ object :person do @desc @email field :email, non_null(:string) - @desc @pubkeys - field :pubkeys, :string, resolve: &Resolv.pubkeys/3 + @desc @dilithium_public_key + field :dilithium_public_key, :string + + @desc @ecdh_public_key + field :ecdh_public_key, :string + + @desc @eddsa_public_key + field :eddsa_public_key, :string + + @desc @ethereum_address + field :ethereum_address, :string + + @desc @reflow_public_key + field :reflow_public_key, :string + + @desc @schnorr_public_key + field :schnorr_public_key, :string end object :person_response do @@ -95,8 +113,23 @@ input_object :person_create_params do @desc @email field :email, non_null(:string) - @desc @pubkeys - field :pubkeys_encoded, :string, name: "pubkeys" + @desc @dilithium_public_key + field :dilithium_public_key, :string + + @desc @ecdh_public_key + field :ecdh_public_key, :string + + @desc @eddsa_public_key + field :eddsa_public_key, :string + + @desc @ethereum_address + field :ethereum_address, :string + + @desc @reflow_public_key + field :reflow_public_key, :string + + @desc @schnorr_public_key + field :schnorr_public_key, :string end input_object :person_update_params do