mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-03-15 19:50:58 +00:00
BREAKING CHANGE: API refactored to use async/await feat: WIP use async await fix: passing tests chore: update travis node.js versions fix: skip ursa optional tests on windows fix: benchmarks docs: update docs fix: remove broken and intested private key decrypt chore: update deps
54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
'use strict'
|
|
|
|
/* eslint-env mocha */
|
|
/* eslint max-nested-callbacks: ["error", 8] */
|
|
|
|
const chai = require('chai')
|
|
const dirtyChai = require('dirty-chai')
|
|
const expect = chai.expect
|
|
chai.use(dirtyChai)
|
|
chai.use(require('chai-string'))
|
|
|
|
const LIBS = ['ursa', 'keypair']
|
|
|
|
describe('RSA crypto libs', function () {
|
|
this.timeout(20 * 1000)
|
|
|
|
LIBS.forEach(lib => {
|
|
describe(lib, () => {
|
|
let crypto
|
|
let rsa
|
|
|
|
before(() => {
|
|
process.env.LP2P_FORCE_CRYPTO_LIB = lib
|
|
|
|
for (const path in require.cache) { // clear module cache
|
|
if (path.endsWith('.js')) {
|
|
delete require.cache[path]
|
|
}
|
|
}
|
|
|
|
crypto = require('../../src')
|
|
rsa = crypto.keys.supportedKeys.rsa
|
|
})
|
|
|
|
it('generates a valid key', async () => {
|
|
const key = await crypto.keys.generateKeyPair('RSA', 512)
|
|
expect(key).to.be.an.instanceof(rsa.RsaPrivateKey)
|
|
const digest = await key.hash()
|
|
expect(digest).to.have.length(34)
|
|
})
|
|
|
|
after(() => {
|
|
for (const path in require.cache) { // clear module cache
|
|
if (path.endsWith('.js')) {
|
|
delete require.cache[path]
|
|
}
|
|
}
|
|
|
|
delete process.env.LP2P_FORCE_CRYPTO_LIB
|
|
})
|
|
})
|
|
})
|
|
})
|