Compare commits

...

7 Commits

Author SHA1 Message Date
Pavel Murygin
dee91b8d97 bump dependencies 2021-04-09 13:06:17 +03:00
Jacob Heun
a05e870c45
chore: release version v0.19.2 2021-03-17 19:03:03 +01:00
Jacob Heun
bc681c76f4
chore: update contributors 2021-03-17 19:03:02 +01:00
Nadim Kobeissi
1c16dd3dec
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 libp2p/js-libp2p-crypto#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
2021-03-17 19:01:53 +01:00
Jacob Heun
4e5a05a12c
chore: release version v0.19.1 2021-03-15 19:13:28 +01:00
Jacob Heun
c067685f45
chore: update contributors 2021-03-15 19:13:28 +01:00
Nadim Kobeissi
bc337698b6
fix: ed25519 key ID generation
As discussed here: https://github.com/ipfs/js-ipfs/issues/3591

Satisfy linter

test: actually verify ids
2021-03-15 19:02:31 +01:00
6 changed files with 45 additions and 24 deletions

View File

@ -1,3 +1,23 @@
<a name="0.19.2"></a>
## [0.19.2](https://github.com/libp2p/js-libp2p-crypto/compare/v0.19.1...v0.19.2) (2021-03-17)
### Bug Fixes
* ed25519 PeerID generation ([#186](https://github.com/libp2p/js-libp2p-crypto/issues/186)) ([1c16dd3](https://github.com/libp2p/js-libp2p-crypto/commit/1c16dd3)), closes [ipfs/js-ipfs#3591](https://github.com/ipfs/js-ipfs/issues/3591) [libp2p/js-libp2p-crypto#185](https://github.com/libp2p/js-libp2p-crypto/issues/185)
<a name="0.19.1"></a>
## [0.19.1](https://github.com/libp2p/js-libp2p-crypto/compare/v0.19.0...v0.19.1) (2021-03-15)
### Bug Fixes
* ed25519 key ID generation ([bc33769](https://github.com/libp2p/js-libp2p-crypto/commit/bc33769))
<a name="0.19.0"></a> <a name="0.19.0"></a>
# [0.19.0](https://github.com/libp2p/js-libp2p-crypto/compare/v0.18.0...v0.19.0) (2021-01-15) # [0.19.0](https://github.com/libp2p/js-libp2p-crypto/compare/v0.18.0...v0.19.0) (2021-01-15)

View File

@ -1,6 +1,6 @@
{ {
"name": "libp2p-crypto", "name": "libp2p-crypto",
"version": "0.19.0", "version": "0.19.2",
"description": "Crypto primitives for libp2p", "description": "Crypto primitives for libp2p",
"main": "src/index.js", "main": "src/index.js",
"types": "src/index.d.ts", "types": "src/index.d.ts",
@ -43,14 +43,15 @@
"is-typedarray": "^1.0.0", "is-typedarray": "^1.0.0",
"iso-random-stream": "^1.1.0", "iso-random-stream": "^1.1.0",
"keypair": "^1.0.1", "keypair": "^1.0.1",
"multibase": "^3.0.0", "multibase": "^4.0.3",
"multicodec": "^2.0.0", "multicodec": "^3.0.1",
"multihashes": "^4.0.2",
"multihashing-async": "^2.0.1", "multihashing-async": "^2.0.1",
"node-forge": "^0.10.0", "node-forge": "^0.10.0",
"pem-jwk": "^2.0.0", "pem-jwk": "^2.0.0",
"protons": "^2.0.0", "protons": "^2.0.0",
"secp256k1": "^4.0.0", "secp256k1": "^4.0.0",
"uint8arrays": "^1.1.0", "uint8arrays": "^2.1.4",
"ursa-optional": "^0.10.1" "ursa-optional": "^0.10.1"
}, },
"devDependencies": { "devDependencies": {
@ -84,21 +85,22 @@
"Maciej Krüger <mkg20001@gmail.com>", "Maciej Krüger <mkg20001@gmail.com>",
"dryajov <dryajov@gmail.com>", "dryajov <dryajov@gmail.com>",
"Alan Shaw <alan.shaw@protocol.ai>", "Alan Shaw <alan.shaw@protocol.ai>",
"Cayman <caymannava@gmail.com>",
"Hugo Dias <hugomrdias@gmail.com>", "Hugo Dias <hugomrdias@gmail.com>",
"Cayman <caymannava@gmail.com>",
"Yusef Napora <yusef@napora.org>", "Yusef Napora <yusef@napora.org>",
"Victor Bjelkholm <victorbjelkholm@gmail.com>", "ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
"Vasco Santos <vasco.santos@ua.pt>",
"Arve Knudsen <arve.knudsen@gmail.com>", "Arve Knudsen <arve.knudsen@gmail.com>",
"Alex Potsides <alex@achingbrain.net>", "Alex Potsides <alex@achingbrain.net>",
"Vasco Santos <vasco.santos@ua.pt>",
"Alberto Elias <hi@albertoelias.me>",
"Jack Kleeman <jackkleeman@gmail.com>",
"Nadim Kobeissi <nadim@symbolic.software>",
"Richard Littauer <richard.littauer@gmail.com>", "Richard Littauer <richard.littauer@gmail.com>",
"Richard Schneider <makaretu@gmail.com>", "Richard Schneider <makaretu@gmail.com>",
"Jack Kleeman <jackkleeman@gmail.com>",
"nikuda <nikuda@gmail.com>",
"dirkmc <dirkmdev@gmail.com>", "dirkmc <dirkmdev@gmail.com>",
"Alberto Elias <hi@albertoelias.me>", "nikuda <nikuda@gmail.com>",
"Tom Swindell <t.swindell@rubyx.co.uk>", "Joao Santos <jrmsantos15@gmail.com>",
"Carson Farmer <carson.farmer@gmail.com>", "Carson Farmer <carson.farmer@gmail.com>",
"Joao Santos <jrmsantos15@gmail.com>" "Tom Swindell <t.swindell@rubyx.co.uk>"
] ]
} }

View File

@ -2,10 +2,9 @@
const sha = require('multihashing-async/src/sha') const sha = require('multihashing-async/src/sha')
const protobuf = require('protons') const protobuf = require('protons')
const multibase = require('multibase')
const errcode = require('err-code') const errcode = require('err-code')
const uint8ArrayEquals = require('uint8arrays/equals') const uint8ArrayEquals = require('uint8arrays/equals')
const mh = require('multihashes')
const crypto = require('./ed25519') const crypto = require('./ed25519')
const pbm = protobuf(require('./keys.proto')) const pbm = protobuf(require('./keys.proto'))
const exporter = require('./exporter') const exporter = require('./exporter')
@ -84,8 +83,8 @@ class Ed25519PrivateKey {
* @returns {Promise<String>} * @returns {Promise<String>}
*/ */
async id () { async id () {
const hash = await this.public.hash() const encoding = mh.encode(this.public.bytes, 'identity')
return multibase.encode('base58btc', hash).toString().slice(1) return await mh.toB58String(encoding)
} }
/** /**

View File

@ -80,9 +80,9 @@ describe('ed25519', function () {
}) })
it('key id', async () => { it('key id', async () => {
const key = await crypto.keys.unmarshalPrivateKey(fixtures.verify.privateKey)
const id = await key.id() const id = await key.id()
expect(id).to.exist() expect(id).to.eql('12D3KooWLqLxEfJ9nDdEe8Kh8PFvNPQRYDQBwyL7CMM7HhVd5LsX')
expect(id).to.be.a('string')
}) })
it('should export a password encrypted libp2p-key', async () => { it('should export a password encrypted libp2p-key', async () => {

View File

@ -59,9 +59,9 @@ describe('RSA', function () {
}) })
it('key id', async () => { it('key id', async () => {
const key = await crypto.keys.unmarshalPrivateKey(uint8ArrayFromString('CAASqAkwggSkAgEAAoIBAQCk0O+6oNRxhcdZe2GxEDrFBkDV4TZFZnp2ly/dL1cGMBql/8oXPZgei6h7+P5zzfDq2YCfwbjbf0IVY1AshRl6B5VGE1WS+9p1y1OZxJf5os6V1ENnTi6FTcyuBl4BN8dmIKOif0hqgqflaT5OhfYZDXfbJyVQj4vb2+Stu2Xpph3nwqAnTw/7GC/7jrt2Cq6Tu1PoZi36wSwEPYW3eQ1HAYxZjTYYDXl2iyHygnTcbkGRwAQ7vjk+mW7u60zyoolCm9f6Y7c/orJ33DDUocbaGJLlHcfd8bioBwaZy/2m7q43X8pQs0Q1/iwUt0HHZj1YARmHKbh0zR31ciFiV37dAgMBAAECggEADtJBNKnA4QKURj47r0YT2uLwkqtBi6UnDyISalQXAdXyl4n0nPlrhBewC5H9I+HZr+zmTbeIjaiYgz7el1pSy7AB4v7bG7AtWZlyx6mvtwHGjR+8/f3AXjl8Vgv5iSeAdXUq8fJ7SyS7v3wi38HZOzCEXj9bci6ud5ODMYJgLE4gZD0+i1+/V9cpuYfGpS/gLTLEMQLiw/9o8NSZ7sAnxg0UlYhotqaQY23hvXPBOe+0oa95zl2n6XTxCafa3dQl/B6CD1tUq9dhbQew4bxqMq/mhRO9pREEqZ083Uh+u4PTc1BeHgIQaS864pHPb+AY1F7KDvPtHhdojnghp8d70QKBgQDeRYFxo6sd04ohY86Z/i9icVYIyCvfXAKnaMKeGUjK7ou6sDJwFX8W97+CzXpZ/vffsk/l5GGhC50KqrITxHAy/h5IjyDODfps7NMIp0Dm9sO4PWibbw3OOVBRc8w3b3i7I8MrUUA1nLHE1T1HA1rKOTz5jYhE0fi9XKiT1ciKOQKBgQC903w+n9y7M7eaMW7Z5/13kZ7PS3HlM681eaPrk8J4J+c6miFF40/8HOsmarS38v0fgTeKkriPz5A7aLzRHhSiOnp350JNM6c3sLwPEs2qx/CRuWWx1rMERatfDdUH6mvlK6QHu0QgSfQR27EO6a6XvVSJXbvFmimjmtIaz/IpxQKBgQDWJ9HYVAGC81abZTaiWK3/A4QJYhQjWNuVwPICsgnYvI4Uib+PDqcs0ffLZ38DRw48kek5bxpBuJbOuDhro1EXUJCNCJpq7jzixituovd9kTRyR3iKii2bDM2+LPwOTXDdnk9lZRugjCEbrPkleq33Ob7uEtfAty4aBTTHe6uEwQKBgQCB+2q8RyMSXNuADhFlzOFXGrOwJm0bEUUMTPrduRQUyt4e1qOqA3klnXe3mqGcxBpnlEe/76/JacvNom6Ikxx16a0qpYRU8OWz0KU1fR6vrrEgV98241k5t6sdL4+MGA1Bo5xyXtzLb1hdUh3vpDwVU2OrnC+To3iXus/b5EBiMQKBgEI1OaBcFiyjgLGEyFKoZbtzH1mdatTExfrAQqCjOVjQByoMpGhHTXwEaosvyYu63Pa8AJPT7juSGaiKYEJFcXO9BiNyVfmQiqSHJcYeuh+fmO9IlHRHgy5xaIIC00AHS2vC/gXwmXAdPis6BZqDJeiCuOLWJ94QXn8JBT8IgGAI', 'base64pad'))
const id = await key.id() const id = await key.id()
expect(id).to.exist() expect(id).to.eql('QmQgsppVMDUpe83wcAqaemKbYvHeF127gnSFQ1xFnBodVw')
expect(id).to.be.a('string')
}) })
describe('key equals', () => { describe('key equals', () => {

View File

@ -11,6 +11,7 @@ const keysPBM = crypto.keys.keysPBM
const randomBytes = crypto.randomBytes const randomBytes = crypto.randomBytes
const secp256k1Crypto = require('../../src/keys/secp256k1')(randomBytes) const secp256k1Crypto = require('../../src/keys/secp256k1')(randomBytes)
const uint8ArrayFromString = require('uint8arrays/from-string') const uint8ArrayFromString = require('uint8arrays/from-string')
const fixtures = require('../fixtures/go-key-secp256k1')
describe('secp256k1 keys', () => { describe('secp256k1 keys', () => {
let key let key
@ -58,9 +59,10 @@ describe('secp256k1 keys', () => {
}) })
it('key id', async () => { it('key id', async () => {
const decoded = keysPBM.PrivateKey.decode(fixtures.privateKey)
const key = await secp256k1.unmarshalSecp256k1PrivateKey(decoded.Data)
const id = await key.id() const id = await key.id()
expect(id).to.exist() expect(id).to.eql('QmPCyMBGEyifPtx5aa6k6wkY9N1eBf9vHK1eKfNc35q9uq')
expect(id).to.be.a('string')
}) })
it('should export a password encrypted libp2p-key', async () => { it('should export a password encrypted libp2p-key', async () => {
@ -254,8 +256,6 @@ describe('crypto functions', () => {
}) })
describe('go interop', () => { describe('go interop', () => {
const fixtures = require('../fixtures/go-key-secp256k1')
it('loads a private key marshaled by go-libp2p-crypto', async () => { it('loads a private key marshaled by go-libp2p-crypto', async () => {
// we need to first extract the key data from the protobuf, which is // we need to first extract the key data from the protobuf, which is
// normally handled by js-libp2p-crypto // normally handled by js-libp2p-crypto