fix: add buffer and update deps (#25)

* fix: add buffer and update deps

update secp256k1 dep and fix code
use multibase to encode b58
avoid un-necessary circular dependency no libp2p-crypto
use  only sha256 from multihashing-async

* Update src/crypto.js

Co-Authored-By: Jacob Heun <jacobheun@gmail.com>

* chore: remove commitlint from CI

Co-authored-by: Jacob Heun <jacobheun@gmail.com>
This commit is contained in:
Hugo Dias
2020-03-17 10:59:23 +00:00
committed by GitHub
parent ae109d46f7
commit 35f196ea4d
7 changed files with 50 additions and 36 deletions

View File

@ -1,14 +1,14 @@
/* eslint-env mocha */
'use strict'
const { Buffer } = require('buffer')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const libp2pCrypto = require('libp2p-crypto')
const keysPBM = libp2pCrypto.keys.keysPBM
const randomBytes = libp2pCrypto.randomBytes
const protobuf = require('protons')
const keysPBM = protobuf(require('libp2p-crypto/src/keys/keys.proto'))
const randomBytes = require('libp2p-crypto/src/random-bytes')
const crypto = require('../src/crypto')(randomBytes)
describe('secp256k1 keys', () => {
@ -136,7 +136,7 @@ describe('handles generation of invalid key', () => {
try {
await secp256k1.generateKeyPair()
} catch (err) {
return expect(err.message).to.equal('Invalid private key')
return expect(err.message).to.equal('Expected private key to be an Uint8Array with length 32')
}
throw new Error('Expected error to be thrown')
})
@ -182,7 +182,7 @@ describe('crypto functions', () => {
try {
await crypto.hashAndSign(Buffer.from('42'), Buffer.from('Hello'))
} catch (err) {
return expect(err.message).to.equal('private key length is invalid')
return expect(err.message).to.equal('Expected private key to be an Uint8Array with length 32')
}
throw new Error('Expected error to be thrown')
})
@ -202,7 +202,7 @@ describe('crypto functions', () => {
try {
await crypto.hashAndVerify(pubKey, Buffer.from('invalid-sig'), Buffer.from('hello'))
} catch (err) {
return expect(err.message).to.equal('couldn\'t parse DER signature')
return expect(err.message).to.equal('Signature could not be parsed')
}
throw new Error('Expected error to be thrown')
})
@ -211,7 +211,7 @@ describe('crypto functions', () => {
try {
await crypto.hashAndSign(Buffer.from('42'), Buffer.from('Hello'))
} catch (err) {
return expect(err.message).to.equal('private key length is invalid')
return expect(err.message).to.equal('Expected private key to be an Uint8Array with length 32')
}
throw new Error('Expected error to be thrown')
})