-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_agent.go
More file actions
45 lines (37 loc) · 1.13 KB
/
update_agent.go
File metadata and controls
45 lines (37 loc) · 1.13 KB
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
package tap
import (
"encoding/json"
"fmt"
didcomm "github.com/Notabene-id/go-didcomm"
"github.com/google/uuid"
)
// UpdateAgentBody represents the body of a TAP UpdateAgent message (TAIP-5).
type UpdateAgentBody struct {
Context string `json:"@context"`
Type string `json:"@type"`
Agent *Agent `json:"agent"`
PreviousDID string `json:"previousDid,omitempty"`
Reason string `json:"reason,omitempty"`
Effective string `json:"effective,omitempty"`
}
func (b *UpdateAgentBody) TAPType() string { return TypeUpdateAgent }
// NewUpdateAgentMessage creates a new DIDComm message with an UpdateAgent body.
func NewUpdateAgentMessage(from string, to []string, thid string, body *UpdateAgentBody) (*didcomm.Message, error) {
if body.Agent == nil {
return nil, fmt.Errorf("%w: missing agent", ErrInvalidBody)
}
body.Context = TAPContext
body.Type = TypeUpdateAgent
rawBody, err := json.Marshal(body)
if err != nil {
return nil, fmt.Errorf("marshal body: %w", err)
}
return &didcomm.Message{
ID: uuid.New().String(),
Type: TypeUpdateAgent,
From: from,
To: to,
Thid: thid,
Body: rawBody,
}, nil
}