-
Notifications
You must be signed in to change notification settings - Fork 28
/
authticket.go
47 lines (42 loc) · 1.14 KB
/
authticket.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 marker
import (
"fmt"
"github.com/0chain/gosdk/core/encryption"
"github.com/0chain/gosdk/zboxcore/client"
)
type AuthTicket struct {
ClientID string `json:"client_id"`
OwnerID string `json:"owner_id"`
AllocationID string `json:"allocation_id"`
FilePathHash string `json:"file_path_hash"`
ActualFileHash string `json:"actual_file_hash"`
FileName string `json:"file_name"`
RefType string `json:"reference_type"`
Expiration int64 `json:"expiration"`
Timestamp int64 `json:"timestamp"`
ReEncryptionKey string `json:"re_encryption_key,omitempty"`
Encrypted bool `json:"encrypted"`
Signature string `json:"signature"`
}
func (at *AuthTicket) GetHashData() string {
hashData := fmt.Sprintf("%v:%v:%v:%v:%v:%v:%v:%v:%v:%v:%v",
at.AllocationID,
at.ClientID,
at.OwnerID,
at.FilePathHash,
at.FileName,
at.RefType,
at.ReEncryptionKey,
at.Expiration,
at.Timestamp,
at.ActualFileHash,
at.Encrypted,
)
return hashData
}
func (at *AuthTicket) Sign() error {
var err error
hash := encryption.Hash(at.GetHashData())
at.Signature, err = client.Sign(hash)
return err
}