Skip to content

Commit

Permalink
feat(elixir): adapt to changes on authority api
Browse files Browse the repository at this point in the history
mainly on use of binary identity identifiers rather than the string
format.
  • Loading branch information
polvorin committed Oct 3, 2023
1 parent 5fbb9eb commit e1521f3
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ defmodule Ockam.Credential.Authenticator.Direct.Client.AddMemberRequest do

typedstruct do
plugin(Ockam.TypedCBOR.Plugin)
field(:identity_id, binary(), minicbor: [key: 1])

field(:identity_id, Ockam.Identity.Identifier.t(),
minicbor: [key: 1, schema: Ockam.Identity.Identifier]
)

field(:attributes, %{String.t() => String.t()}, minicbor: [key: 2])
end
end
Expand All @@ -17,13 +21,16 @@ defmodule Ockam.Credential.Authenticator.Direct.Client.AttributesEntry do
"""
use TypedStruct

alias Ockam.Identity.Identifier

typedstruct do
plugin(Ockam.TypedCBOR.Plugin)
## Rust encodes attribute values as a list of bytes
field(:attributes, %{{:list, :integer} => {:list, :integer}}, minicbor: [key: 1])
field(:added_at, integer(), minicbor: [key: 2])
field(:expires, integer() | nil, minicbor: [key: 3])
field(:attested_by, binary() | nil, minicbor: [key: 4])

field(:attested_by, Identifier.t() | nil, minicbor: [key: 4, schema: Identifier])
end
end

Expand All @@ -35,8 +42,9 @@ defmodule Ockam.Credential.Authenticator.Direct.Client.ListMembersResponse do
"""

alias Ockam.Credential.Authenticator.Direct.Client.AttributesEntry
alias Ockam.Identity.Identifier

@schema {:map, :string, AttributesEntry.minicbor_schema()}
@schema {:map, :binary, AttributesEntry.minicbor_schema()}

def decode_strict(data) do
with {:ok, decoded} <- Ockam.TypedCBOR.decode_strict(@schema, data) do
Expand All @@ -50,7 +58,7 @@ defmodule Ockam.Credential.Authenticator.Direct.Client.ListMembersResponse do
{:erlang.list_to_binary(key), :erlang.list_to_binary(val)}
end)

{id, Map.put(entry, :attributes, attributes)}
{%Identifier{id: id}, Map.put(entry, :attributes, attributes)}
end)}
end
end
Expand All @@ -70,7 +78,11 @@ defmodule Ockam.Credential.Authenticator.Direct.Client do
alias Ockam.Credential.Authenticator.Direct.Client.AttributesEntry
alias Ockam.Credential.Authenticator.Direct.Client.ListMembersResponse

@spec add_member(String.t(), %{String.t() => String.t()}, Ockam.Address.route()) ::
@spec add_member(
Ockam.Identity.Identifier.t(),
%{String.t() => String.t()},
Ockam.Address.route()
) ::
:ok | {:error, any()}
def add_member(identity_id, attributes, api_route) do
request =
Expand Down

0 comments on commit e1521f3

Please sign in to comment.