-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthorize.go
More file actions
41 lines (34 loc) · 1.08 KB
/
authorize.go
File metadata and controls
41 lines (34 loc) · 1.08 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
package tap
import (
"encoding/json"
"fmt"
didcomm "github.com/Notabene-id/go-didcomm"
"github.com/google/uuid"
)
// AuthorizeBody represents the body of a TAP Authorize message (TAIP-4).
type AuthorizeBody struct {
Context string `json:"@context"`
Type string `json:"@type"`
SettlementAddress string `json:"settlementAddress,omitempty"`
SettlementAsset string `json:"settlementAsset,omitempty"`
Amount string `json:"amount,omitempty"`
Expiry string `json:"expiry,omitempty"`
}
func (b *AuthorizeBody) TAPType() string { return TypeAuthorize }
// NewAuthorizeMessage creates a new DIDComm message with an Authorize body.
func NewAuthorizeMessage(from string, to []string, thid string, body *AuthorizeBody) (*didcomm.Message, error) {
body.Context = TAPContext
body.Type = TypeAuthorize
rawBody, err := json.Marshal(body)
if err != nil {
return nil, fmt.Errorf("marshal body: %w", err)
}
return &didcomm.Message{
ID: uuid.New().String(),
Type: TypeAuthorize,
From: from,
To: to,
Thid: thid,
Body: rawBody,
}, nil
}