-
Notifications
You must be signed in to change notification settings - Fork 5
/
anchor.go
62 lines (57 loc) · 1.99 KB
/
anchor.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
package sandbox
import (
"encoding/json"
"time"
)
// SourceAnchor initialises an anchor where the type is "SOURCE",
// which has information about how the anchor was sourced.
func SourceAnchor(subtype string, timestamp time.Time, value string) Anchor {
return Anchor{
Type: "SOURCE",
Value: value,
SubType: subtype,
Timestamp: timestamp,
}
}
// VerifierAnchor initialises an anchor where the type is "VERIFIER",
// which has information about how the anchor was verified.
func VerifierAnchor(subtype string, timestamp time.Time, value string) Anchor {
return Anchor{
Type: "VERIFIER",
Value: value,
SubType: subtype,
Timestamp: timestamp,
}
}
// Anchor is the metadata associated with an attribute.
// It describes how an attribute has been provided to Yoti
// (SOURCE Anchor) and how it has been verified (VERIFIER Anchor).
type Anchor struct {
// Type of the Anchor - most likely either SOURCE or VERIFIER, but it's
// possible that new Anchor types will be added in future.
Type string
// Value identifies the provider that either sourced or verified the attribute value.
// The range of possible values is not limited. For a SOURCE anchor, expect values like
// PASSPORT, DRIVING_LICENSE. For a VERIFIER anchor expect values like YOTI_ADMIN.
Value string
// SubType is an indicator of any specific processing method, or subcategory,
// pertaining to an artifact. For example, for a passport, this would be
// either "NFC" or "OCR".
SubType string
// Timestamp is the time when the anchor was created, i.e. when it was SOURCED or VERIFIED.
Timestamp time.Time
}
// MarshalJSON returns the JSON encoding
func (anchor *Anchor) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type string `json:"type"`
Value string `json:"value"`
SubType string `json:"sub_type"`
Timestamp int64 `json:"timestamp"`
}{
Type: anchor.Type,
Value: anchor.Value,
SubType: anchor.SubType,
Timestamp: anchor.Timestamp.UnixNano() / 1e6,
})
}