2014-03-31 05:47:47 +02:00
|
|
|
var assert = require('assert')
|
2013-02-17 06:39:15 +01:00
|
|
|
|
2014-05-13 09:55:53 +02:00
|
|
|
var sec = require('../src/sec')
|
2014-03-31 05:47:47 +02:00
|
|
|
var ecparams = sec('secp256k1')
|
2013-02-17 06:39:15 +01:00
|
|
|
|
2014-05-03 04:04:54 +02:00
|
|
|
var BigInteger = require('bigi')
|
2014-05-13 09:55:53 +02:00
|
|
|
var ECPointFp = require('../src/ec').ECPointFp
|
2014-04-16 20:10:05 +02:00
|
|
|
|
|
|
|
describe('ec', function() {
|
|
|
|
describe('ECPointFp', function() {
|
2014-04-21 18:04:56 +02:00
|
|
|
it('behaves correctly', function() {
|
2014-04-16 20:10:05 +02:00
|
|
|
var G = ecparams.getG()
|
|
|
|
var n = ecparams.getN()
|
|
|
|
|
|
|
|
assert.ok(G.multiply(n).isInfinity(), "Gn is infinite")
|
|
|
|
|
2014-04-21 18:04:56 +02:00
|
|
|
var k = BigInteger.ONE
|
2014-04-16 20:10:05 +02:00
|
|
|
var P = G.multiply(k)
|
|
|
|
assert.ok(!P.isInfinity(), "kG is not infinite")
|
|
|
|
assert.ok(P.isOnCurve(), "kG on curve")
|
|
|
|
assert.ok(P.multiply(n).isInfinity(), "kGn is infinite")
|
|
|
|
|
|
|
|
assert.ok(P.validate(), "kG validates as a public key")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('decodeFrom', function() {
|
2014-04-21 18:08:00 +02:00
|
|
|
it('decodes compressed ECPoints', function() {
|
|
|
|
var s = new Buffer('02789ece95adf35fb3de994b8b16c90166736d70913a18378fff79503e8c5db7fb', 'hex')
|
|
|
|
var Q = ECPointFp.decodeFrom(ecparams.getCurve(), s)
|
|
|
|
assert.ok(Q)
|
|
|
|
assert.ok(Q.validate())
|
|
|
|
})
|
2013-02-17 06:39:15 +01:00
|
|
|
|
2014-04-21 18:08:00 +02:00
|
|
|
it('decodes uncompressed ECPoints', function() {
|
|
|
|
var s = new Buffer('0486f356006a38b847bedec1bf47013776925d939d5a35a97a4d1263e550c7f1ab5aba44ab74d22892097a0e851addf07ba97e33416df5affaceeb35d5607cd23c', 'hex')
|
|
|
|
var Q = ECPointFp.decodeFrom(ecparams.getCurve(), s)
|
|
|
|
assert.ok(Q)
|
|
|
|
assert.ok(Q.validate())
|
2014-04-16 20:10:05 +02:00
|
|
|
})
|
2014-03-31 05:47:47 +02:00
|
|
|
})
|
2014-01-11 07:57:43 +01:00
|
|
|
})
|