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

fix: revert libp2p records being signed for ipns #1570

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 22 additions & 36 deletions src/core/ipns/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IpnsPublisher {
return callback(err)
}

this._putRecordToRouting(record, peerId, privKey, callback)
this._putRecordToRouting(record, peerId, callback)
})
})
}
Expand All @@ -50,7 +50,7 @@ class IpnsPublisher {
this.publishWithEOL(privKey, value, defaultRecordTtl, callback)
}

_putRecordToRouting (record, peerId, privKey, callback) {
_putRecordToRouting (record, peerId, callback) {
if (!(peerId instanceof PeerId)) {
const errMsg = `peerId received is not valid`

Expand All @@ -74,10 +74,10 @@ class IpnsPublisher {
}

series([
(cb) => this._publishEntry(keys.ipnsKey, embedPublicKeyRecord || record, peerId, privKey, cb),
(cb) => this._publishEntry(keys.ipnsKey, embedPublicKeyRecord || record, peerId, cb),
// Publish the public key if a public key cannot be extracted from the ID
// We will be able to deprecate this part in the future, since the public keys will be only in the peerId
(cb) => embedPublicKeyRecord ? this._publishPublicKey(keys.pkKey, publicKey, peerId, privKey, cb) : cb()
(cb) => embedPublicKeyRecord ? this._publishPublicKey(keys.pkKey, publicKey, peerId, cb) : cb()
], (err) => {
if (err) {
log.error(err)
Expand All @@ -89,7 +89,7 @@ class IpnsPublisher {
})
}

_publishEntry (key, entry, peerId, privKey, callback) {
_publishEntry (key, entry, peerId, callback) {
if (!(key instanceof Key)) {
const errMsg = `datastore key does not have a valid format`

Expand All @@ -108,28 +108,21 @@ class IpnsPublisher {
return callback(err)
}

rec.serializeSigned(privKey, (err, serializedRecord) => {
// TODO Routing - this should be replaced by a put to the DHT
this._repo.datastore.put(key, rec.serialize(), (err, res) => {
if (err) {
log.error(err)
return callback(err)
}

// TODO Routing - this should be replaced by a put to the DHT
this._repo.datastore.put(key, serializedRecord, (err, res) => {
if (err) {
const errMsg = `ipns record for ${key.toString()} could not be stored in the routing`
const errMsg = `ipns record for ${key.toString()} could not be stored in the routing`

log.error(errMsg)
return callback(errcode(new Error(errMsg), 'ERR_STORING_IN_DATASTORE'))
}
log.error(errMsg)
return callback(errcode(new Error(errMsg), 'ERR_STORING_IN_DATASTORE'))
}

log(`ipns record for ${key.toString()} was stored in the routing`)
callback(null, res)
})
log(`ipns record for ${key.toString()} was stored in the routing`)
callback(null, res)
})
}

_publishPublicKey (key, publicKey, peerId, privKey, callback) {
_publishPublicKey (key, publicKey, peerId, callback) {
if (!(key instanceof Key)) {
const errMsg = `datastore key does not have a valid format`

Expand All @@ -153,24 +146,17 @@ class IpnsPublisher {
return callback(err)
}

rec.serializeSigned(privKey, (err, serializedRecord) => {
// TODO Routing - this should be replaced by a put to the DHT
this._repo.datastore.put(key, rec.serialize(), (err, res) => {
if (err) {
log.error(err)
return callback(err)
}

// TODO Routing - this should be replaced by a put to the DHT
this._repo.datastore.put(key, serializedRecord, (err, res) => {
if (err) {
const errMsg = `public key for ${key.toString()} could not be stored in the routing`
const errMsg = `public key for ${key.toString()} could not be stored in the routing`

log.error(errMsg)
return callback(errcode(new Error(errMsg), 'ERR_STORING_IN_DATASTORE'))
}
log.error(errMsg)
return callback(errcode(new Error(errMsg), 'ERR_STORING_IN_DATASTORE'))
}

log(`public key for ${key.toString()} was stored in the routing`)
callback(null, res)
})
log(`public key for ${key.toString()} was stored in the routing`)
callback(null, res)
})
}

Expand Down
13 changes: 3 additions & 10 deletions src/core/ipns/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,13 @@ class IpnsResolver {
return callback(err)
}

// libp2p record signature validation
record.verifySignature(pubKey, (err) => {
// IPNS entry validation
ipns.validate(pubKey, ipnsEntry, (err) => {
if (err) {
return callback(err)
}

// IPNS entry validation
ipns.validate(pubKey, ipnsEntry, (err) => {
if (err) {
return callback(err)
}

callback(null, ipnsEntry.value.toString())
})
callback(null, ipnsEntry.value.toString())
})
})
})
Expand Down