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 3
/
Issue.go
102 lines (81 loc) · 2.12 KB
/
Issue.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
91
92
93
94
95
96
97
98
99
100
101
102
package issuecredential
import (
"encoding/base64"
"encoding/gob"
"github.com/findy-network/findy-agent/agent/aries"
"github.com/findy-network/findy-agent/agent/didcomm"
"github.com/findy-network/findy-agent/agent/pltype"
"github.com/findy-network/findy-agent/std/decorator"
"github.com/findy-network/findy-common-go/dto"
)
var IssueCreator = &IssueFactor{}
type IssueFactor struct{}
func (f *IssueFactor) NewMsg(init didcomm.MsgInit) didcomm.MessageHdr {
m := &Issue{
Type: init.Type,
ID: init.AID,
Comment: init.Info,
Thread: decorator.CheckThread(init.Thread, init.AID),
}
return NewIssue(m)
}
func (f *IssueFactor) NewMessage(data []byte) didcomm.MessageHdr {
return NewIssueMsg(data)
}
func init() {
gob.Register(&IssueImpl{})
aries.Creator.Add(pltype.IssueCredentialIssue, IssueCreator)
aries.Creator.Add(pltype.DIDOrgIssueCredentialIssue, IssueCreator)
}
func NewIssue(r *Issue) *IssueImpl {
return &IssueImpl{Issue: r}
}
func NewIssueMsg(data []byte) *IssueImpl {
var mImpl IssueImpl
dto.FromJSON(data, &mImpl)
mImpl.checkThread()
return &mImpl
}
// MARK: Helpers
func CredentialAttach(p *Issue) (data []byte, err error) {
return base64.StdEncoding.DecodeString(p.CredentialsAttach[0].Data.Base64)
}
func (p *IssueImpl) checkThread() {
p.Issue.Thread = decorator.CheckThread(p.Issue.Thread, p.Issue.ID)
}
// MARK: Struct
type IssueImpl struct {
*Issue
}
func NewCredentialsAttach(attach []byte) []decorator.Attachment {
data := decorator.AttachmentData{
Base64: base64.StdEncoding.EncodeToString(attach)}
rp := []decorator.Attachment{{
ID: "libindy-cred-0",
MimeType: "application/json",
Data: data,
}}
return rp
}
func (p *IssueImpl) ID() string {
return p.Issue.ID
}
func (p *IssueImpl) Type() string {
return p.Issue.Type
}
func (p *IssueImpl) SetID(id string) {
p.Issue.ID = id
}
func (p *IssueImpl) SetType(t string) {
p.Issue.Type = t
}
func (p *IssueImpl) JSON() []byte {
return dto.ToJSONBytes(p)
}
func (p *IssueImpl) Thread() *decorator.Thread {
//if p.Issue.Thread == nil {}
return p.Issue.Thread
}
func (p *IssueImpl) FieldObj() interface{} {
return p.Issue
}