@@ -20,12 +20,14 @@ var serializeIp = ipUtils.ipAndPortToBuffer;
20
20
21
21
var SHA256_HASH_SIZE = constants . SHA256_HASH_SIZE ;
22
22
var PUBKEY_ID_SIZE = constants . PUBKEY_ID_SIZE ;
23
+ var BLS_PUBLIC_KEY_SIZE = constants . BLS_PUBLIC_KEY_SIZE ;
23
24
24
25
/**
25
26
* @typedef {Object } SMLEntry
26
- * @property {string } proRegTxHash uint256
27
+ * @property {string } proRegTxHash
28
+ * @property {string } confirmedHash
27
29
* @property {string } service - ip and port
28
- * @property {string } keyIDOperator - public key hash, 20 bytes
30
+ * @property {string } pubKeyOperator - operator public key
29
31
* @property {string } keyIDVoting - public key hash, 20 bytes
30
32
* @property {boolean } isValid
31
33
*/
@@ -34,9 +36,10 @@ var PUBKEY_ID_SIZE = constants.PUBKEY_ID_SIZE;
34
36
* @class SimplifiedMNListEntry
35
37
* @param {* } arg - A Buffer, JSON string, or Object representing a SmlEntry
36
38
* @constructor
37
- * @property {string } proRegTxHash uint256
39
+ * @property {string } proRegTxHash
40
+ * @property {string } confirmedHash
38
41
* @property {string } service - ip and port
39
- * @property {string } keyIDOperator - public key hash, 20 bytes
42
+ * @property {string } pubKeyOperator - operator public key
40
43
* @property {string } keyIDVoting - public key hash, 20 bytes
41
44
* @property {boolean } isValid
42
45
*/
@@ -67,10 +70,11 @@ SimplifiedMNListEntry.fromBuffer = function fromBuffer(buffer) {
67
70
var bufferReader = new BufferReader ( buffer ) ;
68
71
69
72
return SimplifiedMNListEntry . fromObject ( {
70
- proRegTxHash : bufferReader . read ( SHA256_HASH_SIZE ) . toString ( 'hex' ) ,
73
+ proRegTxHash : bufferReader . read ( SHA256_HASH_SIZE ) . reverse ( ) . toString ( 'hex' ) ,
74
+ confirmedHash : bufferReader . read ( SHA256_HASH_SIZE ) . reverse ( ) . toString ( 'hex' ) ,
71
75
service : parseIp ( bufferReader . read ( ipUtils . IP_AND_PORT_SIZE ) ) ,
72
- keyIDOperator : bufferReader . read ( PUBKEY_ID_SIZE ) . toString ( 'hex' ) ,
73
- keyIDVoting : bufferReader . read ( PUBKEY_ID_SIZE ) . toString ( 'hex' ) ,
76
+ pubKeyOperator : bufferReader . read ( BLS_PUBLIC_KEY_SIZE ) . toString ( 'hex' ) ,
77
+ keyIDVoting : bufferReader . read ( PUBKEY_ID_SIZE ) . reverse ( ) . toString ( 'hex' ) ,
74
78
isValid : Boolean ( bufferReader . readUInt8 ( ) )
75
79
} ) ;
76
80
} ;
@@ -91,10 +95,11 @@ SimplifiedMNListEntry.prototype.toBuffer = function toBuffer() {
91
95
this . validate ( ) ;
92
96
var bufferWriter = new BufferWriter ( ) ;
93
97
94
- bufferWriter . write ( Buffer . from ( this . proRegTxHash , 'hex' ) ) ;
98
+ bufferWriter . write ( Buffer . from ( this . proRegTxHash , 'hex' ) . reverse ( ) ) ;
99
+ bufferWriter . write ( Buffer . from ( this . confirmedHash , 'hex' ) . reverse ( ) ) ;
95
100
bufferWriter . write ( serializeIp ( this . service ) ) ;
96
- bufferWriter . write ( Buffer . from ( this . keyIDOperator , 'hex' ) ) ;
97
- bufferWriter . write ( Buffer . from ( this . keyIDVoting , 'hex' ) ) ;
101
+ bufferWriter . write ( Buffer . from ( this . pubKeyOperator , 'hex' ) ) ;
102
+ bufferWriter . write ( Buffer . from ( this . keyIDVoting , 'hex' ) . reverse ( ) ) ;
98
103
bufferWriter . writeUInt8 ( Number ( this . isValid ) ) ;
99
104
100
105
return bufferWriter . toBuffer ( ) ;
@@ -108,8 +113,9 @@ SimplifiedMNListEntry.prototype.toBuffer = function toBuffer() {
108
113
SimplifiedMNListEntry . fromObject = function fromObject ( obj ) {
109
114
var SMLEntry = new SimplifiedMNListEntry ( ) ;
110
115
SMLEntry . proRegTxHash = obj . proRegTxHash ;
116
+ SMLEntry . confirmedHash = obj . confirmedHash ;
111
117
SMLEntry . service = obj . service ;
112
- SMLEntry . keyIDOperator = obj . keyIDOperator ;
118
+ SMLEntry . pubKeyOperator = obj . pubKeyOperator ;
113
119
SMLEntry . keyIDVoting = obj . keyIDVoting ;
114
120
SMLEntry . isValid = obj . isValid ;
115
121
@@ -119,22 +125,24 @@ SimplifiedMNListEntry.fromObject = function fromObject(obj) {
119
125
120
126
SimplifiedMNListEntry . prototype . validate = function validate ( ) {
121
127
$ . checkArgument ( isSha256 ( this . proRegTxHash ) , 'Expected proRegTxHash to be a sha256 hex string' ) ;
128
+ $ . checkArgument ( isSha256 ( this . confirmedHash ) , 'Expected confirmedHash to be a sha256 hex string' ) ;
122
129
if ( ! ipUtils . isZeroAddress ( this . service ) ) {
123
130
$ . checkArgument ( ipUtils . isIPV4 ( this . service ) , 'Expected service to be a string with ip address and port' ) ;
124
131
}
125
132
if ( ! isHexStringOfSize ( this . keyIDVoting , PUBKEY_ID_SIZE * 2 ) ) {
126
133
console . log ( this . keyIDVoting ) ;
127
134
}
128
- $ . checkArgument ( isHexStringOfSize ( this . keyIDOperator , PUBKEY_ID_SIZE * 2 ) , 'Expected keyIDOperator to be a pubkey id' ) ;
135
+ $ . checkArgument ( isHexStringOfSize ( this . pubKeyOperator , BLS_PUBLIC_KEY_SIZE * 2 ) , 'Expected pubKeyOperator to be a pubkey id' ) ;
129
136
$ . checkArgument ( isHexStringOfSize ( this . keyIDVoting , PUBKEY_ID_SIZE * 2 ) , 'Expected keyIDVoting to be a pubkey id' ) ;
130
137
$ . checkArgument ( typeof this . isValid === 'boolean' , 'Expected isValid to be a boolean' ) ;
131
138
} ;
132
139
133
140
SimplifiedMNListEntry . prototype . toObject = function toObject ( ) {
134
141
return {
135
142
proRegTxHash : this . proRegTxHash ,
143
+ confirmedHash : this . confirmedHash ,
136
144
service : this . service ,
137
- keyIDOperator : this . keyIDOperator ,
145
+ pubKeyOperator : this . pubKeyOperator ,
138
146
keyIDVoting : this . keyIDVoting ,
139
147
isValid : this . isValid
140
148
} ;
@@ -143,7 +151,7 @@ SimplifiedMNListEntry.prototype.toObject = function toObject() {
143
151
/**
144
152
* @return {Buffer }
145
153
*/
146
- SimplifiedMNListEntry . prototype . getHash = function hash ( ) {
154
+ SimplifiedMNListEntry . prototype . calculateHash = function calculateHash ( ) {
147
155
return Hash . sha256sha256 ( this . toBuffer ( ) ) ;
148
156
} ;
149
157
0 commit comments