comparing buffers

This commit is contained in:
nginnever 2016-03-10 11:25:59 -08:00
parent f55eebcef7
commit ca9cef6de7
2 changed files with 12 additions and 1 deletions

View File

@ -109,9 +109,13 @@ exports.create = function () {
const protoPublic64 = formatKey(asnPub, 'Public')
const protoPrivate64 = formatKey(asnPriv, 'Private')
// store the keys as a buffer
const bufProtoPub64 = new Buffer(protoPublic64, 'base64')
const bufProtoPriv64 = new Buffer(protoPrivate64, 'base64')
const mhId = multihashing(new Buffer(protoPublic64, 'base64'), 'sha2-256')
return new Id(mhId, protoPrivate64, protoPublic64)
return new Id(mhId, bufProtoPriv64, bufProtoPub64)
}
exports.createFromHexString = function (str) {

View File

@ -55,5 +55,12 @@ describe('id', function (done) {
expect(testIdB58String).to.equal(id.toB58String())
done()
})
it('Compare generated ID with one created from PubKey', (done) => {
const id1 = PeerId.create()
const id2 = PeerId.createFromPubKey(id1.pubKey)
expect(id2.id).to.deep.equal(id1.id)
done()
})
})