mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-31 16:32:01 +00:00
fix: expose getPublicKey (#1188)
This is used externally by IPFS so expose the method
This commit is contained in:
@@ -244,9 +244,6 @@ export class DefaultDialer implements Dialer, Startable {
|
||||
const addrs: Multiaddr[] = []
|
||||
for (const a of knownAddrs) {
|
||||
const resolvedAddrs = await this._resolve(a)
|
||||
|
||||
log('resolved %s to %s', a, resolvedAddrs)
|
||||
|
||||
resolvedAddrs.forEach(ra => addrs.push(ra))
|
||||
}
|
||||
|
||||
|
@@ -223,6 +223,12 @@ export interface Libp2p extends Startable, EventEmitter<Libp2pEvents> {
|
||||
* Sends a request to fetch the value associated with the given key from the given peer.
|
||||
*/
|
||||
fetch: (peer: PeerId | Multiaddr | string, key: string) => Promise<Uint8Array | null>
|
||||
|
||||
/**
|
||||
* Returns the public key for the passed PeerId. If the PeerId is of the 'RSA' type
|
||||
* this may mean searching the DHT if the key is not present in the KeyStore.
|
||||
*/
|
||||
getPublicKey: (peer: PeerId, options?: AbortOptions) => Promise<Uint8Array>
|
||||
}
|
||||
|
||||
export type Libp2pOptions = RecursivePartial<Libp2pInit>
|
||||
|
@@ -412,9 +412,13 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
|
||||
/**
|
||||
* Get the public key for the given peer id
|
||||
*/
|
||||
async getPublicKey (peer: PeerId, options: AbortOptions = {}) {
|
||||
async getPublicKey (peer: PeerId, options: AbortOptions = {}): Promise<Uint8Array> {
|
||||
log('getPublicKey %p', peer)
|
||||
|
||||
if (peer.publicKey != null) {
|
||||
return peer.publicKey
|
||||
}
|
||||
|
||||
const peerInfo = await this.peerStore.get(peer)
|
||||
|
||||
if (peerInfo.pubKey != null) {
|
||||
@@ -437,7 +441,7 @@ export class Libp2pNode extends EventEmitter<Libp2pEvents> implements Libp2p {
|
||||
|
||||
await this.peerStore.keyBook.set(peer, event.value)
|
||||
|
||||
return key
|
||||
return key.bytes
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user