@ -1,8 +1,9 @@
'use strict' ;
var assert = require ( 'assert' ) ;
var chai = chai || require ( 'chai' ) ;
var bitcore = bitcore || require ( '../bitcore' ) ;
var coinUtil = coinUtil || require ( '../util/util' ) ;
var buffertools = require ( 'buffertools' ) ;
var should = chai . should ( ) ;
@ -118,6 +119,7 @@ describe('Key', function() {
it ( 'should exist' , function ( ) {
should . exist ( Key . addUncompressed ) ;
} ) ;
it ( 'should add two uncompressed public keys' , function ( ) {
var key1 = Key . generateSync ( ) ;
key1 . compressed = false ;
@ -128,6 +130,56 @@ describe('Key', function() {
var pubkey = Key . addUncompressed ( pubkey1 , pubkey2 ) ;
pubkey . length . should . equal ( 65 ) ;
} ) ;
it ( 'a + b should equal b + a' , function ( ) {
var key1 = Key . generateSync ( ) ;
key1 . compressed = false ;
var key2 = Key . generateSync ( ) ;
key2 . compressed = false ;
var pubkey1 = key1 . public ;
var pubkey2 = key2 . public ;
var r1 = Key . addUncompressed ( pubkey1 , pubkey2 ) ;
var r2 = Key . addUncompressed ( pubkey2 , pubkey1 ) ;
r1 . toString ( 'hex' ) . should . equal ( r2 . toString ( 'hex' ) ) ;
} ) ;
it ( 'should be able to add these two public keys without error' , function ( ) {
var key1 = new Key ( ) ;
key1 . private = coinUtil . sha256 ( "first " + 3 ) ;
key1 . compressed = false ;
key1 . regenerateSync ( ) ;
var key2 = new Key ( ) ;
key2 . private = coinUtil . sha256 ( "second " + 3 ) ;
key2 . compressed = false ;
key2 . regenerateSync ( ) ;
var pubkey1 = key1 . public ;
var pubkey2 = key2 . public ;
var pubkey = Key . addUncompressed ( pubkey1 , pubkey2 ) ;
pubkey . length . should . equal ( 65 ) ;
var key = new Key ( ) ;
key . public = pubkey ;
assert ( key . public !== null ) ;
} ) ;
it ( 'should be able to add many public keys without error' , function ( ) {
for ( var i = 0 ; i <= 1000 ; i ++ ) {
var key1 = new Key ( ) ;
key1 . private = coinUtil . sha256 ( "first " + i ) ;
key1 . compressed = false ;
key1 . regenerateSync ( ) ;
var key2 = new Key ( ) ;
key2 . private = coinUtil . sha256 ( "second " + i ) ;
key2 . compressed = false ;
key2 . regenerateSync ( ) ;
var pubkey1 = key1 . public ;
var pubkey2 = key2 . public ;
var pubkey = Key . addUncompressed ( pubkey1 , pubkey2 ) ;
pubkey . length . should . equal ( 65 ) ;
var key = new Key ( ) ;
key . public = pubkey ;
assert ( key . public !== null ) ;
} ;
} ) ;
} ) ;
} ) ;