@@ -40,7 +40,7 @@ class IpnsPublisher {
40
40
return callback ( err )
41
41
}
42
42
43
- this . _putRecordToRouting ( record , peerId , callback )
43
+ this . _putRecordToRouting ( record , peerId , privKey , callback )
44
44
} )
45
45
} )
46
46
}
@@ -50,7 +50,7 @@ class IpnsPublisher {
50
50
this . publishWithEOL ( privKey , value , defaultRecordTtl , callback )
51
51
}
52
52
53
- _putRecordToRouting ( record , peerId , callback ) {
53
+ _putRecordToRouting ( record , peerId , privKey , callback ) {
54
54
if ( ! ( peerId instanceof PeerId ) ) {
55
55
const errMsg = `peerId received is not valid`
56
56
@@ -74,10 +74,10 @@ class IpnsPublisher {
74
74
}
75
75
76
76
series ( [
77
- ( cb ) => this . _publishEntry ( keys . ipnsKey , embedPublicKeyRecord || record , peerId , cb ) ,
77
+ ( cb ) => this . _publishEntry ( keys . ipnsKey , embedPublicKeyRecord || record , peerId , privKey , cb ) ,
78
78
// Publish the public key if a public key cannot be extracted from the ID
79
79
// We will be able to deprecate this part in the future, since the public keys will be only in the peerId
80
- ( cb ) => embedPublicKeyRecord ? this . _publishPublicKey ( keys . pkKey , publicKey , peerId , cb ) : cb ( )
80
+ ( cb ) => embedPublicKeyRecord ? this . _publishPublicKey ( keys . pkKey , publicKey , peerId , privKey , cb ) : cb ( )
81
81
] , ( err ) => {
82
82
if ( err ) {
83
83
log . error ( err )
@@ -89,7 +89,7 @@ class IpnsPublisher {
89
89
} )
90
90
}
91
91
92
- _publishEntry ( key , entry , peerId , callback ) {
92
+ _publishEntry ( key , entry , peerId , privKey , callback ) {
93
93
if ( ! ( key instanceof Key ) ) {
94
94
const errMsg = `datastore key does not have a valid format`
95
95
@@ -108,21 +108,28 @@ class IpnsPublisher {
108
108
return callback ( err )
109
109
}
110
110
111
- // TODO Routing - this should be replaced by a put to the DHT
112
- this . _repo . datastore . put ( key , rec . serialize ( ) , ( err , res ) => {
111
+ rec . serializeSigned ( privKey , ( err , serializedRecord ) => {
113
112
if ( err ) {
114
- const errMsg = `ipns record for ${ key . toString ( ) } could not be stored in the routing`
115
-
116
- log . error ( errMsg )
117
- return callback ( errcode ( new Error ( errMsg ) , 'ERR_STORING_IN_DATASTORE' ) )
113
+ log . error ( err )
114
+ return callback ( err )
118
115
}
119
116
120
- log ( `ipns record for ${ key . toString ( ) } was stored in the routing` )
121
- callback ( null , res )
117
+ // TODO Routing - this should be replaced by a put to the DHT
118
+ this . _repo . datastore . put ( key , serializedRecord , ( err , res ) => {
119
+ if ( err ) {
120
+ const errMsg = `ipns record for ${ key . toString ( ) } could not be stored in the routing`
121
+
122
+ log . error ( errMsg )
123
+ return callback ( errcode ( new Error ( errMsg ) , 'ERR_STORING_IN_DATASTORE' ) )
124
+ }
125
+
126
+ log ( `ipns record for ${ key . toString ( ) } was stored in the routing` )
127
+ callback ( null , res )
128
+ } )
122
129
} )
123
130
}
124
131
125
- _publishPublicKey ( key , publicKey , peerId , callback ) {
132
+ _publishPublicKey ( key , publicKey , peerId , privKey , callback ) {
126
133
if ( ! ( key instanceof Key ) ) {
127
134
const errMsg = `datastore key does not have a valid format`
128
135
@@ -146,17 +153,24 @@ class IpnsPublisher {
146
153
return callback ( err )
147
154
}
148
155
149
- // TODO Routing - this should be replaced by a put to the DHT
150
- this . _repo . datastore . put ( key , rec . serialize ( ) , ( err , res ) => {
156
+ rec . serializeSigned ( privKey , ( err , serializedRecord ) => {
151
157
if ( err ) {
152
- const errMsg = `public key for ${ key . toString ( ) } could not be stored in the routing`
153
-
154
- log . error ( errMsg )
155
- return callback ( errcode ( new Error ( errMsg ) , 'ERR_STORING_IN_DATASTORE' ) )
158
+ log . error ( err )
159
+ return callback ( err )
156
160
}
157
161
158
- log ( `public key for ${ key . toString ( ) } was stored in the routing` )
159
- callback ( null , res )
162
+ // TODO Routing - this should be replaced by a put to the DHT
163
+ this . _repo . datastore . put ( key , serializedRecord , ( err , res ) => {
164
+ if ( err ) {
165
+ const errMsg = `public key for ${ key . toString ( ) } could not be stored in the routing`
166
+
167
+ log . error ( errMsg )
168
+ return callback ( errcode ( new Error ( errMsg ) , 'ERR_STORING_IN_DATASTORE' ) )
169
+ }
170
+
171
+ log ( `public key for ${ key . toString ( ) } was stored in the routing` )
172
+ callback ( null , res )
173
+ } )
160
174
} )
161
175
}
162
176
0 commit comments