Skip to content

Commit 6b9516c

Browse files
committed
Revert "chore: update deps (#40)"
This reverts commit b6d5313.
1 parent be63323 commit 6b9516c

File tree

4 files changed

+55
-23
lines changed

4 files changed

+55
-23
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
"homepage": "https://github.com/libp2p/js-libp2p-keychain#readme",
4242
"dependencies": {
4343
"err-code": "^2.0.0",
44-
"interface-datastore": "^0.8.0",
45-
"libp2p-crypto": "^0.17.1",
46-
"merge-options": "^2.0.0",
44+
"interface-datastore": "^0.7.0",
45+
"libp2p-crypto": "^0.16.2",
46+
"merge-options": "^1.0.1",
4747
"node-forge": "^0.9.1",
4848
"sanitize-filename": "^1.6.1"
4949
},
@@ -52,13 +52,13 @@
5252
"chai": "^4.2.0",
5353
"chai-string": "^1.5.0",
5454
"datastore-fs": "^0.9.0",
55-
"datastore-level": "^0.14.0",
55+
"datastore-level": "^0.12.1",
5656
"dirty-chai": "^2.0.1",
57-
"level": "^6.0.0",
57+
"level": "^5.0.1",
5858
"multihashes": "^0.4.15",
59-
"peer-id": "^0.13.5",
59+
"peer-id": "^0.12.2",
6060
"promisify-es6": "^1.0.3",
61-
"rimraf": "^3.0.0"
61+
"rimraf": "^2.6.3"
6262
},
6363
"contributors": [
6464
"Alan Shaw <[email protected]>",

src/keychain.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const sanitize = require('sanitize-filename')
55
const mergeOptions = require('merge-options')
66
const crypto = require('libp2p-crypto')
77
const DS = require('interface-datastore')
8+
const promisify = require('promisify-es6')
89
const CMS = require('./cms')
910
const errcode = require('err-code')
1011

@@ -205,9 +206,16 @@ class Keychain {
205206

206207
let keyInfo
207208
try {
208-
const keypair = await crypto.keys.generateKeyPair(type, size)
209-
const kid = await keypair.id()
210-
const pem = await keypair.export(this._())
209+
const keypair = await promisify(crypto.keys.generateKeyPair, {
210+
context: crypto.keys
211+
})(type, size)
212+
213+
const kid = await promisify(keypair.id, {
214+
context: keypair
215+
})()
216+
const pem = await promisify(keypair.export, {
217+
context: keypair
218+
})(this._())
211219
keyInfo = {
212220
name: name,
213221
id: kid
@@ -359,8 +367,12 @@ class Keychain {
359367
try {
360368
const res = await this.store.get(dsname)
361369
const pem = res.toString()
362-
const privateKey = await crypto.keys.import(pem, this._())
363-
return privateKey.export(password)
370+
const privateKey = await promisify(crypto.keys.import, {
371+
context: crypto.keys
372+
})(pem, this._())
373+
return promisify(privateKey.export, {
374+
context: privateKey
375+
})(password)
364376
} catch (err) {
365377
return throwDelayed(err)
366378
}
@@ -388,15 +400,21 @@ class Keychain {
388400

389401
let privateKey
390402
try {
391-
privateKey = await crypto.keys.import(pem, password)
403+
privateKey = await promisify(crypto.keys.import, {
404+
context: crypto.keys
405+
})(pem, password)
392406
} catch (err) {
393407
return throwDelayed(errcode(new Error('Cannot read the key, most likely the password is wrong'), 'ERR_CANNOT_READ_KEY'))
394408
}
395409

396410
let kid
397411
try {
398-
kid = await privateKey.id()
399-
pem = await privateKey.export(this._())
412+
kid = await promisify(privateKey.id, {
413+
context: privateKey
414+
})()
415+
pem = await promisify(privateKey.export, {
416+
context: privateKey
417+
})(this._())
400418
} catch (err) {
401419
return throwDelayed(err)
402420
}
@@ -428,8 +446,12 @@ class Keychain {
428446
if (exists) return throwDelayed(errcode(new Error(`Key '${name}' already exists`), 'ERR_KEY_ALREADY_EXISTS'))
429447

430448
try {
431-
const kid = await privateKey.id()
432-
const pem = await privateKey.export(this._())
449+
const kid = await promisify(privateKey.id, {
450+
context: privateKey
451+
})()
452+
const pem = await promisify(privateKey.export, {
453+
context: privateKey
454+
})(this._())
433455
const keyInfo = {
434456
name: name,
435457
id: kid

test/keychain.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ chai.use(require('dirty-chai'))
99
chai.use(require('chai-string'))
1010
const Keychain = require('../')
1111
const PeerId = require('peer-id')
12+
const promisify = require('promisify-es6')
1213

1314
module.exports = (datastore1, datastore2) => {
1415
describe('keychain', () => {
@@ -268,7 +269,7 @@ module.exports = (datastore1, datastore2) => {
268269

269270
before(async function () {
270271
const encoded = Buffer.from(alicePrivKey, 'base64')
271-
alice = await PeerId.createFromPrivKey(encoded)
272+
alice = await promisify(PeerId.createFromPrivKey)(encoded)
272273
})
273274

274275
it('private key can be imported', async () => {

test/peerid.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const multihash = require('multihashes')
1010
const crypto = require('libp2p-crypto')
1111
const rsaUtils = require('libp2p-crypto/src/keys/rsa-utils')
1212
const rsaClass = require('libp2p-crypto/src/keys/rsa-class')
13+
const promisify = require('promisify-es6')
1314

1415
const sample = {
1516
id: '122019318b6e5e0cf93a2314bf01269a2cc23cd3dcd452d742cdb9379d8646f6e4a9',
@@ -23,7 +24,7 @@ describe('peer ID', () => {
2324

2425
before(async () => {
2526
const encoded = Buffer.from(sample.privKey, 'base64')
26-
peer = await PeerId.createFromPrivKey(encoded)
27+
peer = await promisify(PeerId.createFromPrivKey)(encoded)
2728
})
2829

2930
it('decoded public key', async () => {
@@ -34,14 +35,18 @@ describe('peer ID', () => {
3435

3536
// get protobuf version of the private key
3637
const privateKeyProtobuf = peer.marshalPrivKey()
37-
const key = await crypto.keys.unmarshalPrivateKey(privateKeyProtobuf)
38+
const key = await promisify(crypto.keys.unmarshalPrivateKey, {
39+
context: crypto.keys
40+
})(privateKeyProtobuf)
3841
expect(key).to.exist()
3942
})
4043

4144
it('encoded public key with DER', async () => {
4245
const jwk = rsaUtils.pkixToJwk(publicKeyDer)
4346
const rsa = new rsaClass.RsaPublicKey(jwk)
44-
const keyId = await rsa.hash()
47+
const keyId = await promisify(rsa.hash, {
48+
context: rsa
49+
})()
4550
const kids = multihash.toB58String(keyId)
4651
expect(kids).to.equal(peer.toB58String())
4752
})
@@ -55,15 +60,19 @@ describe('peer ID', () => {
5560
kid: '2011-04-29'
5661
}
5762
const rsa = new rsaClass.RsaPublicKey(jwk)
58-
const keyId = await rsa.hash()
63+
const keyId = await promisify(rsa.hash, {
64+
context: rsa
65+
})()
5966
const kids = multihash.toB58String(keyId)
6067
expect(kids).to.equal(peer.toB58String())
6168
})
6269

6370
it('decoded private key', async () => {
6471
// get protobuf version of the private key
6572
const privateKeyProtobuf = peer.marshalPrivKey()
66-
const key = await crypto.keys.unmarshalPrivateKey(privateKeyProtobuf)
73+
const key = await promisify(crypto.keys.unmarshalPrivateKey, {
74+
context: crypto.keys
75+
})(privateKeyProtobuf)
6776
expect(key).to.exist()
6877
})
6978
})

0 commit comments

Comments
 (0)