-
Notifications
You must be signed in to change notification settings - Fork 1
/
subject.go
47 lines (37 loc) · 930 Bytes
/
subject.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
package main
import (
"crypto/ed25519"
"fmt"
)
type Subject struct {
keys KeyPair
}
func CreateSubject() (Subject, error) {
pub, priv, err := ed25519.GenerateKey(nil)
if err != nil {
err = fmt.Errorf("Couldn't create subject keys: %w", err)
return Subject{}, err
}
subject := Subject{
keys: KeyPair{PublicKey: pub, PrivateKey: priv},
}
return subject, err
}
func (s Subject) GetID() []byte {
return []byte(s.keys.PublicKey)
}
func (s Subject) SignPresentation(credentials Credential, nonce []byte) (
Presentation, error) {
presentation := Presentation{PresentationToSign: PresentationToSign{
Context: vcContext,
TypeOfPresentation: []string{presType},
Credential: credentials,
Nonce: nonce,
}}
docToSign, err := presentation.Export()
if err != nil {
return presentation, err
}
presentation.Proof = SignProof(s.keys, docToSign)
return presentation, err
}