@ -1,6 +1,6 @@
var should = require ( 'chai' ) . should ( ) ;
var Stealth = require ( '../lib/expmt/stealth' ) ;
var Key = require ( '../lib/key' ) ;
var Keypair = require ( '../lib/keypair ' ) ;
var Privkey = require ( '../lib/privkey' ) ;
var Pubkey = require ( '../lib/pubkey' ) ;
var BN = require ( '../lib/bn' ) ;
@ -10,19 +10,19 @@ var base58check = require('../lib/base58check');
describe ( 'Stealth' , function ( ) {
var stealth = Stealth ( ) ;
stealth . payloadKey = Key ( ) ;
stealth . payloadKey . privkey = Privkey ( ) ;
stealth . payloadKey . privkey . bn = BN ( ) . fromBuffer ( Hash . sha256 ( new Buffer ( 'test 1' ) ) ) ;
stealth . payloadKey . privkey2pubkey ( ) ;
stealth . scanKey = Key ( ) ;
stealth . scanKey . privkey = Privkey ( ) ;
stealth . scanKey . privkey . bn = BN ( ) . fromBuffer ( Hash . sha256 ( new Buffer ( 'test 2' ) ) ) ;
stealth . scanKey . privkey2pubkey ( ) ;
var senderKey = Key ( ) ;
senderKey . privkey = Privkey ( ) ;
senderKey . privkey . bn = BN ( ) . fromBuffer ( Hash . sha256 ( new Buffer ( 'test 3' ) ) ) ;
senderKey . privkey2pubkey ( ) ;
stealth . payloadKeypair = Keypair ( ) ;
stealth . payloadKeypair . privkey = Privkey ( ) ;
stealth . payloadKeypair . privkey . bn = BN ( ) . fromBuffer ( Hash . sha256 ( new Buffer ( 'test 1' ) ) ) ;
stealth . payloadKeypair . privkey2pubkey ( ) ;
stealth . scanKeypair = Keypair ( ) ;
stealth . scanKeypair . privkey = Privkey ( ) ;
stealth . scanKeypair . privkey . bn = BN ( ) . fromBuffer ( Hash . sha256 ( new Buffer ( 'test 2' ) ) ) ;
stealth . scanKeypair . privkey2pubkey ( ) ;
var senderKeypair = Keypair ( ) ;
senderKeypair . privkey = Privkey ( ) ;
senderKeypair . privkey . bn = BN ( ) . fromBuffer ( Hash . sha256 ( new Buffer ( 'test 3' ) ) ) ;
senderKeypair . privkey2pubkey ( ) ;
var addressString = '9dDbC9FzZ74r8njQkXD6W27gtrxLiWaeFPHxeo1fynQRXPicqxVt7u95ozbwoVVMXyrzaHKN9owsteg63FgwDfrxWx82SAW' ;
@ -39,7 +39,7 @@ describe('Stealth', function() {
describe ( '#set' , function ( ) {
it ( 'should set payload key' , function ( ) {
should . exist ( Stealth ( ) . set ( { payloadKey : stealth . payloadKey } ) . payloadKey ) ;
should . exist ( Stealth ( ) . set ( { payloadKeypair : stealth . payloadKeypair } ) . payloadKeypair ) ;
} ) ;
} ) ;
@ -50,8 +50,8 @@ describe('Stealth', function() {
var stealth2 = new Stealth ( ) ;
var buf = base58check . decode ( addressString ) ;
stealth2 . fromAddressBuffer ( buf ) ;
stealth2 . payloadKey . pubkey . toString ( ) . should . equal ( stealth . payloadKey . pubkey . toString ( ) ) ;
stealth2 . scanKey . pubkey . toString ( ) . should . equal ( stealth . scanKey . pubkey . toString ( ) ) ;
stealth2 . payloadKeypair . pubkey . toString ( ) . should . equal ( stealth . payloadKeypair . pubkey . toString ( ) ) ;
stealth2 . scanKeypair . pubkey . toString ( ) . should . equal ( stealth . scanKeypair . pubkey . toString ( ) ) ;
} ) ;
} ) ;
@ -61,8 +61,8 @@ describe('Stealth', function() {
it ( 'should give a stealth address with the right pubkeys' , function ( ) {
var stealth2 = new Stealth ( ) ;
stealth2 . fromAddressString ( addressString ) ;
stealth2 . payloadKey . pubkey . toString ( ) . should . equal ( stealth . payloadKey . pubkey . toString ( ) ) ;
stealth2 . scanKey . pubkey . toString ( ) . should . equal ( stealth . scanKey . pubkey . toString ( ) ) ;
stealth2 . payloadKeypair . pubkey . toString ( ) . should . equal ( stealth . payloadKeypair . pubkey . toString ( ) ) ;
stealth2 . scanKeypair . pubkey . toString ( ) . should . equal ( stealth . scanKeypair . pubkey . toString ( ) ) ;
} ) ;
} ) ;
@ -71,42 +71,42 @@ describe('Stealth', function() {
it ( 'should create a new stealth from random' , function ( ) {
var stealth = Stealth ( ) . fromRandom ( ) ;
should . exist ( stealth . payloadKey . privkey . bn . gt ( 0 ) ) ;
should . exist ( stealth . scanKey . privkey . bn . gt ( 0 ) ) ;
should . exist ( stealth . payloadKeypair . privkey . bn . gt ( 0 ) ) ;
should . exist ( stealth . scanKeypair . privkey . bn . gt ( 0 ) ) ;
} ) ;
} ) ;
describe ( '#getSharedKeyAsReceiver' , function ( ) {
describe ( '#getSharedKeypair AsReceiver' , function ( ) {
it ( 'should return a key' , function ( ) {
var key = stealth . getSharedKeyAsReceiver ( senderKey . pubkey ) ;
( key instanceof Key ) . should . equal ( true ) ;
var key = stealth . getSharedKeypair AsReceiver ( senderKeypair . pubkey ) ;
( key instanceof Keypair ) . should . equal ( true ) ;
} ) ;
} ) ;
describe ( '#getSharedKeyAsSender' , function ( ) {
describe ( '#getSharedKeypair AsSender' , function ( ) {
it ( 'should return a key' , function ( ) {
var stealth2 = new Stealth ( ) ;
stealth2 . payloadKey = new Key ( ) ;
stealth2 . payloadKey . pubkey = stealth . payloadKey . pubkey ;
stealth2 . scanKey = new Key ( ) ;
stealth2 . scanKey . pubkey = stealth . scanKey . pubkey ;
var key = stealth2 . getSharedKeyAsSender ( senderKey ) ;
( key instanceof Key ) . should . equal ( true ) ;
stealth2 . payloadKeypair = new Keypair ( ) ;
stealth2 . payloadKeypair . pubkey = stealth . payloadKeypair . pubkey ;
stealth2 . scanKeypair = new Keypair ( ) ;
stealth2 . scanKeypair . pubkey = stealth . scanKeypair . pubkey ;
var key = stealth2 . getSharedKeypair AsSender ( senderKeypair ) ;
( key instanceof Keypair ) . should . equal ( true ) ;
} ) ;
it ( 'should return the same key as getSharedKeyAsReceiver' , function ( ) {
it ( 'should return the same key as getSharedKeypair AsReceiver' , function ( ) {
var stealth2 = new Stealth ( ) ;
stealth2 . payloadKey = new Key ( ) ;
stealth2 . payloadKey . pubkey = stealth . payloadKey . pubkey ;
stealth2 . scanKey = new Key ( ) ;
stealth2 . scanKey . pubkey = stealth . scanKey . pubkey ;
var key = stealth2 . getSharedKeyAsSender ( senderKey ) ;
stealth2 . payloadKeypair = new Keypair ( ) ;
stealth2 . payloadKeypair . pubkey = stealth . payloadKeypair . pubkey ;
stealth2 . scanKeypair = new Keypair ( ) ;
stealth2 . scanKeypair . pubkey = stealth . scanKeypair . pubkey ;
var key = stealth2 . getSharedKeypair AsSender ( senderKeypair ) ;
var key2 = stealth . getSharedKeyAsReceiver ( senderKey . pubkey ) ;
var key2 = stealth . getSharedKeypair AsReceiver ( senderKeypair . pubkey ) ;
key . toString ( ) . should . equal ( key2 . toString ( ) ) ;
} ) ;
@ -115,7 +115,7 @@ describe('Stealth', function() {
describe ( '#getReceivePubkeyAsReceiver' , function ( ) {
it ( 'should return a pubkey' , function ( ) {
var pubkey = stealth . getReceivePubkeyAsReceiver ( senderKey . pubkey ) ;
var pubkey = stealth . getReceivePubkeyAsReceiver ( senderKeypair . pubkey ) ;
( pubkey instanceof Pubkey ) . should . equal ( true ) ;
} ) ;
@ -124,33 +124,33 @@ describe('Stealth', function() {
describe ( '#getReceivePubkeyAsSender' , function ( ) {
it ( 'should return a pubkey' , function ( ) {
var pubkey = stealth . getReceivePubkeyAsSender ( senderKey ) ;
var pubkey = stealth . getReceivePubkeyAsSender ( senderKeypair ) ;
( pubkey instanceof Pubkey ) . should . equal ( true ) ;
} ) ;
it ( 'should return the same pubkey as getReceivePubkeyAsReceiver' , function ( ) {
var pubkey = stealth . getReceivePubkeyAsSender ( senderKey ) ;
var pubkey2 = stealth . getReceivePubkeyAsReceiver ( senderKey . pubkey ) ;
var pubkey = stealth . getReceivePubkeyAsSender ( senderKeypair ) ;
var pubkey2 = stealth . getReceivePubkeyAsReceiver ( senderKeypair . pubkey ) ;
pubkey2 . toString ( ) . should . equal ( pubkey . toString ( ) ) ;
} ) ;
} ) ;
describe ( '#getReceiveKey' , function ( ) {
describe ( '#getReceiveKeypair ' , function ( ) {
it ( 'should return a key' , function ( ) {
var key = stealth . getReceiveKey ( senderKey . pubkey ) ;
( key instanceof Key ) . should . equal ( true ) ;
var key = stealth . getReceiveKeypair ( senderKeypair . pubkey ) ;
( key instanceof Keypair ) . should . equal ( true ) ;
} ) ;
it ( 'should return a key with the same pubkey as getReceivePubkeyAsReceiver' , function ( ) {
var key = stealth . getReceiveKey ( senderKey . pubkey ) ;
var pubkey = stealth . getReceivePubkeyAsReceiver ( senderKey . pubkey ) ;
var key = stealth . getReceiveKeypair ( senderKeypair . pubkey ) ;
var pubkey = stealth . getReceivePubkeyAsReceiver ( senderKeypair . pubkey ) ;
key . pubkey . toString ( ) . should . equal ( pubkey . toString ( ) ) ;
} ) ;
it ( 'should return private key with length 32 or less' , function ( ) {
var key = stealth . getReceiveKey ( senderKey . pubkey ) ;
var key = stealth . getReceiveKeypair ( senderKeypair . pubkey ) ;
key . privkey . bn . toBuffer ( ) . length . should . be . below ( 33 ) ;
} ) ;
@ -160,12 +160,12 @@ describe('Stealth', function() {
it ( 'should return true if it (the transaction or message) is for me' , function ( ) {
var pubkeyhash = new Buffer ( '3cb64fa6ee9b3e8754e3e2bd033bf61048604a99' , 'hex' ) ;
stealth . isForMe ( senderKey . pubkey , pubkeyhash ) . should . equal ( true ) ;
stealth . isForMe ( senderKeypair . pubkey , pubkeyhash ) . should . equal ( true ) ;
} ) ;
it ( 'should return false if it (the transaction or message) is not for me' , function ( ) {
var pubkeyhash = new Buffer ( '00b64fa6ee9b3e8754e3e2bd033bf61048604a99' , 'hex' ) ;
stealth . isForMe ( senderKey . pubkey , pubkeyhash ) . should . equal ( false ) ;
stealth . isForMe ( senderKeypair . pubkey , pubkeyhash ) . should . equal ( false ) ;
} ) ;
} ) ;