Conversation
src/errors.js
Outdated
| exports.ERR_SIGNATURE_VERIFICATION = 'ERR_SIGNATURE_VERIFICATION' | ||
| exports.ERR_UNRECOGNIZED_FORMAT = 'ERR_UNRECOGNIZED_FORMAT' | ||
| exports.ERR_PEER_ID_FROM_PUBLIC_KEY = 'ERR_PEER_ID_FROM_PUBLIC_KEY' | ||
| exports.ERR_PUBLICK_KEY_FROM_ID = 'ERR_PUBLICK_KEY_FROM_ID' |
src/index.js
Outdated
| const NanoDate = require('nano-date').default | ||
| const { Key } = require('interface-datastore') | ||
| const crypto = require('libp2p-crypto') | ||
| const peerId = require('peer-id') |
There was a problem hiding this comment.
I would import this as PeerId - it is a class and saves you having to use peerIdResult to differentiate between this and a peer ID instance.
src/index.js
Outdated
| const { parseRFC3339 } = require('./utils') | ||
| const ERRORS = require('./errors') | ||
|
|
||
| const ID_MULTIHASH_CODE = 0 |
There was a problem hiding this comment.
Can this be imported from multihashes? If not then it needs a comment to explain what it is.
There was a problem hiding this comment.
Just created a PR multiformats/js-multihash#57 for that 🙂
src/index.js
Outdated
| if (err) { | ||
| const error = 'cannot create peer id from the public key' | ||
|
|
||
| log.error(error) |
There was a problem hiding this comment.
Much more useful to log err than the message
src/index.js
Outdated
| const error = 'cannot create peer id from the public key' | ||
|
|
||
| log.error(error) | ||
| return callback(Object.assign(new Error(error), { code: ERRORS.ERR_PEER_ID_FROM_PUBLIC_KEY })) |
There was a problem hiding this comment.
Either assign the code to err or use a module like explain-error to retain the stack.
src/index.js
Outdated
|
|
||
| // If we vailed to extract the public key from the peer ID, embed it in the record. | ||
| entry.pubKey = crypto.keys.marshalPublicKey(publicKey) | ||
| return callback(null, entry) |
There was a problem hiding this comment.
Minor, no need to return a call to callback when it's the last statement of the function.
| return callback(null, pubKey) | ||
| } else { | ||
| return callback(null, peerId.pubKey) | ||
| } |
There was a problem hiding this comment.
Minor, use if with a single return or if & else with no returns.
src/index.js
Outdated
| const extractPublicKey = (peerId, entry, callback) => { | ||
| callback(new Error('not implemented yet')) | ||
| if (entry.pubKey) { | ||
| const pubKey = crypto.keys.unmarshalPublicKey(entry.pubKey) |
src/index.js
Outdated
| if (validityType.toString() === '0') { | ||
| return 'EOL' | ||
| } else { | ||
| log.error('unrecognized validity type') |
There was a problem hiding this comment.
Put the validityType in the log message for better debugging
src/index.js
Outdated
| * Format: ${base32(/ipns/<HASH>)}, ${base32(/pk/<HASH>)} | ||
| * | ||
| * @param {Buffer} key peer identifier object. | ||
| * @param {Buffer} pid peer identifier object. |
There was a problem hiding this comment.
Not specifically an object, a buffer. Does this need an explanation of how you might extract this from a PeerId instance?
… into feat/add-public-key-support
alanshaw
left a comment
There was a problem hiding this comment.
Nice! Just a few small issues to clean up and this will be gtg.
src/index.js
Outdated
| try { | ||
| const pubKey = crypto.keys.unmarshalPublicKey(entry.pubKey) | ||
|
|
||
| return callback(null, pubKey) |
There was a problem hiding this comment.
Avoid callback in a try block - if the callback throws, it'll be caught and the callback will be called again - very hard to debug!
| * @param {function(Error)} [callback] | ||
| * @return {Void} | ||
| */ | ||
| const embedPublicKey = (publicKey, entry, callback) => { |
There was a problem hiding this comment.
Check publicKey, publicKey.bytes and entry exist?
src/index.js
Outdated
| } | ||
|
|
||
| // If we failed to extract the public key from the peer ID, embed it in the record. | ||
| entry.pubKey = crypto.keys.marshalPublicKey(publicKey) |
| @@ -120,7 +153,17 @@ const embedPublicKey = (publicKey, entry, callback) => { | |||
| * @return {Void} | |||
| */ | |||
| const extractPublicKey = (peerId, entry, callback) => { | |||
package.json
Outdated
| "ipfsd-ctl": "^0.36.0", | ||
| "libp2p-crypto": "^0.13.0", | ||
| "multihashes": "^0.4.13" | ||
| "libp2p-crypto": "^0.13.0" |
There was a problem hiding this comment.
This needs to move to dependencies
A working version of **IPNS working locally** is here! 🚀 😎 💪 Steps: - [x] Create a new repo (**js-ipns**) like it was made with go in the last week ([go-ipns](https://github.com/ipfs/go-ipns)) and port the related code from this PR to there - [x] Resolve IPNS names in publish, in order to verify if they exist (as it is being done for regular files) before being published - [x] Handle remaining parameters in publish and resolve (except ttl). - [x] Test interface core spec [interface-ipfs-core#327](ipfs-inactive/interface-js-ipfs-core#327) - [x] Test interoperability with go. [interop#26](ipfs/interop#26) - [x] Integrate logging - [x] Write unit tests - [x] Add support for the lifetime with nanoseconds precision - [x] Add Cache - [x] Add initializeKeyspace - [x] Republish Some notes, regarding the previous steps: - There is an optional parameter not implemented in this PR, which is `ttl`, since it is still experimental, we can add it in a separate PR. Finally, thanks @Stebalien for your help and time answering all my questions regarding the IPNS implementation in GO. Moreover, since there are no specs, and not that much documentation, I have been writing a document with all the IPNS workflow. It is a WIP by now, but it is currently available [here](ipfs/specs#184). Related PRs: - [x] [js-ipns#4](ipfs/js-ipns#4) - [x] [js-ipfs-repo#173](ipfs/js-ipfs-repo#173) - [x] [js-ipfs#1496](#1496) - [x] [interface-ipfs-core#327](ipfs-inactive/interface-js-ipfs-core#327) - [x] enable `interface-ipfs-core` tests for IPNS in `js-ipfs`
Adding public key methods for allowing full interop with
go-ipfs