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