@@ -4,7 +4,7 @@ const ipns = require('ipns')
4
4
const crypto = require ( 'libp2p-crypto' )
5
5
const PeerId = require ( 'peer-id' )
6
6
const errcode = require ( 'err-code' )
7
- const parallel = require ( 'async/parallel ' )
7
+ const auto = require ( 'async/auto ' )
8
8
9
9
const debug = require ( 'debug' )
10
10
const log = debug ( 'jsipfs:ipns:resolver' )
@@ -100,13 +100,13 @@ class IpnsResolver {
100
100
101
101
const { routingKey, routingPubKey } = ipns . getIdKeys ( peerId . toBytes ( ) )
102
102
103
- parallel ( [
103
+ auto ( {
104
104
// Name should be the hash of a public key retrievable from ipfs.
105
105
// 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 ) {
110
110
if ( err . code !== 'ERR_NOT_FOUND' ) {
111
111
const errMsg = `unexpected error getting the ipns record ${ peerId . id } `
112
112
@@ -119,21 +119,24 @@ class IpnsResolver {
119
119
return callback ( errcode ( new Error ( errMsg ) , 'ERR_NO_RECORD_FOUND' ) )
120
120
}
121
121
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`
128
130
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
+ }
131
134
}
132
135
133
136
// IPNS entry
134
137
let ipnsEntry
135
138
try {
136
- ipnsEntry = ipns . unmarshal ( res [ 1 ] )
139
+ ipnsEntry = ipns . unmarshal ( res . record )
137
140
} catch ( err ) {
138
141
const errMsg = `found ipns record that we couldn't convert to a value`
139
142
0 commit comments