diff --git a/package.json b/package.json index ffed277..ff6dbc6 100644 --- a/package.json +++ b/package.json @@ -41,9 +41,9 @@ "homepage": "https://github.com/libp2p/js-libp2p-keychain#readme", "dependencies": { "err-code": "^2.0.0", - "interface-datastore": "^0.7.0", - "libp2p-crypto": "^0.16.2", - "merge-options": "^1.0.1", + "interface-datastore": "^0.8.0", + "libp2p-crypto": "^0.17.1", + "merge-options": "^2.0.0", "node-forge": "^0.9.1", "sanitize-filename": "^1.6.1" }, @@ -52,13 +52,13 @@ "chai": "^4.2.0", "chai-string": "^1.5.0", "datastore-fs": "^0.9.0", - "datastore-level": "^0.12.1", + "datastore-level": "^0.14.0", "dirty-chai": "^2.0.1", - "level": "^5.0.1", + "level": "^6.0.0", "multihashes": "^0.4.15", - "peer-id": "^0.12.2", + "peer-id": "^0.13.5", "promisify-es6": "^1.0.3", - "rimraf": "^2.6.3" + "rimraf": "^3.0.0" }, "contributors": [ "Alan Shaw ", diff --git a/src/keychain.js b/src/keychain.js index 7bd8ba3..aae7897 100644 --- a/src/keychain.js +++ b/src/keychain.js @@ -5,7 +5,6 @@ const sanitize = require('sanitize-filename') const mergeOptions = require('merge-options') const crypto = require('libp2p-crypto') const DS = require('interface-datastore') -const promisify = require('promisify-es6') const CMS = require('./cms') const errcode = require('err-code') @@ -206,16 +205,9 @@ class Keychain { let keyInfo try { - const keypair = await promisify(crypto.keys.generateKeyPair, { - context: crypto.keys - })(type, size) - - const kid = await promisify(keypair.id, { - context: keypair - })() - const pem = await promisify(keypair.export, { - context: keypair - })(this._()) + const keypair = await crypto.keys.generateKeyPair(type, size) + const kid = await keypair.id() + const pem = await keypair.export(this._()) keyInfo = { name: name, id: kid @@ -367,12 +359,8 @@ class Keychain { try { const res = await this.store.get(dsname) const pem = res.toString() - const privateKey = await promisify(crypto.keys.import, { - context: crypto.keys - })(pem, this._()) - return promisify(privateKey.export, { - context: privateKey - })(password) + const privateKey = await crypto.keys.import(pem, this._()) + return privateKey.export(password) } catch (err) { return throwDelayed(err) } @@ -400,21 +388,15 @@ class Keychain { let privateKey try { - privateKey = await promisify(crypto.keys.import, { - context: crypto.keys - })(pem, password) + privateKey = await crypto.keys.import(pem, password) } catch (err) { return throwDelayed(errcode(new Error('Cannot read the key, most likely the password is wrong'), 'ERR_CANNOT_READ_KEY')) } let kid try { - kid = await promisify(privateKey.id, { - context: privateKey - })() - pem = await promisify(privateKey.export, { - context: privateKey - })(this._()) + kid = await privateKey.id() + pem = await privateKey.export(this._()) } catch (err) { return throwDelayed(err) } @@ -446,12 +428,8 @@ class Keychain { if (exists) return throwDelayed(errcode(new Error(`Key '${name}' already exists`), 'ERR_KEY_ALREADY_EXISTS')) try { - const kid = await promisify(privateKey.id, { - context: privateKey - })() - const pem = await promisify(privateKey.export, { - context: privateKey - })(this._()) + const kid = await privateKey.id() + const pem = await privateKey.export(this._()) const keyInfo = { name: name, id: kid diff --git a/test/keychain.spec.js b/test/keychain.spec.js index 0756f5f..c455f2d 100644 --- a/test/keychain.spec.js +++ b/test/keychain.spec.js @@ -9,7 +9,6 @@ chai.use(require('dirty-chai')) chai.use(require('chai-string')) const Keychain = require('../') const PeerId = require('peer-id') -const promisify = require('promisify-es6') module.exports = (datastore1, datastore2) => { describe('keychain', () => { @@ -269,7 +268,7 @@ module.exports = (datastore1, datastore2) => { before(async function () { const encoded = Buffer.from(alicePrivKey, 'base64') - alice = await promisify(PeerId.createFromPrivKey)(encoded) + alice = await PeerId.createFromPrivKey(encoded) }) it('private key can be imported', async () => { diff --git a/test/peerid.js b/test/peerid.js index 42274db..4360e53 100644 --- a/test/peerid.js +++ b/test/peerid.js @@ -10,7 +10,6 @@ const multihash = require('multihashes') const crypto = require('libp2p-crypto') const rsaUtils = require('libp2p-crypto/src/keys/rsa-utils') const rsaClass = require('libp2p-crypto/src/keys/rsa-class') -const promisify = require('promisify-es6') const sample = { id: '122019318b6e5e0cf93a2314bf01269a2cc23cd3dcd452d742cdb9379d8646f6e4a9', @@ -24,7 +23,7 @@ describe('peer ID', () => { before(async () => { const encoded = Buffer.from(sample.privKey, 'base64') - peer = await promisify(PeerId.createFromPrivKey)(encoded) + peer = await PeerId.createFromPrivKey(encoded) }) it('decoded public key', async () => { @@ -35,18 +34,14 @@ describe('peer ID', () => { // get protobuf version of the private key const privateKeyProtobuf = peer.marshalPrivKey() - const key = await promisify(crypto.keys.unmarshalPrivateKey, { - context: crypto.keys - })(privateKeyProtobuf) + const key = await crypto.keys.unmarshalPrivateKey(privateKeyProtobuf) expect(key).to.exist() }) it('encoded public key with DER', async () => { const jwk = rsaUtils.pkixToJwk(publicKeyDer) const rsa = new rsaClass.RsaPublicKey(jwk) - const keyId = await promisify(rsa.hash, { - context: rsa - })() + const keyId = await rsa.hash() const kids = multihash.toB58String(keyId) expect(kids).to.equal(peer.toB58String()) }) @@ -60,9 +55,7 @@ describe('peer ID', () => { kid: '2011-04-29' } const rsa = new rsaClass.RsaPublicKey(jwk) - const keyId = await promisify(rsa.hash, { - context: rsa - })() + const keyId = await rsa.hash() const kids = multihash.toB58String(keyId) expect(kids).to.equal(peer.toB58String()) }) @@ -70,9 +63,7 @@ describe('peer ID', () => { it('decoded private key', async () => { // get protobuf version of the private key const privateKeyProtobuf = peer.marshalPrivKey() - const key = await promisify(crypto.keys.unmarshalPrivateKey, { - context: crypto.keys - })(privateKeyProtobuf) + const key = await crypto.keys.unmarshalPrivateKey(privateKeyProtobuf) expect(key).to.exist() }) })