Browse Source
...this involves adding a Curve class, and significant refactoring to make this possible in a clean way.patch-2
Ryan X. Charles
11 years ago
13 changed files with 151 additions and 59 deletions
@ -0,0 +1,22 @@ |
|||
"use strict"; |
|||
var imports = require('soop'); |
|||
var bignum = imports.bignum || require('bignum'); |
|||
var Point = imports.Point || require('./Point'); |
|||
|
|||
var n = bignum.fromBuffer(new Buffer("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 'hex'), {size: 32}); |
|||
var G = new Point(bignum.fromBuffer(new Buffer("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 'hex'), {size: 32}), |
|||
bignum.fromBuffer(new Buffer("483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", 'hex'), {size: 32})); |
|||
|
|||
/* secp256k1 curve */ |
|||
var Curve = function() { |
|||
}; |
|||
|
|||
Curve.getG = function() { |
|||
return G; |
|||
}; |
|||
|
|||
Curve.getN = function() { |
|||
return n; |
|||
}; |
|||
|
|||
module.exports = require('soop')(Curve); |
@ -1 +1,3 @@ |
|||
module.exports = require('bindings')('KeyModule').Key; |
|||
var Key = require('bindings')('KeyModule').Key; |
|||
|
|||
module.exports = Key; |
|||
|
@ -0,0 +1,37 @@ |
|||
'use strict'; |
|||
|
|||
var chai = chai || require('chai'); |
|||
var bitcore = bitcore || require('../bitcore'); |
|||
var coinUtil = coinUtil || bitcore.util; |
|||
var buffertools = require('buffertools'); |
|||
var bignum = require('bignum'); |
|||
|
|||
var should = chai.should(); |
|||
var assert = chai.assert; |
|||
|
|||
var Curve = bitcore.Curve; |
|||
|
|||
describe('Curve', function() { |
|||
|
|||
it('should initialize the main object', function() { |
|||
should.exist(Curve); |
|||
}); |
|||
|
|||
describe('getN', function() { |
|||
it('should return a big number', function() { |
|||
var N = Curve.getN(); |
|||
should.exist(N); |
|||
N.toBuffer({size: 32}).toString('hex').length.should.equal(64); |
|||
}); |
|||
}); |
|||
|
|||
describe('getG', function() { |
|||
it('should return a Point', function() { |
|||
var G = Curve.getG(); |
|||
should.exist(G.x); |
|||
G.x.toBuffer({size: 32}).toString('hex').length.should.equal(64); |
|||
G.y.toBuffer({size: 32}).toString('hex').length.should.equal(64); |
|||
}); |
|||
}); |
|||
|
|||
}); |
Loading…
Reference in new issue