Browse Source

works in browser

compiled with ./browser/build and then open test/index.html
patch-2
Ryan X. Charles 11 years ago
parent
commit
bd3a2c42ec
  1. 2
      .gitignore
  2. 4
      browser/build
  3. 3
      package.json
  4. 18
      test/index.html
  5. 10
      test/test.ecdsa.js

2
.gitignore

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

4
browser/build

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

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

18
test/index.html

@ -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>

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

Loading…
Cancel
Save