@ -4,7 +4,7 @@ var _ = require('lodash');
var chai = require ( 'chai' ) ;
var chai = require ( 'chai' ) ;
var sinon = require ( 'sinon' ) ;
var sinon = require ( 'sinon' ) ;
var should = chai . should ( ) ;
var should = chai . should ( ) ;
var Sign Utils = require ( '../lib/sign utils' ) ;
var Wallet Utils = require ( '../lib/wallet utils' ) ;
var aText = 'hola' ;
var aText = 'hola' ;
@ -14,56 +14,55 @@ var aSignature = '3045022100d6186930e4cd9984e3168e15535e2297988555838ad10126d6c2
var otherPubKey = '02555a2d45e309c00cc8c5090b6ec533c6880ab2d3bc970b3943def989b3373f16' ;
var otherPubKey = '02555a2d45e309c00cc8c5090b6ec533c6880ab2d3bc970b3943def989b3373f16' ;
describe ( 'Sign Utils' , function ( ) {
describe ( 'Wallet Utils' , function ( ) {
describe ( '#hash' , function ( ) {
describe ( '#hashMessage ' , function ( ) {
it ( 'Should create a hash' , function ( ) {
it ( 'Should create a hash' , function ( ) {
var res = Sign Utils. hash ( aText ) ;
var res = Wallet Utils. hashMessage ( aText ) ;
res . toString ( 'hex' ) . should . equal ( '4102b8a140ec642feaa1c645345f714bc7132d4fd2f7f6202db8db305a96172f' ) ;
res . toString ( 'hex' ) . should . equal ( '4102b8a140ec642feaa1c645345f714bc7132d4fd2f7f6202db8db305a96172f' ) ;
} ) ;
} ) ;
} ) ;
} ) ;
describe ( '#sign' , function ( ) {
describe ( '#signMessage ' , function ( ) {
it ( 'Should sign' , function ( ) {
it ( 'Should sign a message ' , function ( ) {
var sig = Sign Utils. sign ( aText , aPrivKey ) ;
var sig = Wallet Utils. signMessage ( aText , aPrivKey ) ;
should . exist ( sig ) ;
should . exist ( sig ) ;
sig . should . equal ( aSignature ) ;
sig . should . equal ( aSignature ) ;
} ) ;
} ) ;
it ( 'Should fail to sign with wrong args' , function ( ) {
it ( 'Should fail to sign with wrong args' , function ( ) {
( function ( ) {
( function ( ) {
Sign Utils. sign ( aText , aPubKey ) ;
Wallet Utils. signMessage ( aText , aPubKey ) ;
} ) . should . throw ( 'Number' ) ;
} ) . should . throw ( 'Number' ) ;
} ) ;
} ) ;
} ) ;
} ) ;
describe ( '#verify' , function ( ) {
describe ( '#verifyMessage ' , function ( ) {
it ( 'Should fail to verify a malformed signature' , function ( ) {
it ( 'Should fail to verify a malformed signature' , function ( ) {
var res = Sign Utils. verify ( aText , 'badsignature' , otherPubKey ) ;
var res = Wallet Utils. verifyMessage ( aText , 'badsignature' , otherPubKey ) ;
should . exist ( res ) ;
should . exist ( res ) ;
res . should . equal ( false ) ;
res . should . equal ( false ) ;
} ) ;
} ) ;
it ( 'Should fail to verify a null signature' , function ( ) {
it ( 'Should fail to verify a null signature' , function ( ) {
var res = Sign Utils. verify ( aText , null , otherPubKey ) ;
var res = Wallet Utils. verifyMessage ( aText , null , otherPubKey ) ;
should . exist ( res ) ;
should . exist ( res ) ;
res . should . equal ( false ) ;
res . should . equal ( false ) ;
} ) ;
} ) ;
it ( 'Should fail to verify with wrong pubkey' , function ( ) {
it ( 'Should fail to verify with wrong pubkey' , function ( ) {
var res = Sign Utils. verify ( aText , aSignature , otherPubKey ) ;
var res = Wallet Utils. verifyMessage ( aText , aSignature , otherPubKey ) ;
should . exist ( res ) ;
should . exist ( res ) ;
res . should . equal ( false ) ;
res . should . equal ( false ) ;
} ) ;
} ) ;
it ( 'Should verify' , function ( ) {
it ( 'Should verify' , function ( ) {
var res = Sign Utils. verify ( aText , aSignature , aPubKey ) ;
var res = Wallet Utils. verifyMessage ( aText , aSignature , aPubKey ) ;
should . exist ( res ) ;
should . exist ( res ) ;
res . should . equal ( true ) ;
res . should . equal ( true ) ;
} ) ;
} ) ;
} ) ;
} ) ;
describe ( '#sign #verify round trip' , function ( ) {
describe ( '#signMessage #verifyMessage round trip' , function ( ) {
it ( 'Should sign and verify' , function ( ) {
it ( 'Should sign and verify' , function ( ) {
var aLongerText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." ;
var aLongerText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." ;
var sig = Sign Utils. sign ( aLongerText , aPrivKey ) ;
var sig = Wallet Utils. signMessage ( aLongerText , aPrivKey ) ;
Sign Utils. verify ( aLongerText , sig , aPubKey ) . should . equal ( true ) ;
Wallet Utils. verifyMessage ( aLongerText , sig , aPubKey ) . should . equal ( true ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;