Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 21ba084

Browse files
committed
fix: publick key from routing
1 parent 5f8fbd3 commit 21ba084

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/core/ipns/resolver.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const ipns = require('ipns')
44
const crypto = require('libp2p-crypto')
55
const PeerId = require('peer-id')
66
const errcode = require('err-code')
7-
const parallel = require('async/parallel')
7+
const auto = require('async/auto')
88

99
const debug = require('debug')
1010
const log = debug('jsipfs:ipns:resolver')
@@ -100,13 +100,13 @@ class IpnsResolver {
100100

101101
const { routingKey, routingPubKey } = ipns.getIdKeys(peerId.toBytes())
102102

103-
parallel([
103+
auto({
104104
// Name should be the hash of a public key retrievable from ipfs.
105105
// We retrieve public key to add it to the PeerId, as the IPNS record may not have it.
106-
(cb) => this._routing.get(routingPubKey.toBuffer(), cb),
107-
(cb) => this._routing.get(routingKey.toBuffer(), cb)
108-
], (err, res) => {
109-
if (err) {
106+
pubKey: (cb) => this._routing.get(routingPubKey.toBuffer(), cb),
107+
record: (cb) => this._routing.get(routingKey.toBuffer(), cb)
108+
}, (err, res) => {
109+
if (err && !res.record) {
110110
if (err.code !== 'ERR_NOT_FOUND') {
111111
const errMsg = `unexpected error getting the ipns record ${peerId.id}`
112112

@@ -119,21 +119,24 @@ class IpnsResolver {
119119
return callback(errcode(new Error(errMsg), 'ERR_NO_RECORD_FOUND'))
120120
}
121121

122-
// Public key
123-
try {
124-
// Insert it into the peer id public key, to be validated by IPNS validator
125-
peerId.pubKey = crypto.keys.unmarshalPublicKey(res[0])
126-
} catch (err) {
127-
const errMsg = `found public key record that we couldn't convert to a value`
122+
// If public key was found in the routing, add it to the peer id
123+
// otherwise, wait to check if it is embedded in the record.
124+
if (res.pubKey) {
125+
try {
126+
// Insert it into the peer id public key, to be validated by IPNS validator
127+
peerId.pubKey = crypto.keys.unmarshalPublicKey(res.pubKey)
128+
} catch (err) {
129+
const errMsg = `found public key record that we couldn't convert to a value`
128130

129-
log.error(errMsg)
130-
return callback(errcode(new Error(errMsg), 'ERR_INVALID_PUB_KEY_RECEIVED'))
131+
log.error(errMsg)
132+
return callback(errcode(new Error(errMsg), 'ERR_INVALID_PUB_KEY_RECEIVED'))
133+
}
131134
}
132135

133136
// IPNS entry
134137
let ipnsEntry
135138
try {
136-
ipnsEntry = ipns.unmarshal(res[1])
139+
ipnsEntry = ipns.unmarshal(res.record)
137140
} catch (err) {
138141
const errMsg = `found ipns record that we couldn't convert to a value`
139142

0 commit comments

Comments
 (0)