Skip to content

Commit

Permalink
test loading publisher id from concat, validating messages with it
Browse files Browse the repository at this point in the history
  • Loading branch information
yusefnapora committed Jan 18, 2017
1 parent 180790e commit 02a5e45
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
6 changes: 6 additions & 0 deletions test/resources/fixtures/concat-message-signature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
publisherIdB58: '4XTTM4JKrrBeAK6qXmo8FoKmT5RkfjeXfZrnWjJNw9fKvPnEs',
privateKeyB58: 'K3TgUMffighKb23qdfq8oyJM4ByiG3nMgKMHNQeTFEKtfDJzGaTeEzJzp1BUmPYikTtzrgyiEg8DGSfWXemtWh5APs2a8K8hpfHYwhmvxh35YdGrrYHgMEpxFxCEEiaRkN7oDt7q',
message: Buffer.from('This message was signed with a key generated by concat', 'utf-8'),
signature: Buffer.from('Id02py5k9yGJBYQ6/W1qOThAdF9Y5LQySQGbCQdV+pYou+xNeRG26sIJQCZ3B/9SQ/CpJfZjwr+QjwydNWg6Ag==', 'base64')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`~K'��^�h��I�$p�ˎ���M.�%2��+=.�l^�$s�V#�������� ��;No�P�U�.�l^�$s�V#�������� ��;No�P�U�
33 changes: 32 additions & 1 deletion test/signature_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@

const assert = require('assert')
const { before, describe, it } = require('mocha')
const path = require('path')

const { PublisherId } = require('../src/peer/identity')
const { PublisherId, PrivateSigningKey } = require('../src/peer/identity')
const { makeSimpleStatement } = require('../src/metadata/statement')
const { signStatement, verifyStatement } = require('../src/metadata/signatures')

const CONCAT_PUBLISHER_ID_PUB58 = '4XTTM4JKrrBeAK6qXmo8FoKmT5RkfjeXfZrnWjJNw9fKvPnEs'
const CONCAT_PUBLISHER_ID_PATH = path.join(__dirname, 'resources', 'publisher_ids', 'concat',
`${CONCAT_PUBLISHER_ID_PUB58}.privateKey`)
const CONCAT_MESSAGE_FIXTURES = require('./resources/fixtures/concat-message-signature')

describe('Signature verification', () => {
let publisherId

Expand Down Expand Up @@ -69,4 +75,29 @@ describe('Signature verification', () => {
assert(!valid, 'incorrectly validated an altered statement')
})
})

it('loads a publisher id from a file generated by concat', () => {
return PublisherId.load(CONCAT_PUBLISHER_ID_PATH)
.then(id => {
assert.notEqual(id, null, 'publisher id did not load')
assert.equal(CONCAT_PUBLISHER_ID_PUB58, id.privateKey.publicKey.toB58String(),
'base58-encoded public key does not match fixture')
})
})

it('generates the same signature as concat using the same publisher id', () => {
let privateKey
return PrivateSigningKey.fromB58String(CONCAT_MESSAGE_FIXTURES.privateKeyB58)
.then(key => {
privateKey = key
assert.equal(privateKey.publicKey.toB58String(), CONCAT_MESSAGE_FIXTURES.publisherIdB58,
'base58-encoded public key does not match fixture')

return privateKey.sign(CONCAT_MESSAGE_FIXTURES.message)
})
.then(sig => {
assert.deepEqual(sig, CONCAT_MESSAGE_FIXTURES.signature,
'signatures did not match')
})
})
})

0 comments on commit 02a5e45

Please sign in to comment.