Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit 1c16dd3

Browse files
fix: ed25519 PeerID generation (#186)
* Fix Ed25519 PeerID generation This commit pushes further fixes to the generation of Ed25519 peer IDs, building upon the discussion in ipfs/js-ipfs#3591 and the subsequent pull request #185. The purpose of this new pull request is to harmonize the encoding of PeerIDs for Ed25519 keys such that the same new format is used everywhere: peer IDs when assigned upon key generation, peer IDs when shown via key listing, as well as the peer IDs displayed as IPNS names when the key is used as the basis for an IPNS record. Concretely, this changes the peer ID representation of Ed25519 keys from the `Qm...` format to the newer `1...` format. The accompanying test has been modified accordingly. * Satisfy linter
1 parent 4e5a05a commit 1c16dd3

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"keypair": "^1.0.1",
4646
"multibase": "^3.0.0",
4747
"multicodec": "^2.0.0",
48+
"multihashes": "^4.0.2",
4849
"multihashing-async": "^2.0.1",
4950
"node-forge": "^0.10.0",
5051
"pem-jwk": "^2.0.0",

src/keys/ed25519-class.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ const sha = require('multihashing-async/src/sha')
44
const protobuf = require('protons')
55
const errcode = require('err-code')
66
const uint8ArrayEquals = require('uint8arrays/equals')
7-
const uint8ArrayToString = require('uint8arrays/to-string')
8-
7+
const mh = require('multihashes')
98
const crypto = require('./ed25519')
109
const pbm = protobuf(require('./keys.proto'))
1110
const exporter = require('./exporter')
@@ -84,8 +83,8 @@ class Ed25519PrivateKey {
8483
* @returns {Promise<String>}
8584
*/
8685
async id () {
87-
const hash = await this.public.hash()
88-
return uint8ArrayToString(hash, 'base58btc')
86+
const encoding = mh.encode(this.public.bytes, 'identity')
87+
return await mh.toB58String(encoding)
8988
}
9089

9190
/**

test/keys/ed25519.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('ed25519', function () {
8282
it('key id', async () => {
8383
const key = await crypto.keys.unmarshalPrivateKey(fixtures.verify.privateKey)
8484
const id = await key.id()
85-
expect(id).to.eql('QmUawW9qzMrBBiMrWQQMvoatadKZ9F4EwZCAMKnt3STLtz')
85+
expect(id).to.eql('12D3KooWLqLxEfJ9nDdEe8Kh8PFvNPQRYDQBwyL7CMM7HhVd5LsX')
8686
})
8787

8888
it('should export a password encrypted libp2p-key', async () => {

0 commit comments

Comments
 (0)