forked from build-trust/ockam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathockam.go
157 lines (125 loc) · 3.41 KB
/
ockam.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package ockam
import (
"encoding/json"
"github.com/ockam-network/did"
)
// Block represents a block in the Ockam Blockchain
type Block interface {
Height() string
Hash() string
}
// Chain represents a chain of blocks that is maintained by a network of nodes
type Chain interface {
ID() string
Sync() error
LatestBlock() Block
Register(Entity) (Claim, error)
Submit(Claim) error
FetchClaim(string) ([]byte, Claim, error)
FetchEntity(string) ([]byte, Entity, error)
}
// Node represents a node connected to a network of other peer nodes
type Node interface {
Chain
Peers() []Node
Chain() Chain
}
// NodeDiscoverer provides the means to discover other nodes on in a network
type NodeDiscoverer interface {
Discover() ([]Node, error)
}
// PublicKey is
type PublicKey interface {
Label() string
SetLabel(string)
Owner() Entity
SetOwner(Entity)
Type() string
Encoding() string
Value() string
DID() (*did.DID, error)
}
// Signature is
// https://w3c-dvcg.github.io/ld-signatures/#linked-data-signature-overview
type Signature interface {
// Type
// https://w3c-ccg.github.io/ld-cryptosuite-registry/#ed25519signature2018
Type() string
Creator() string
Created() string
Domain() string
// Nonce
// https://web-payments.org/vocabs/security#nonce
Nonce() string
// SignatureValue
// https://web-payments.org/vocabs/security#signatureValue
SignatureValue() []byte
SignedValue() []byte
}
// Claim is
type Claim interface {
ID() string
Nonce() string
Type() string
SetType(string)
Issuer() Entity
SetIssuer(Entity)
Subject() Entity
SetSubject(Entity)
Data() map[string]interface{}
SetData(map[string]interface{})
Signatures() []Signature
AddSignature(Signature)
json.Marshaler
}
// Entity represents and Ockam entity
type Entity interface {
ID() *did.DID
PublicKeys() []PublicKey
Signers() []Signer
Attributes() map[string]interface{}
}
// Signer is
type Signer interface {
PublicKey() PublicKey
Sign(Claim) error
SignatureType() string
}
// Fields is
type Fields map[string]interface{}
// Logger is an interface for Logging.
type Logger interface {
Error(format string, v ...interface{})
Warn(format string, v ...interface{})
Notice(format string, v ...interface{})
Info(format string, v ...interface{})
Debug(format string, v ...interface{})
WithFields(fields Fields) Logger
}
type Store interface {
Put(key, value interface{}) error
Get(key interface{}) (value interface{}, err error)
Delete(key interface{}) error
}
type CommitStore interface {
Store
GetLastTrusted() (interface{}, error)
StoreLastTrusted(lastTrusted interface{}) error
}
// Cryptographer is
type Cryptographer interface {
GenerateKeyPair() (publicKey []byte, secretKey []byte, err error)
AnonymousEncrypt(unencrypted []byte, recipientPublicKey []byte) (encrypted []byte, err error)
AnonymousDecrypt(encrypted []byte, recipientSecretKey []byte) (unencrypted []byte, err error)
Sign(message []byte, secretKey []byte) (signed []byte, err error)
VerifySignature(signed []byte, signerPublicKey []byte) (ok bool, message []byte, err error)
AuthenticatedEncrypt(unencrypted []byte, senderSecretKey []byte, recipientPublicKey []byte, nonce []byte) (
encrypted []byte, err error)
AuthenticatedDecrypt(encrypted []byte, recipientSecretKey []byte, senderPublicKey []byte, nonce []byte) (
unencrypted []byte, err error)
}
// Version returns the current version of Ockam
func Version() string {
version := "0.3.2"
return version
}