Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 464fcbe

Browse files
Alan Shawvasco-santos
authored andcommitted
chore: update deps (#40)
1 parent 0d13a8b commit 464fcbe

File tree

4 files changed

+23
-55
lines changed

4 files changed

+23
-55
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.7.0",
45-
"libp2p-crypto": "^0.16.2",
46-
"merge-options": "^1.0.1",
44+
"interface-datastore": "^0.8.0",
45+
"libp2p-crypto": "^0.17.1",
46+
"merge-options": "^2.0.0",
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.12.1",
55+
"datastore-level": "^0.14.0",
5656
"dirty-chai": "^2.0.1",
57-
"level": "^5.0.1",
57+
"level": "^6.0.0",
5858
"multihashes": "^0.4.15",
59-
"peer-id": "^0.12.2",
59+
"peer-id": "^0.13.5",
6060
"promisify-es6": "^1.0.3",
61-
"rimraf": "^2.6.3"
61+
"rimraf": "^3.0.0"
6262
},
6363
"contributors": [
6464
"Alan Shaw <[email protected]>",

src/keychain.js

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ 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')
98
const CMS = require('./cms')
109
const errcode = require('err-code')
1110

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

207206
let keyInfo
208207
try {
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._())
208+
const keypair = await crypto.keys.generateKeyPair(type, size)
209+
const kid = await keypair.id()
210+
const pem = await keypair.export(this._())
219211
keyInfo = {
220212
name: name,
221213
id: kid
@@ -367,12 +359,8 @@ class Keychain {
367359
try {
368360
const res = await this.store.get(dsname)
369361
const pem = res.toString()
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)
362+
const privateKey = await crypto.keys.import(pem, this._())
363+
return privateKey.export(password)
376364
} catch (err) {
377365
return throwDelayed(err)
378366
}
@@ -400,21 +388,15 @@ class Keychain {
400388

401389
let privateKey
402390
try {
403-
privateKey = await promisify(crypto.keys.import, {
404-
context: crypto.keys
405-
})(pem, password)
391+
privateKey = await crypto.keys.import(pem, password)
406392
} catch (err) {
407393
return throwDelayed(errcode(new Error('Cannot read the key, most likely the password is wrong'), 'ERR_CANNOT_READ_KEY'))
408394
}
409395

410396
let kid
411397
try {
412-
kid = await promisify(privateKey.id, {
413-
context: privateKey
414-
})()
415-
pem = await promisify(privateKey.export, {
416-
context: privateKey
417-
})(this._())
398+
kid = await privateKey.id()
399+
pem = await privateKey.export(this._())
418400
} catch (err) {
419401
return throwDelayed(err)
420402
}
@@ -446,12 +428,8 @@ class Keychain {
446428
if (exists) return throwDelayed(errcode(new Error(`Key '${name}' already exists`), 'ERR_KEY_ALREADY_EXISTS'))
447429

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

test/keychain.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ 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')
1312

1413
module.exports = (datastore1, datastore2) => {
1514
describe('keychain', () => {
@@ -269,7 +268,7 @@ module.exports = (datastore1, datastore2) => {
269268

270269
before(async function () {
271270
const encoded = Buffer.from(alicePrivKey, 'base64')
272-
alice = await promisify(PeerId.createFromPrivKey)(encoded)
271+
alice = await PeerId.createFromPrivKey(encoded)
273272
})
274273

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

test/peerid.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ 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')
1413

1514
const sample = {
1615
id: '122019318b6e5e0cf93a2314bf01269a2cc23cd3dcd452d742cdb9379d8646f6e4a9',
@@ -24,7 +23,7 @@ describe('peer ID', () => {
2423

2524
before(async () => {
2625
const encoded = Buffer.from(sample.privKey, 'base64')
27-
peer = await promisify(PeerId.createFromPrivKey)(encoded)
26+
peer = await PeerId.createFromPrivKey(encoded)
2827
})
2928

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

3635
// get protobuf version of the private key
3736
const privateKeyProtobuf = peer.marshalPrivKey()
38-
const key = await promisify(crypto.keys.unmarshalPrivateKey, {
39-
context: crypto.keys
40-
})(privateKeyProtobuf)
37+
const key = await crypto.keys.unmarshalPrivateKey(privateKeyProtobuf)
4138
expect(key).to.exist()
4239
})
4340

4441
it('encoded public key with DER', async () => {
4542
const jwk = rsaUtils.pkixToJwk(publicKeyDer)
4643
const rsa = new rsaClass.RsaPublicKey(jwk)
47-
const keyId = await promisify(rsa.hash, {
48-
context: rsa
49-
})()
44+
const keyId = await rsa.hash()
5045
const kids = multihash.toB58String(keyId)
5146
expect(kids).to.equal(peer.toB58String())
5247
})
@@ -60,19 +55,15 @@ describe('peer ID', () => {
6055
kid: '2011-04-29'
6156
}
6257
const rsa = new rsaClass.RsaPublicKey(jwk)
63-
const keyId = await promisify(rsa.hash, {
64-
context: rsa
65-
})()
58+
const keyId = await rsa.hash()
6659
const kids = multihash.toB58String(keyId)
6760
expect(kids).to.equal(peer.toB58String())
6861
})
6962

7063
it('decoded private key', async () => {
7164
// get protobuf version of the private key
7265
const privateKeyProtobuf = peer.marshalPrivKey()
73-
const key = await promisify(crypto.keys.unmarshalPrivateKey, {
74-
context: crypto.keys
75-
})(privateKeyProtobuf)
66+
const key = await crypto.keys.unmarshalPrivateKey(privateKeyProtobuf)
7667
expect(key).to.exist()
7768
})
7869
})

0 commit comments

Comments
 (0)