This repository has been archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
conversion.go
90 lines (84 loc) · 2.37 KB
/
conversion.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package findy
import (
"github.com/findy-network/findy-agent-vault/agency/model"
graph "github.com/findy-network/findy-agent-vault/graph/model"
agency "github.com/findy-network/findy-common-go/grpc/agency/v1"
)
func statusToConnection(status *agency.ProtocolStatus) *model.Connection {
connection := status.GetDIDExchange()
if connection != nil {
return &model.Connection{
OurDID: connection.MyDID,
TheirDID: connection.TheirDID,
TheirEndpoint: connection.TheirEndpoint,
TheirLabel: connection.TheirLabel,
}
}
return nil
}
func statusToCredential(status *agency.ProtocolStatus) *model.Credential {
credential := status.GetIssueCredential()
if credential != nil {
role := graph.CredentialRoleHolder
if status.State.GetProtocolID().Role != agency.Protocol_ADDRESSEE {
role = graph.CredentialRoleIssuer
}
values := make([]*graph.CredentialValue, 0)
for _, v := range credential.Attributes.Attributes {
values = append(values, &graph.CredentialValue{
Name: v.Name,
Value: v.Value,
})
}
return &model.Credential{
Role: role,
SchemaID: credential.SchemaID,
CredDefID: credential.CredDefID,
Attributes: values,
InitiatedByUs: false,
}
}
return nil
}
func statusToProof(status *agency.ProtocolStatus) *model.Proof {
proof := status.GetPresentProof()
if proof != nil {
role := graph.ProofRoleProver
if status.State.GetProtocolID().Role != agency.Protocol_ADDRESSEE {
role = graph.ProofRoleVerifier
}
attributes := make([]*graph.ProofAttribute, 0)
values := make([]*model.ProofValue, 0)
for _, v := range proof.Proof.Attributes {
attributes = append(attributes, &graph.ProofAttribute{
Name: v.Name,
CredDefID: v.CredDefID,
})
if role == graph.ProofRoleVerifier {
values = append(values, &model.ProofValue{
Name: v.Name,
CredDefID: v.CredDefID,
Value: v.Value,
})
}
}
return &model.Proof{
Role: role,
Attributes: attributes,
Values: values,
InitiatedByUs: false,
}
}
return nil
}
func statusToMessage(status *agency.ProtocolStatus) *model.Message {
message := status.GetBasicMessage()
if message != nil {
return &model.Message{
Message: message.Content,
// TODO: remove SentByMe from agency API
SentByMe: status.State.GetProtocolID().Role != agency.Protocol_ADDRESSEE,
}
}
return nil
}