Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (f *ForField) UnmarshalJSON(data []byte) error {
type Policy struct {
Type string `json:"@type"`
Context any `json:"@context,omitempty"`
From string `json:"from,omitempty"`
FromAgent string `json:"fromAgent,omitempty"`
FromRole string `json:"fromRole,omitempty"`
AboutParty string `json:"aboutParty,omitempty"`
Expand Down
19 changes: 19 additions & 0 deletions types_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tap

import (
"bytes"
"encoding/json"
"testing"
)
Expand Down Expand Up @@ -137,6 +138,24 @@ func TestPolicy_JSONRoundTrip(t *testing.T) {
}
}

func TestPolicy_FromFieldRoundTrip(t *testing.T) {
in := Policy{Type: "RequireAuthorization", From: "did:web:vasp.example"}
data, err := json.Marshal(in)
if err != nil {
t.Fatalf("marshal: %v", err)
}
if !bytes.Contains(data, []byte(`"from":"did:web:vasp.example"`)) {
t.Fatalf("missing from in JSON: %s", string(data))
}
var out Policy
if err := json.Unmarshal(data, &out); err != nil {
t.Fatalf("unmarshal: %v", err)
}
if out.From != in.From {
t.Errorf("From = %q, want %q", out.From, in.From)
}
}

func TestTransactionConstraints_JSONRoundTrip(t *testing.T) {
tc := TransactionConstraints{
Purposes: []string{"BEXP", "SUPP"},
Expand Down
Loading