-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
127 lines (97 loc) · 3.32 KB
/
types.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
package ffi
import (
"bytes"
"encoding/json"
"sort"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid"
)
// BLS
// SignatureBytes is the length of a BLS signature
const SignatureBytes = 96
// PrivateKeyBytes is the length of a BLS private key
const PrivateKeyBytes = 32
// PublicKeyBytes is the length of a BLS public key
const PublicKeyBytes = 48
// DigestBytes is the length of a BLS message hash/digest
const DigestBytes = 96
// Signature is a compressed affine
type Signature [SignatureBytes]byte
// PrivateKey is a compressed affine
type PrivateKey [PrivateKeyBytes]byte
// PublicKey is a compressed affine
type PublicKey [PublicKeyBytes]byte
// Message is a byte slice
type Message []byte
// Digest is a compressed affine
type Digest [DigestBytes]byte
// Used when generating a private key deterministically
type PrivateKeyGenSeed [32]byte
// Proofs
// SortedPublicSectorInfo is a slice of publicSectorInfo sorted
// (lexicographically, ascending) by sealed (replica) CID.
type SortedPublicSectorInfo struct {
f []publicSectorInfo
}
// SortedPrivateSectorInfo is a slice of PrivateSectorInfo sorted
// (lexicographically, ascending) by sealed (replica) CID.
type SortedPrivateSectorInfo struct {
f []PrivateSectorInfo
}
func newSortedPublicSectorInfo(sectorInfo ...publicSectorInfo) SortedPublicSectorInfo {
fn := func(i, j int) bool {
return bytes.Compare(sectorInfo[i].SealedCID.Bytes(), sectorInfo[j].SealedCID.Bytes()) == -1
}
sort.Slice(sectorInfo[:], fn)
return SortedPublicSectorInfo{
f: sectorInfo,
}
}
// Values returns the sorted publicSectorInfo as a slice
func (s *SortedPublicSectorInfo) Values() []publicSectorInfo {
return s.f
}
// MarshalJSON JSON-encodes and serializes the SortedPublicSectorInfo.
func (s SortedPublicSectorInfo) MarshalJSON() ([]byte, error) {
return json.Marshal(s.f)
}
// UnmarshalJSON parses the JSON-encoded byte slice and stores the result in the
// value pointed to by s.f. Note that this method allows for construction of a
// SortedPublicSectorInfo which violates its invariant (that its publicSectorInfo are sorted
// in some defined way). Callers should take care to never provide a byte slice
// which would violate this invariant.
func (s *SortedPublicSectorInfo) UnmarshalJSON(b []byte) error {
return json.Unmarshal(b, &s.f)
}
// NewSortedPrivateSectorInfo returns a SortedPrivateSectorInfo
func NewSortedPrivateSectorInfo(sectorInfo ...PrivateSectorInfo) SortedPrivateSectorInfo {
fn := func(i, j int) bool {
return bytes.Compare(sectorInfo[i].SealedCID.Bytes(), sectorInfo[j].SealedCID.Bytes()) == -1
}
sort.Slice(sectorInfo[:], fn)
return SortedPrivateSectorInfo{
f: sectorInfo,
}
}
// Values returns the sorted PrivateSectorInfo as a slice
func (s *SortedPrivateSectorInfo) Values() []PrivateSectorInfo {
return s.f
}
// MarshalJSON JSON-encodes and serializes the SortedPrivateSectorInfo.
func (s SortedPrivateSectorInfo) MarshalJSON() ([]byte, error) {
return json.Marshal(s.f)
}
func (s *SortedPrivateSectorInfo) UnmarshalJSON(b []byte) error {
return json.Unmarshal(b, &s.f)
}
type publicSectorInfo struct {
PoStProofType abi.RegisteredPoStProof
SealedCID cid.Cid
SectorNum abi.SectorNumber
}
type PrivateSectorInfo struct {
abi.SectorInfo
CacheDirPath string
PoStProofType abi.RegisteredPoStProof
SealedSectorPath string
}