From bd3a2c42ec3820b573abb0937d6623910dce7b1f Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Sat, 9 Aug 2014 22:47:32 -0700 Subject: [PATCH] works in browser compiled with ./browser/build and then open test/index.html --- .gitignore | 2 ++ browser/build | 4 ++++ package.json | 3 ++- test/index.html | 18 ++++++++++++++++++ test/test.ecdsa.js | 10 ++++++---- 5 files changed, 32 insertions(+), 5 deletions(-) create mode 100755 browser/build create mode 100644 test/index.html diff --git a/.gitignore b/.gitignore index 2716af2..d3c99a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.swp coverage node_modules +browser/privsec.js +browser/tests.js diff --git a/browser/build b/browser/build new file mode 100755 index 0000000..136320a --- /dev/null +++ b/browser/build @@ -0,0 +1,4 @@ +#!/bin/bash + +browserify index.js -o browser/privsec.js +ls test/test.* | xargs browserify -o browser/tests.js diff --git a/package.json b/package.json index 7d56d18..3399445 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ }, "devDependencies": { "chai": "~1.9.1", - "mocha": "~1.21.0" + "mocha": "~1.21.0", + "browserify": "~5.9.1" }, "author": "Ryan X. Charles ", "license": "MIT" diff --git a/test/index.html b/test/index.html new file mode 100644 index 0000000..54742fd --- /dev/null +++ b/test/index.html @@ -0,0 +1,18 @@ + + + + Mocha + + + + + +
+ + + + + + diff --git a/test/test.ecdsa.js b/test/test.ecdsa.js index 1632f9c..915acf7 100644 --- a/test/test.ecdsa.js +++ b/test/test.ecdsa.js @@ -62,18 +62,20 @@ describe("ecdsa", function() { it('should return an error if the pubkey is invalid', function() { var ecdsa = new ECDSA(); ecdsa.hash = Hash.sha256(new Buffer('test')); - ecdsa.sigError().should.equal("Invalid pubkey: TypeError: Cannot read property 'pubkey' of undefined"); + ecdsa.sigError().indexOf("Invalid pubkey").should.equal(0); }); it('should return an error if r, s are invalid', function() { var ecdsa = new ECDSA(); ecdsa.hash = Hash.sha256(new Buffer('test')); - ecdsa.pubkey = new Pubkey(); - ecdsa.pubkey.fromDER(new Buffer('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341', 'hex')); + var pk = new Pubkey(); + pk.fromDER(new Buffer('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341', 'hex')); + ecdsa.key = new Key(); + ecdsa.key.pubkey = pk; ecdsa.sig = new Signature(); ecdsa.sig.r = bn(0); ecdsa.sig.s = bn(0); - ecdsa.sigError().should.equal("Invalid pubkey: TypeError: Cannot read property 'pubkey' of undefined"); + ecdsa.sigError().should.equal("r and s not in range"); }); it('should return an error if the signature is incorrect', function() {