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