Skip to content

Commit

Permalink
fix: key encoding (#48)
Browse files Browse the repository at this point in the history
The boolean argument to `new Key` specifies whether to try to clean
the key up - remove trailing slashes, etc.

Here we're putting potentially non-printable characters into the
key so we don't want to do any such operation.

fixes ipfs/js-ipfs#2930
  • Loading branch information
achingbrain authored Jun 22, 2020
1 parent 7d3c49c commit 7c6c672
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ const getIdKeys = (pid) => {
const ipnsBuffer = Buffer.from('/ipns/')

return {
routingPubKey: new Key(Buffer.concat([pkBuffer, pid])), // Added on https://github.com/ipfs/js-ipns/pull/8#issue-213857876 (pkKey will be deprecated in a future release)
routingPubKey: new Key(Buffer.concat([pkBuffer, pid]), false), // Added on https://github.com/ipfs/js-ipns/pull/8#issue-213857876 (pkKey will be deprecated in a future release)
pkKey: new Key(rawStdEncoding(Buffer.concat([pkBuffer, pid]))),
routingKey: new Key(Buffer.concat([ipnsBuffer, pid])), // Added on https://github.com/ipfs/js-ipns/pull/6#issue-213631461 (ipnsKey will be deprecated in a future release)
routingKey: new Key(Buffer.concat([ipnsBuffer, pid]), false), // Added on https://github.com/ipfs/js-ipns/pull/6#issue-213631461 (ipnsKey will be deprecated in a future release)
ipnsKey: new Key(rawStdEncoding(Buffer.concat([ipnsBuffer, pid])))
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const expect = chai.expect
chai.use(dirtyChai)
chai.use(chaiBytes)
chai.use(chaiString)
const { toB58String } = require('multihashes')

const ipfs = require('ipfs')
const ipfsHttpClient = require('ipfs-http-client')
Expand Down Expand Up @@ -157,6 +158,20 @@ describe('ipns', function () {
expect(idKeys.routingKey).to.not.startsWith('/ipns/')
})

it('should be able to turn routing key back into id', () => {
const keys = [
'QmQd5Enz5tzP8u5wHur8ADuJMbcNhEf86CkWkqRzoWUhst',
'QmW6mcoqDKJRch2oph2FmvZhPLJn6wPU648Vv9iMyMtmtG'
]

keys.forEach(key => {
const { routingKey } = ipns.getIdKeys(fromB58String(key))
const id = toB58String(routingKey.toBuffer().slice(ipns.namespaceLength))

expect(id).to.equal(key)
})
})

it('should be able to embed a public key in an ipns record', async () => {
const sequence = 0
const validity = 1000000
Expand Down

0 comments on commit 7c6c672

Please sign in to comment.