@@ -7,6 +7,7 @@ log.error = debug('libp2p:peer-store:error')
7
7
8
8
const { EventEmitter } = require ( 'events' )
9
9
10
+ const PeerId = require ( 'peer-id' )
10
11
const PeerInfo = require ( 'peer-info' )
11
12
12
13
/**
@@ -160,10 +161,15 @@ class PeerStore extends EventEmitter {
160
161
161
162
/**
162
163
* Get the info to the given id.
163
- * @param {string } peerId b58str id
164
+ * @param {PeerId| string } peerId b58str id
164
165
* @returns {PeerInfo }
165
166
*/
166
167
get ( peerId ) {
168
+ // TODO: deprecate this and just accept `PeerId` instances
169
+ if ( PeerId . isPeerId ( peerId ) ) {
170
+ peerId = peerId . toB58String ( )
171
+ }
172
+
167
173
const peerInfo = this . peers . get ( peerId )
168
174
169
175
if ( peerInfo ) {
@@ -175,19 +181,29 @@ class PeerStore extends EventEmitter {
175
181
176
182
/**
177
183
* Has the info to the given id.
178
- * @param {string } peerId b58str id
184
+ * @param {PeerId| string } peerId b58str id
179
185
* @returns {boolean }
180
186
*/
181
187
has ( peerId ) {
188
+ // TODO: deprecate this and just accept `PeerId` instances
189
+ if ( PeerId . isPeerId ( peerId ) ) {
190
+ peerId = peerId . toB58String ( )
191
+ }
192
+
182
193
return this . peers . has ( peerId )
183
194
}
184
195
185
196
/**
186
197
* Removes the Peer with the matching `peerId` from the PeerStore
187
- * @param {string } peerId b58str id
198
+ * @param {PeerId| string } peerId b58str id
188
199
* @returns {boolean } true if found and removed
189
200
*/
190
201
remove ( peerId ) {
202
+ // TODO: deprecate this and just accept `PeerId` instances
203
+ if ( PeerId . isPeerId ( peerId ) ) {
204
+ peerId = peerId . toB58String ( )
205
+ }
206
+
191
207
return this . peers . delete ( peerId )
192
208
}
193
209
0 commit comments