mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-06-23 02:31:37 +00:00
go interop test for ephemeral keys
This commit is contained in:
@ -2,8 +2,10 @@
|
||||
'use strict'
|
||||
|
||||
const expect = require('chai').expect
|
||||
const EC = require('elliptic').ec
|
||||
|
||||
const crypto = require('../src')
|
||||
const fixtures = require('./fixtures/go-elliptic-key')
|
||||
|
||||
describe('generateEphemeralKeyPair', () => {
|
||||
it('returns a function that generates a shared secret', () => {
|
||||
@ -18,4 +20,25 @@ describe('generateEphemeralKeyPair', () => {
|
||||
res.key
|
||||
).to.exist
|
||||
})
|
||||
|
||||
describe('go interop', () => {
|
||||
it('generates a shared secret', () => {
|
||||
const curve = fixtures.curve
|
||||
const ec = new EC(fixtures.curveJs)
|
||||
const bobPrivate = ec.keyFromPrivate(fixtures.bob.private, 'binary')
|
||||
|
||||
const alice = crypto.generateEphemeralKeyPair(curve)
|
||||
const bob = {
|
||||
key: fixtures.bob.public,
|
||||
// this is using bobs private key from go ipfs
|
||||
// instead of alices
|
||||
genSharedKey: (key) => alice.genSharedKey(key, bobPrivate)
|
||||
}
|
||||
|
||||
const s1 = alice.genSharedKey(bob.key)
|
||||
const s2 = bob.genSharedKey(alice.key)
|
||||
|
||||
expect(s1.equals(s2)).to.be.eql(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user