2016-05-19 18:47:48 +02:00
|
|
|
/* eslint-env mocha */
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const expect = require('chai').expect
|
|
|
|
|
|
|
|
const crypto = require('../src')
|
2016-05-20 14:41:25 +02:00
|
|
|
const fixtures = require('./fixtures/go-key-rsa')
|
2016-05-19 18:47:48 +02:00
|
|
|
|
|
|
|
describe('libp2p-crypto', () => {
|
2016-05-19 21:45:43 +02:00
|
|
|
let key
|
2016-05-23 19:13:31 +02:00
|
|
|
before(() => {
|
|
|
|
key = crypto.generateKeyPair('RSA', 2048)
|
2016-05-19 21:45:43 +02:00
|
|
|
})
|
2016-05-19 20:18:31 +02:00
|
|
|
|
2016-05-19 21:45:43 +02:00
|
|
|
it('marshalPublicKey and unmarshalPublicKey', () => {
|
|
|
|
const key2 = crypto.unmarshalPublicKey(crypto.marshalPublicKey(key.public))
|
2016-05-19 20:18:31 +02:00
|
|
|
|
2016-05-19 21:45:43 +02:00
|
|
|
expect(key2.equals(key.public)).to.be.eql(true)
|
|
|
|
})
|
2016-05-19 20:18:31 +02:00
|
|
|
|
2016-05-19 21:45:43 +02:00
|
|
|
it('marshalPrivateKey and unmarshalPrivateKey', () => {
|
|
|
|
const key2 = crypto.unmarshalPrivateKey(crypto.marshalPrivateKey(key))
|
2016-05-19 18:47:48 +02:00
|
|
|
|
2016-05-19 21:45:43 +02:00
|
|
|
expect(key2.equals(key)).to.be.eql(true)
|
2016-05-19 18:47:48 +02:00
|
|
|
})
|
2016-05-20 14:41:25 +02:00
|
|
|
|
|
|
|
describe('go interop', () => {
|
|
|
|
it('unmarshals private key', () => {
|
|
|
|
const key = crypto.unmarshalPrivateKey(fixtures.private.key)
|
|
|
|
const hash = fixtures.private.hash
|
|
|
|
|
|
|
|
expect(
|
|
|
|
key.hash()
|
|
|
|
).to.be.eql(
|
|
|
|
hash
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('unmarshals public key', () => {
|
|
|
|
const key = crypto.unmarshalPublicKey(fixtures.public.key)
|
|
|
|
const hash = fixtures.public.hash
|
|
|
|
|
|
|
|
expect(
|
|
|
|
key.hash()
|
|
|
|
).to.be.eql(
|
|
|
|
hash
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('unmarshal -> marshal, private key', () => {
|
|
|
|
const key = crypto.unmarshalPrivateKey(fixtures.private.key)
|
|
|
|
const marshalled = crypto.marshalPrivateKey(key)
|
|
|
|
expect(
|
|
|
|
fixtures.private.key.equals(marshalled)
|
|
|
|
).to.be.eql(
|
|
|
|
true
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('unmarshal -> marshal, public key', () => {
|
|
|
|
const key = crypto.unmarshalPublicKey(fixtures.public.key)
|
|
|
|
const marshalled = crypto.marshalPublicKey(key)
|
|
|
|
expect(
|
|
|
|
fixtures.public.key.equals(marshalled)
|
|
|
|
).to.be.eql(
|
|
|
|
true
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2016-05-19 18:47:48 +02:00
|
|
|
})
|