create-ecdh 2.0.2 → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2017 createECDH contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/browser.js CHANGED
@@ -1,112 +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
- };
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
+ }
30
38
 
31
- aliases.p224 = aliases.secp224r1;
32
- aliases.p256 = aliases.secp256r1 = aliases.prime256v1;
33
- aliases.p192 = aliases.secp192r1 = aliases.prime192v1;
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
34
44
 
35
- function ECDH(curve) {
36
- this.curveType = aliases[curve];
37
- if (!this.curveType ) {
38
- this.curveType = {
39
- name: curve
40
- };
41
- }
42
- this.curve = new elliptic.ec(this.curveType.name);
43
- 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
44
54
  }
45
55
 
46
56
  ECDH.prototype.generateKeys = function (enc, format) {
47
- this.keys = this.curve.genKeyPair();
48
- return this.getPublicKey(enc, format);
49
- };
57
+ this.keys = this.curve.genKeyPair()
58
+ return this.getPublicKey(enc, format)
59
+ }
50
60
 
51
61
  ECDH.prototype.computeSecret = function (other, inenc, enc) {
52
- inenc = inenc || 'utf8';
53
- if (!Buffer.isBuffer(other)) {
54
- other = new Buffer(other, inenc);
55
- }
56
- var otherPub = this.curve.keyFromPublic(other).getPublic();
57
- var out = otherPub.mul(this.keys.getPrivate()).getX();
58
- return formatReturnValue(out, enc, this.curveType.byteLength);
59
- };
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
+ }
60
70
 
61
71
  ECDH.prototype.getPublicKey = function (enc, format) {
62
- var key = this.keys.getPublic(format === 'compressed', true);
63
- if (format === 'hybrid') {
64
- if (key[key.length - 1] % 2) {
65
- key[0] = 7;
66
- } else {
67
- key [0] = 6;
68
- }
69
- }
70
- return formatReturnValue(key, enc);
71
- };
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
82
 
73
83
  ECDH.prototype.getPrivateKey = function (enc) {
74
- return formatReturnValue(this.keys.getPrivate(), enc);
75
- };
84
+ return formatReturnValue(this.keys.getPrivate(), enc)
85
+ }
76
86
 
77
87
  ECDH.prototype.setPublicKey = function (pub, enc) {
78
- enc = enc || 'utf8';
79
- if (!Buffer.isBuffer(pub)) {
80
- pub = new Buffer(pub, enc);
81
- }
82
- this.keys._importPublic(pub);
83
- return this;
84
- };
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
+ }
85
95
 
86
96
  ECDH.prototype.setPrivateKey = function (priv, enc) {
87
- enc = enc || 'utf8';
88
- if (!Buffer.isBuffer(priv)) {
89
- priv = new Buffer(priv, enc);
90
- }
91
- var _priv = new BN(priv);
92
- _priv = _priv.toString(16);
93
- this.keys._importPrivate(_priv);
94
- return this;
95
- };
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
+ }
96
108
 
97
- function formatReturnValue(bn, enc, len) {
98
- if (!Array.isArray(bn)) {
99
- bn = bn.toArray();
100
- }
101
- var buf = new Buffer(bn);
102
- if (len && buf.length < len) {
103
- var zeros = new Buffer(len - buf.length);
104
- zeros.fill(0);
105
- buf = Buffer.concat([zeros, buf]);
106
- }
107
- if (!enc) {
108
- return buf;
109
- } else {
110
- return buf.toString(enc);
111
- }
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
+ }
112
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": "2.0.2",
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",
@@ -24,8 +24,9 @@
24
24
  },
25
25
  "homepage": "https://github.com/crypto-browserify/createECDH",
26
26
  "dependencies": {
27
- "bn.js": "^2.0.0",
28
- "elliptic": "^3.0.0"
27
+ "bn.js": "^4.1.0",
28
+ "elliptic": "^6.0.0",
29
+ "standard": "^5.4.1"
29
30
  },
30
31
  "devDependencies": {
31
32
  "tap-spec": "^1.0.1",
package/readme.md CHANGED
@@ -1,4 +1,4 @@
1
1
  createECDH [![Build Status](https://travis-ci.org/crypto-browserify/createECDH.svg)](https://travis-ci.org/crypto-browserify/createECDH)
2
2
  ====
3
3
 
4
- In io.js or node >= 0.11 this module is just a shortcut to crypto.createECDH. In node <= 0.11 or the browser this is a pure JavaScript implimentation, more specifically a wrapper around [elliptic](https://github.com/indutny/elliptic), to give it the same API as node. `secp256k1`, `secp224r1` (aka p-224), `prime256v1` (aka p-256, secp256r1), `prime192v1` (aka p-192, secp192r1) curves all work in both this library and node (though only the highlighted name will work in node).
4
+ In io.js or node >= 0.11 this module is just a shortcut to crypto.createECDH. In node <= 0.11 or the browser this is a pure JavaScript implimentation, more specifically a wrapper around [elliptic](https://github.com/indutny/elliptic), to give it the same API as node. `secp256k1`, `secp224r1` (aka p224), `prime256v1` (aka p256, secp256r1), `prime192v1` (aka p192, secp192r1), `secp384r1` (aka p384), `secp521r1` (aka p521) curves all work in both this library and node (though only the highlighted name will work in node).
package/.npmignore DELETED
@@ -1 +0,0 @@
1
- test.js