Skip to content

Commit

Permalink
chore: rebase branch
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Jul 11, 2019
1 parent e83647a commit 03459fb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@
},
"homepage": "https://github.com/libp2p/js-peer-id",
"devDependencies": {
"aegir": "^18.2.2",
"bundlesize": "~0.17.1",
"aegir": "^19.0.5",
"bundlesize": "~0.18.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1"
},
"dependencies": {
"async": "^2.6.2",
"class-is": "^1.1.0",
"libp2p-crypto": "~0.16.1",
"libp2p-crypto": "libp2p/js-libp2p-crypto",
"multihashes": "~0.4.14"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const PeerId = require('./index.js')

async function main () {
const id = await PeerId.create()
console.log(JSON.stringify(id.toJSON(), null, 2))
console.log(JSON.stringify(id.toJSON(), null, 2)) // eslint-disable-line no-console
}

main()
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ exports.create = async (opts) => {
opts = opts || {}
opts.bits = opts.bits || 2048

const key = await crypto.keys.generateKeyPair('RSA', opts.bits)
const key = await cryptoKeys.generateKeyPair('RSA', opts.bits)
const digest = await key.public.hash()

return new PeerIdWithIs(digest, key)
Expand Down Expand Up @@ -170,7 +170,7 @@ exports.createFromPubKey = async (key) => {
throw new Error('Supplied key is neither a base64 string nor a buffer')
}

const pubKey = await crypto.keys.unmarshalPublicKey(buf)
const pubKey = await cryptoKeys.unmarshalPublicKey(buf)
const digest = await pubKey.hash()
return new PeerIdWithIs(digest, null, pubKey)
}
Expand All @@ -187,7 +187,7 @@ exports.createFromPrivKey = async (key) => {
throw new Error('Supplied key is neither a base64 string nor a buffer')
}

const privKey = await crypto.keys.unmarshalPrivateKey(buf)
const privKey = await cryptoKeys.unmarshalPrivateKey(buf)
const digest = await privKey.public.hash()

return new PeerIdWithIs(digest, privKey, privKey.public)
Expand All @@ -197,13 +197,13 @@ exports.createFromJSON = async (obj) => {
let id = mh.fromB58String(obj.id)
let rawPrivKey = obj.privKey && Buffer.from(obj.privKey, 'base64')
let rawPubKey = obj.pubKey && Buffer.from(obj.pubKey, 'base64')
let pub = rawPubKey && await crypto.keys.unmarshalPublicKey(rawPubKey)
let pub = rawPubKey && await cryptoKeys.unmarshalPublicKey(rawPubKey)

if (!rawPrivKey) {
return new PeerIdWithIs(id, null, pub)
}

const privKey = await crypto.keys.unmarshalPrivateKey(rawPrivKey)
const privKey = await cryptoKeys.unmarshalPrivateKey(rawPrivKey)
const privDigest = await privKey.public.hash()
let pubDigest

Expand Down
8 changes: 4 additions & 4 deletions test/peer-id.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ describe('PeerId', () => {
}).to.throw(/immutable/)
})

it('recreate an Id from Hex string', async () => {
it('recreate an Id from Hex string', () => {
const id = PeerId.createFromHexString(testIdHex)
expect(testIdBytes).to.deep.equal(id.id)
})

it('Recreate an Id from a Buffer', async () => {
it('Recreate an Id from a Buffer', () => {
const id = PeerId.createFromBytes(testIdBytes)
expect(testId.id).to.equal(id.toHexString())
})

it('Recreate a B58 String', async () => {
it('Recreate a B58 String', () => {
const id = PeerId.createFromB58String(testIdB58String)
expect(testIdB58String).to.equal(id.toB58String())
})
Expand Down Expand Up @@ -106,7 +106,7 @@ describe('PeerId', () => {
expect(id1.toPrint()).to.equal('<peer.ID ' + id1.toB58String().substr(2, 6) + '>')
})

it('toBytes', async () => {
it('toBytes', () => {
const id = PeerId.createFromHexString(testIdHex)
expect(id.toBytes().toString('hex')).to.equal(testIdBytes.toString('hex'))
})
Expand Down

0 comments on commit 03459fb

Please sign in to comment.