-
Notifications
You must be signed in to change notification settings - Fork 458
/
schema.ts
157 lines (150 loc) · 3.42 KB
/
schema.ts
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
/*
* Copyright © 2021 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/
import {
HASH_LENGTH,
BLS_SIGNATURE_LENGTH,
MAX_LENGTH_AGGREGATION_BITS,
} from '../../../modules/interoperability/constants';
import { ADDRESS_LENGTH } from '../../../modules/validators/constants';
/**
* @see https://github.com/LiskHQ/lips/blob/main/proposals/lip-0061.md#schema
*/
export const unsignedCertificateSchema = {
$id: '/consensus/unsignedCertificate',
type: 'object',
required: ['blockID', 'height', 'timestamp', 'stateRoot', 'validatorsHash'],
properties: {
blockID: {
dataType: 'bytes',
minLength: HASH_LENGTH,
maxLength: HASH_LENGTH,
fieldNumber: 1,
},
height: {
dataType: 'uint32',
fieldNumber: 2,
},
timestamp: {
dataType: 'uint32',
fieldNumber: 3,
},
stateRoot: {
dataType: 'bytes',
minLength: HASH_LENGTH,
maxLength: HASH_LENGTH,
fieldNumber: 4,
},
validatorsHash: {
dataType: 'bytes',
minLength: HASH_LENGTH,
maxLength: HASH_LENGTH,
fieldNumber: 5,
},
},
};
/**
* @see https://github.com/LiskHQ/lips/blob/main/proposals/lip-0061.md#schema
*/
export const certificateSchema = {
$id: '/consensus/certificate',
type: 'object',
required: [...unsignedCertificateSchema.required, 'aggregationBits', 'signature'],
properties: {
...unsignedCertificateSchema.properties,
timestamp: {
minimum: 1,
dataType: 'uint32',
fieldNumber: 3,
},
aggregationBits: {
dataType: 'bytes',
fieldNumber: 6,
maxLength: MAX_LENGTH_AGGREGATION_BITS,
},
signature: {
dataType: 'bytes',
minLength: BLS_SIGNATURE_LENGTH,
maxLength: BLS_SIGNATURE_LENGTH,
fieldNumber: 7,
},
},
};
export const singleCommitSchema = {
$id: '/consensus/singleCommit',
type: 'object',
required: ['blockID', 'height', 'validatorAddress', 'certificateSignature'],
properties: {
blockID: {
dataType: 'bytes',
fieldNumber: 1,
minLength: HASH_LENGTH,
maxLength: HASH_LENGTH,
},
height: {
dataType: 'uint32',
fieldNumber: 2,
},
validatorAddress: {
dataType: 'bytes',
minLength: ADDRESS_LENGTH,
maxLength: ADDRESS_LENGTH,
fieldNumber: 3,
format: 'lisk32',
},
certificateSignature: {
dataType: 'bytes',
fieldNumber: 4,
minLength: BLS_SIGNATURE_LENGTH,
maxLength: BLS_SIGNATURE_LENGTH,
},
},
};
export interface SingleCommitsNetworkPacket {
commits: Buffer[];
}
export const singleCommitsNetworkPacketSchema = {
$id: '/consensus/singleCommitsNetworkPacket',
type: 'object',
required: ['commits'],
properties: {
commits: {
type: 'array',
fieldNumber: 1,
items: {
dataType: 'bytes',
},
},
},
};
export const aggregateCommitSchema = {
$id: '/consensus/aggregateCommit',
type: 'object',
required: ['height', 'aggregationBits', 'certificateSignature'],
properties: {
height: {
dataType: 'uint32',
fieldNumber: 1,
},
aggregationBits: {
dataType: 'bytes',
fieldNumber: 2,
},
certificateSignature: {
dataType: 'bytes',
minLength: BLS_SIGNATURE_LENGTH,
maxLength: BLS_SIGNATURE_LENGTH,
fieldNumber: 3,
},
},
};