mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-03-15 06:01:01 +00:00
fix: ed25519 key ID generation
As discussed here: https://github.com/ipfs/js-ipfs/issues/3591 Satisfy linter test: actually verify ids
This commit is contained in:
parent
b07978dbea
commit
bc337698b6
@ -2,9 +2,9 @@
|
||||
|
||||
const sha = require('multihashing-async/src/sha')
|
||||
const protobuf = require('protons')
|
||||
const multibase = require('multibase')
|
||||
const errcode = require('err-code')
|
||||
const uint8ArrayEquals = require('uint8arrays/equals')
|
||||
const uint8ArrayToString = require('uint8arrays/to-string')
|
||||
|
||||
const crypto = require('./ed25519')
|
||||
const pbm = protobuf(require('./keys.proto'))
|
||||
@ -85,7 +85,7 @@ class Ed25519PrivateKey {
|
||||
*/
|
||||
async id () {
|
||||
const hash = await this.public.hash()
|
||||
return multibase.encode('base58btc', hash).toString().slice(1)
|
||||
return uint8ArrayToString(hash, 'base58btc')
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,9 +80,9 @@ describe('ed25519', function () {
|
||||
})
|
||||
|
||||
it('key id', async () => {
|
||||
const key = await crypto.keys.unmarshalPrivateKey(fixtures.verify.privateKey)
|
||||
const id = await key.id()
|
||||
expect(id).to.exist()
|
||||
expect(id).to.be.a('string')
|
||||
expect(id).to.eql('QmUawW9qzMrBBiMrWQQMvoatadKZ9F4EwZCAMKnt3STLtz')
|
||||
})
|
||||
|
||||
it('should export a password encrypted libp2p-key', async () => {
|
||||
|
@ -59,9 +59,9 @@ describe('RSA', function () {
|
||||
})
|
||||
|
||||
it('key id', async () => {
|
||||
const key = await crypto.keys.unmarshalPrivateKey(uint8ArrayFromString('CAASqAkwggSkAgEAAoIBAQCk0O+6oNRxhcdZe2GxEDrFBkDV4TZFZnp2ly/dL1cGMBql/8oXPZgei6h7+P5zzfDq2YCfwbjbf0IVY1AshRl6B5VGE1WS+9p1y1OZxJf5os6V1ENnTi6FTcyuBl4BN8dmIKOif0hqgqflaT5OhfYZDXfbJyVQj4vb2+Stu2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OwJm0bEUUMTPrduRQUyt4e1qOqA3klnXe3mqGcxBpnlEe/76/JacvNom6Ikxx16a0qpYRU8OWz0KU1fR6vrrEgV98241k5t6sdL4+MGA1Bo5xyXtzLb1hdUh3vpDwVU2OrnC+To3iXus/b5EBiMQKBgEI1OaBcFiyjgLGEyFKoZbtzH1mdatTExfrAQqCjOVjQByoMpGhHTXwEaosvyYu63Pa8AJPT7juSGaiKYEJFcXO9BiNyVfmQiqSHJcYeuh+fmO9IlHRHgy5xaIIC00AHS2vC/gXwmXAdPis6BZqDJeiCuOLWJ94QXn8JBT8IgGAI', 'base64pad'))
|
||||
const id = await key.id()
|
||||
expect(id).to.exist()
|
||||
expect(id).to.be.a('string')
|
||||
expect(id).to.eql('QmQgsppVMDUpe83wcAqaemKbYvHeF127gnSFQ1xFnBodVw')
|
||||
})
|
||||
|
||||
describe('key equals', () => {
|
||||
|
@ -11,6 +11,7 @@ const keysPBM = crypto.keys.keysPBM
|
||||
const randomBytes = crypto.randomBytes
|
||||
const secp256k1Crypto = require('../../src/keys/secp256k1')(randomBytes)
|
||||
const uint8ArrayFromString = require('uint8arrays/from-string')
|
||||
const fixtures = require('../fixtures/go-key-secp256k1')
|
||||
|
||||
describe('secp256k1 keys', () => {
|
||||
let key
|
||||
@ -58,9 +59,10 @@ describe('secp256k1 keys', () => {
|
||||
})
|
||||
|
||||
it('key id', async () => {
|
||||
const decoded = keysPBM.PrivateKey.decode(fixtures.privateKey)
|
||||
const key = await secp256k1.unmarshalSecp256k1PrivateKey(decoded.Data)
|
||||
const id = await key.id()
|
||||
expect(id).to.exist()
|
||||
expect(id).to.be.a('string')
|
||||
expect(id).to.eql('QmPCyMBGEyifPtx5aa6k6wkY9N1eBf9vHK1eKfNc35q9uq')
|
||||
})
|
||||
|
||||
it('should export a password encrypted libp2p-key', async () => {
|
||||
@ -254,8 +256,6 @@ describe('crypto functions', () => {
|
||||
})
|
||||
|
||||
describe('go interop', () => {
|
||||
const fixtures = require('../fixtures/go-key-secp256k1')
|
||||
|
||||
it('loads a private key marshaled by go-libp2p-crypto', async () => {
|
||||
// we need to first extract the key data from the protobuf, which is
|
||||
// normally handled by js-libp2p-crypto
|
||||
|
Loading…
x
Reference in New Issue
Block a user