works in browser

compiled with ./browser/build and then open test/index.html
This commit is contained in:
Ryan X. Charles 2014-08-09 22:47:32 -07:00
parent 9649cc58e9
commit bd3a2c42ec
5 changed files with 32 additions and 5 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
*.swp
coverage
node_modules
browser/privsec.js
browser/tests.js

4
browser/build Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
browserify index.js -o browser/privsec.js
ls test/test.* | xargs browserify -o browser/tests.js

View File

@ -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 <ryanxcharles@gmail.com>",
"license": "MIT"

18
test/index.html Normal file
View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>Mocha</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script src="../browser/tests.js"></script>
<script>
mocha.run();
</script>
</body>
</html>

View File

@ -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() {