create-ecdh 4.0.1 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  language: node_js
2
-
2
+ sudo: false
3
3
  node_js:
4
- - "0.10"
5
- - "0.11"
6
- - "0.12"
7
- - "iojs"
4
+ - 6
5
+ - 8
6
+ - 9
7
+ - 10
package/browser.js CHANGED
@@ -1,122 +1,124 @@
1
- var elliptic = require('elliptic');
2
- var BN = require('bn.js');
1
+ var elliptic = require('elliptic')
2
+ var BN = require('bn.js')
3
3
 
4
- module.exports = function createECDH(curve) {
5
- return new ECDH(curve);
6
- };
4
+ module.exports = function createECDH (curve) {
5
+ return new ECDH(curve)
6
+ }
7
7
 
8
8
  var aliases = {
9
- secp256k1: {
10
- name: 'secp256k1',
11
- byteLength: 32
12
- },
13
- secp224r1: {
14
- name: 'p224',
15
- byteLength: 28
16
- },
17
- prime256v1: {
18
- name: 'p256',
19
- byteLength: 32
20
- },
21
- prime192v1: {
22
- name: 'p192',
23
- byteLength: 24
24
- },
25
- ed25519: {
26
- name: 'ed25519',
27
- byteLength: 32
28
- },
29
- secp384r1: {
30
- name: 'p384',
31
- byteLength: 48
32
- },
33
- secp521r1: {
34
- name: 'p521',
35
- byteLength: 66
36
- }
37
- };
9
+ secp256k1: {
10
+ name: 'secp256k1',
11
+ byteLength: 32
12
+ },
13
+ secp224r1: {
14
+ name: 'p224',
15
+ byteLength: 28
16
+ },
17
+ prime256v1: {
18
+ name: 'p256',
19
+ byteLength: 32
20
+ },
21
+ prime192v1: {
22
+ name: 'p192',
23
+ byteLength: 24
24
+ },
25
+ ed25519: {
26
+ name: 'ed25519',
27
+ byteLength: 32
28
+ },
29
+ secp384r1: {
30
+ name: 'p384',
31
+ byteLength: 48
32
+ },
33
+ secp521r1: {
34
+ name: 'p521',
35
+ byteLength: 66
36
+ }
37
+ }
38
38
 
39
- aliases.p224 = aliases.secp224r1;
40
- aliases.p256 = aliases.secp256r1 = aliases.prime256v1;
41
- aliases.p192 = aliases.secp192r1 = aliases.prime192v1;
42
- aliases.p384 = aliases.secp384r1;
43
- aliases.p521 = aliases.secp521r1;
39
+ aliases.p224 = aliases.secp224r1
40
+ aliases.p256 = aliases.secp256r1 = aliases.prime256v1
41
+ aliases.p192 = aliases.secp192r1 = aliases.prime192v1
42
+ aliases.p384 = aliases.secp384r1
43
+ aliases.p521 = aliases.secp521r1
44
44
 
45
- function ECDH(curve) {
46
- this.curveType = aliases[curve];
47
- if (!this.curveType ) {
48
- this.curveType = {
49
- name: curve
50
- };
51
- }
52
- this.curve = new elliptic.ec(this.curveType.name);
53
- this.keys = void 0;
45
+ function ECDH (curve) {
46
+ this.curveType = aliases[curve]
47
+ if (!this.curveType) {
48
+ this.curveType = {
49
+ name: curve
50
+ }
51
+ }
52
+ this.curve = new elliptic.ec(this.curveType.name) // eslint-disable-line new-cap
53
+ this.keys = void 0
54
54
  }
55
55
 
56
56
  ECDH.prototype.generateKeys = function (enc, format) {
57
- this.keys = this.curve.genKeyPair();
58
- return this.getPublicKey(enc, format);
59
- };
57
+ this.keys = this.curve.genKeyPair()
58
+ return this.getPublicKey(enc, format)
59
+ }
60
60
 
61
61
  ECDH.prototype.computeSecret = function (other, inenc, enc) {
62
- inenc = inenc || 'utf8';
63
- if (!Buffer.isBuffer(other)) {
64
- other = new Buffer(other, inenc);
65
- }
66
- var otherPub = this.curve.keyFromPublic(other).getPublic();
67
- var out = otherPub.mul(this.keys.getPrivate()).getX();
68
- return formatReturnValue(out, enc, this.curveType.byteLength);
69
- };
62
+ inenc = inenc || 'utf8'
63
+ if (!Buffer.isBuffer(other)) {
64
+ other = new Buffer(other, inenc)
65
+ }
66
+ var otherPub = this.curve.keyFromPublic(other).getPublic()
67
+ var out = otherPub.mul(this.keys.getPrivate()).getX()
68
+ return formatReturnValue(out, enc, this.curveType.byteLength)
69
+ }
70
70
 
71
71
  ECDH.prototype.getPublicKey = function (enc, format) {
72
- var key = this.keys.getPublic(format === 'compressed', true);
73
- if (format === 'hybrid') {
74
- if (key[key.length - 1] % 2) {
75
- key[0] = 7;
76
- } else {
77
- key [0] = 6;
78
- }
79
- }
80
- return formatReturnValue(key, enc);
81
- };
72
+ var key = this.keys.getPublic(format === 'compressed', true)
73
+ if (format === 'hybrid') {
74
+ if (key[key.length - 1] % 2) {
75
+ key[0] = 7
76
+ } else {
77
+ key[0] = 6
78
+ }
79
+ }
80
+ return formatReturnValue(key, enc)
81
+ }
82
82
 
83
83
  ECDH.prototype.getPrivateKey = function (enc) {
84
- return formatReturnValue(this.keys.getPrivate(), enc);
85
- };
84
+ return formatReturnValue(this.keys.getPrivate(), enc)
85
+ }
86
86
 
87
87
  ECDH.prototype.setPublicKey = function (pub, enc) {
88
- enc = enc || 'utf8';
89
- if (!Buffer.isBuffer(pub)) {
90
- pub = new Buffer(pub, enc);
91
- }
92
- this.keys._importPublic(pub);
93
- return this;
94
- };
88
+ enc = enc || 'utf8'
89
+ if (!Buffer.isBuffer(pub)) {
90
+ pub = new Buffer(pub, enc)
91
+ }
92
+ this.keys._importPublic(pub)
93
+ return this
94
+ }
95
95
 
96
96
  ECDH.prototype.setPrivateKey = function (priv, enc) {
97
- enc = enc || 'utf8';
98
- if (!Buffer.isBuffer(priv)) {
99
- priv = new Buffer(priv, enc);
100
- }
101
- var _priv = new BN(priv);
102
- _priv = _priv.toString(16);
103
- this.keys._importPrivate(_priv);
104
- return this;
105
- };
97
+ enc = enc || 'utf8'
98
+ if (!Buffer.isBuffer(priv)) {
99
+ priv = new Buffer(priv, enc)
100
+ }
101
+
102
+ var _priv = new BN(priv)
103
+ _priv = _priv.toString(16)
104
+ this.keys = this.curve.genKeyPair()
105
+ this.keys._importPrivate(_priv)
106
+ return this
107
+ }
106
108
 
107
- function formatReturnValue(bn, enc, len) {
108
- if (!Array.isArray(bn)) {
109
- bn = bn.toArray();
110
- }
111
- var buf = new Buffer(bn);
112
- if (len && buf.length < len) {
113
- var zeros = new Buffer(len - buf.length);
114
- zeros.fill(0);
115
- buf = Buffer.concat([zeros, buf]);
116
- }
117
- if (!enc) {
118
- return buf;
119
- } else {
120
- return buf.toString(enc);
121
- }
109
+ function formatReturnValue (bn, enc, len) {
110
+ if (!Array.isArray(bn)) {
111
+ bn = bn.toArray()
112
+ }
113
+ var buf = new Buffer(bn)
114
+ if (len && buf.length < len) {
115
+ var zeros = new Buffer(len - buf.length)
116
+ zeros.fill(0)
117
+ buf = Buffer.concat([zeros, buf])
118
+ }
119
+ if (!enc) {
120
+ return buf
121
+ } else {
122
+ return buf.toString(enc)
123
+ }
122
124
  }
package/index.js CHANGED
@@ -1,3 +1,3 @@
1
- var createECDH = require('crypto').createECDH;
1
+ var createECDH = require('crypto').createECDH
2
2
 
3
- module.exports = createECDH || require('./browser');
3
+ module.exports = createECDH || require('./browser')
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "create-ecdh",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "createECDH but browserifiable",
5
5
  "main": "index.js",
6
6
  "browser": "browser.js",
7
7
  "scripts": {
8
- "test": "node test.js | tspec"
8
+ "test": "standard && node test.js | tspec"
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
@@ -25,7 +25,8 @@
25
25
  "homepage": "https://github.com/crypto-browserify/createECDH",
26
26
  "dependencies": {
27
27
  "bn.js": "^4.1.0",
28
- "elliptic": "^6.0.0"
28
+ "elliptic": "^6.0.0",
29
+ "standard": "^5.4.1"
29
30
  },
30
31
  "devDependencies": {
31
32
  "tap-spec": "^1.0.1",