Skip to content

Commit 882de00

Browse files
committed
modularize ecdh
1 parent e896146 commit 882de00

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ var dh = require('diffie-hellman');
4343
})
4444

4545
require('browserify-sign/inject')(module.exports, exports);
46-
require('create-ecdh/inject')(module.exports, exports);
47-
require('public-encrypt/inject')(module.exports, exports);
46+
47+
exports.createECDH = require('create-ecdh');
48+
49+
var publicEncrypt = require('public-encrypt');
4850

4951
// the least I can do is make error messages for the rest of the node.js/crypto api.
5052
[

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"dependencies": {
1919
"browserify-aes": "^1.0.0",
2020
"browserify-sign": "2.8.0",
21-
"create-ecdh": "1.0.3",
21+
"create-ecdh": "^2.0.0",
2222
"create-hash": "^1.1.0",
2323
"create-hmac": "^1.1.0",
2424
"diffie-hellman": "^3.0.1",

test/ecdh.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
var mods = [
2-
'secp256k1'
2+
'secp256k1',
3+
'secp224r1',
4+
'prime256v1',
5+
'prime192v1'
36
];
47
var test = require('tape');
5-
var crypto = require('../');
8+
var createECDH1 = require('../').createECDH;
9+
var createECDH2 = require('create-ecdh/browser');
610
test('createECDH', function (t) {
711
mods.forEach(function (mod) {
812
t.test(mod + ' uncompressed', function (t){
913
t.plan(2);
10-
var dh1 = crypto.createECDH(mod);
14+
var dh1 = createECDH1(mod);
1115
dh1.generateKeys();
12-
var dh2 = crypto.createECDH(mod);
16+
var dh2 = createECDH2(mod);
1317
dh2.generateKeys();
1418
var pubk1 = dh1.getPublicKey();
1519
var pubk2 = dh2.getPublicKey();
@@ -20,9 +24,9 @@ mods.forEach(function (mod) {
2024
});
2125
t.test(mod + ' compressed', function (t){
2226
t.plan(2);
23-
var dh1 = crypto.createECDH(mod);
27+
var dh1 = createECDH1(mod);
2428
dh1.generateKeys();
25-
var dh2 = crypto.createECDH(mod);
29+
var dh2 = createECDH2(mod);
2630
dh2.generateKeys();
2731
var pubk1 = dh1.getPublicKey(null, 'compressed');
2832
var pubk2 = dh2.getPublicKey(null, 'compressed');
@@ -33,8 +37,8 @@ mods.forEach(function (mod) {
3337
});
3438
t.test(mod + ' set stuff', function (t){
3539
t.plan(5);
36-
var dh1 = crypto.createECDH(mod);
37-
var dh2 = crypto.createECDH(mod);
40+
var dh1 = createECDH1(mod);
41+
var dh2 = createECDH2(mod);
3842
dh1.generateKeys();
3943
dh2.generateKeys();
4044
dh1.setPrivateKey(dh2.getPrivateKey());

0 commit comments

Comments
 (0)