create-ecdh 4.0.4 → 4.0.5
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/.github/FUNDING.yml +12 -0
- package/CHANGELOG.md +136 -0
- package/browser.js +109 -104
- package/index.js +22 -2
- package/package.json +43 -7
- package/.travis.yml +0 -7
- /package/{readme.md → README.md} +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# These are supported funding model platforms
|
|
2
|
+
|
|
3
|
+
github: [ljharb]
|
|
4
|
+
patreon: # Replace with a single Patreon username
|
|
5
|
+
open_collective: # Replace with a single Open Collective username
|
|
6
|
+
ko_fi: # Replace with a single Ko-fi username
|
|
7
|
+
tidelift: npm/createECDH
|
|
8
|
+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
9
|
+
liberapay: # Replace with a single Liberapay username
|
|
10
|
+
issuehunt: # Replace with a single IssueHunt username
|
|
11
|
+
otechie: # Replace with a single Otechie username
|
|
12
|
+
custom: # Replace with a single custom sponsorship URL
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [v4.0.5](https://github.com/browserify/createECDH/compare/v4.0.4...v4.0.5) - 2026-11-13
|
|
9
|
+
|
|
10
|
+
### Commits
|
|
11
|
+
|
|
12
|
+
- [eslint] remove autofixable overrides [`0d88756`](https://github.com/browserify/createECDH/commit/0d88756535ce694d513cf9f4586a66194c48db2e)
|
|
13
|
+
- [meta] modernize the package [`25eea4b`](https://github.com/browserify/createECDH/commit/25eea4bc4aec9a77e1d0e3c8da4ff06e31b614f5)
|
|
14
|
+
- [eslint] remove remaining overrides [`f733f24`](https://github.com/browserify/createECDH/commit/f733f2491f804ff4faa759c65cbfb75aa028466d)
|
|
15
|
+
- [Fix] `computeSecret`, `setPublicKey`: reject public keys that are invalid for the curve [`1cfaf33`](https://github.com/browserify/createECDH/commit/1cfaf332773237e5fea4b51a2ad3efab4c22bec1)
|
|
16
|
+
- [meta] switch to eslint [`cdd622f`](https://github.com/browserify/createECDH/commit/cdd622f17b1a5948eb823352515444fa46367009)
|
|
17
|
+
- [Fix] use the JS implementation when native `setPrivateKey` does not compute the public key [`13fadb6`](https://github.com/browserify/createECDH/commit/13fadb63b6be0e72fa1917b0396fdc9f28858684)
|
|
18
|
+
- [Deps] update `bn.js`, `elliptic` [`3adc987`](https://github.com/browserify/createECDH/commit/3adc987435d3849600267cd108bdaa83e1e52ab4)
|
|
19
|
+
- [Robustness] cache `Array.isArray` at module level [`4b33188`](https://github.com/browserify/createECDH/commit/4b33188665910b01c9e8472853bf8e4787204bf4)
|
|
20
|
+
- [meta] add missing auto-changelog settings [`bc21216`](https://github.com/browserify/createECDH/commit/bc212162ed25c069c9586f7a537afd60fde1f0fd)
|
|
21
|
+
|
|
22
|
+
## [v4.0.4](https://github.com/browserify/createECDH/compare/v4.0.3...v4.0.4) - 2020-08-04
|
|
23
|
+
|
|
24
|
+
### Merged
|
|
25
|
+
|
|
26
|
+
- Update elliptic version [`#16`](https://github.com/browserify/createECDH/pull/16)
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- Update elliptic version (#16) [`#14`](https://github.com/crypto-browserify/createECDH/issues/14)
|
|
31
|
+
|
|
32
|
+
## [v4.0.3](https://github.com/browserify/createECDH/compare/v4.0.2...v4.0.3) - 2018-05-07
|
|
33
|
+
|
|
34
|
+
### Commits
|
|
35
|
+
|
|
36
|
+
- move standard to dev deps [`5b6ad7a`](https://github.com/browserify/createECDH/commit/5b6ad7a3697706b8c008135e4087c0e1a82f9efa)
|
|
37
|
+
|
|
38
|
+
## [v4.0.2](https://github.com/browserify/createECDH/compare/v4.0.1...v4.0.2) - 2018-05-07
|
|
39
|
+
|
|
40
|
+
### Merged
|
|
41
|
+
|
|
42
|
+
- Private key import [`#8`](https://github.com/browserify/createECDH/pull/8)
|
|
43
|
+
|
|
44
|
+
## [v4.0.1](https://github.com/browserify/createECDH/compare/v4.0.0...v4.0.1) - 2018-04-11
|
|
45
|
+
|
|
46
|
+
### Merged
|
|
47
|
+
|
|
48
|
+
- add license [`#10`](https://github.com/browserify/createECDH/pull/10)
|
|
49
|
+
|
|
50
|
+
## [v4.0.0](https://github.com/browserify/createECDH/compare/v3.0.0...v4.0.0) - 2015-10-29
|
|
51
|
+
|
|
52
|
+
### Merged
|
|
53
|
+
|
|
54
|
+
- update bn and elliptic [`#7`](https://github.com/browserify/createECDH/pull/7)
|
|
55
|
+
|
|
56
|
+
## [v3.0.0](https://github.com/browserify/createECDH/compare/v2.0.2...v3.0.0) - 2015-10-26
|
|
57
|
+
|
|
58
|
+
### Merged
|
|
59
|
+
|
|
60
|
+
- upgrade bn.js and elliptic, add 2 curves [`#6`](https://github.com/browserify/createECDH/pull/6)
|
|
61
|
+
|
|
62
|
+
### Commits
|
|
63
|
+
|
|
64
|
+
- upgrade bn.js and eleptic, add 2 curves [`84f7984`](https://github.com/browserify/createECDH/commit/84f798475470600dfbb2259ff03d702ccd91018d)
|
|
65
|
+
|
|
66
|
+
## [v2.0.2](https://github.com/browserify/createECDH/compare/v2.0.1...v2.0.2) - 2015-10-05
|
|
67
|
+
|
|
68
|
+
### Merged
|
|
69
|
+
|
|
70
|
+
- add browser field [`#5`](https://github.com/browserify/createECDH/pull/5)
|
|
71
|
+
|
|
72
|
+
## [v2.0.1](https://github.com/browserify/createECDH/compare/v2.0.0...v2.0.1) - 2015-05-21
|
|
73
|
+
|
|
74
|
+
### Merged
|
|
75
|
+
|
|
76
|
+
- update deps [`#4`](https://github.com/browserify/createECDH/pull/4)
|
|
77
|
+
|
|
78
|
+
### Commits
|
|
79
|
+
|
|
80
|
+
- adds npmignore [`3cbf265`](https://github.com/browserify/createECDH/commit/3cbf265600d93aef242c56e72c68ac812c844b92)
|
|
81
|
+
|
|
82
|
+
## [v2.0.0](https://github.com/browserify/createECDH/compare/v1.0.3...v2.0.0) - 2015-02-12
|
|
83
|
+
|
|
84
|
+
### Merged
|
|
85
|
+
|
|
86
|
+
- modularize, expand documentation, expand curve list [`#3`](https://github.com/browserify/createECDH/pull/3)
|
|
87
|
+
|
|
88
|
+
### Commits
|
|
89
|
+
|
|
90
|
+
- ecdh [`649d8ee`](https://github.com/browserify/createECDH/commit/649d8ee793c080c97f0dc9908075da51e5e66fd2)
|
|
91
|
+
- add prime generation [`feb843b`](https://github.com/browserify/createECDH/commit/feb843bb68872e2b2387839c10d0ecfa66476662)
|
|
92
|
+
- modularize [`96e6a1e`](https://github.com/browserify/createECDH/commit/96e6a1e18595b512ba600dd409640333d6fe30b5)
|
|
93
|
+
- gen primes [`32b0cd0`](https://github.com/browserify/createECDH/commit/32b0cd0b6c3bb8a52161a4776970d2950ac36008)
|
|
94
|
+
- clean up prime generation [`721d40b`](https://github.com/browserify/createECDH/commit/721d40b6418dfce6e356af62f297a1cced5679a7)
|
|
95
|
+
- rm fast primes [`08779de`](https://github.com/browserify/createECDH/commit/08779de3f58bf83ef7b135b867a503154cf9c472)
|
|
96
|
+
- add factory, return this on set functions [`9aa1df2`](https://github.com/browserify/createECDH/commit/9aa1df299026ea6c40a6dbd254f9d80b7cc075a3)
|
|
97
|
+
- generate primes [`f1d7cc3`](https://github.com/browserify/createECDH/commit/f1d7cc3257525be9e1a34338271dc4de27a0196d)
|
|
98
|
+
- update .travis.yml [`5576ed5`](https://github.com/browserify/createECDH/commit/5576ed5b70f622f6a70884ab963334d46e5a8afb)
|
|
99
|
+
- update eliptic [`6b3fbd0`](https://github.com/browserify/createECDH/commit/6b3fbd00c9930e23921b276acedcb1788d1d03d2)
|
|
100
|
+
- Update bn.js [`08a105a`](https://github.com/browserify/createECDH/commit/08a105a882f6db84abd81e9f9109146d20fe8562)
|
|
101
|
+
- Update bn.js [`fb6a7d9`](https://github.com/browserify/createECDH/commit/fb6a7d960c5c45469fa6abd3e67a7b1d9a976ddf)
|
|
102
|
+
- name [`99208c8`](https://github.com/browserify/createECDH/commit/99208c8728a9e671cc46d4afe97c7a3b71974f3d)
|
|
103
|
+
- travis [`810fac1`](https://github.com/browserify/createECDH/commit/810fac1b8ff14ace34ddd88c49b09bed1a45e25b)
|
|
104
|
+
- touch travis [`9039dea`](https://github.com/browserify/createECDH/commit/9039deaf14d2a1903aee048338cdf7fe5bb2e556)
|
|
105
|
+
- rm console log [`c40a075`](https://github.com/browserify/createECDH/commit/c40a075e7bf3b16e5eb6024eb472f3106b0f0f26)
|
|
106
|
+
|
|
107
|
+
## [v1.0.3](https://github.com/browserify/createECDH/compare/v1.0.2...v1.0.3) - 2014-11-04
|
|
108
|
+
|
|
109
|
+
### Commits
|
|
110
|
+
|
|
111
|
+
- Revert "bench" [`54dc2a2`](https://github.com/browserify/createECDH/commit/54dc2a28b5ff73a61c261b721b0665a349b2c67d)
|
|
112
|
+
- bench [`3a4f943`](https://github.com/browserify/createECDH/commit/3a4f943ef0070a8146c0aa8b75e20747acc24040)
|
|
113
|
+
- finish up [`de5c813`](https://github.com/browserify/createECDH/commit/de5c8132359dbf07182576e2dcdc771ae412e41f)
|
|
114
|
+
|
|
115
|
+
## [v1.0.2](https://github.com/browserify/createECDH/compare/v1.0.1...v1.0.2) - 2014-11-02
|
|
116
|
+
|
|
117
|
+
## v1.0.1 - 2015-01-03
|
|
118
|
+
|
|
119
|
+
### Commits
|
|
120
|
+
|
|
121
|
+
- ecdh [`649d8ee`](https://github.com/browserify/createECDH/commit/649d8ee793c080c97f0dc9908075da51e5e66fd2)
|
|
122
|
+
- first [`923fdc5`](https://github.com/browserify/createECDH/commit/923fdc540603443b7da981094c8906f722ce1ef8)
|
|
123
|
+
- add prime generation [`feb843b`](https://github.com/browserify/createECDH/commit/feb843bb68872e2b2387839c10d0ecfa66476662)
|
|
124
|
+
- gen primes [`32b0cd0`](https://github.com/browserify/createECDH/commit/32b0cd0b6c3bb8a52161a4776970d2950ac36008)
|
|
125
|
+
- works [`a4ec953`](https://github.com/browserify/createECDH/commit/a4ec953802fdc5944a0318331bfadea364942cde)
|
|
126
|
+
- clean up prime generation [`721d40b`](https://github.com/browserify/createECDH/commit/721d40b6418dfce6e356af62f297a1cced5679a7)
|
|
127
|
+
- Revert "bench" [`54dc2a2`](https://github.com/browserify/createECDH/commit/54dc2a28b5ff73a61c261b721b0665a349b2c67d)
|
|
128
|
+
- bench [`3a4f943`](https://github.com/browserify/createECDH/commit/3a4f943ef0070a8146c0aa8b75e20747acc24040)
|
|
129
|
+
- rm fast primes [`08779de`](https://github.com/browserify/createECDH/commit/08779de3f58bf83ef7b135b867a503154cf9c472)
|
|
130
|
+
- finish up [`de5c813`](https://github.com/browserify/createECDH/commit/de5c8132359dbf07182576e2dcdc771ae412e41f)
|
|
131
|
+
- deps [`911fcfb`](https://github.com/browserify/createECDH/commit/911fcfb2ffb579f2668a5e5dbd927bbaa36660fe)
|
|
132
|
+
- generate primes [`f1d7cc3`](https://github.com/browserify/createECDH/commit/f1d7cc3257525be9e1a34338271dc4de27a0196d)
|
|
133
|
+
- Update bn.js [`fb6a7d9`](https://github.com/browserify/createECDH/commit/fb6a7d960c5c45469fa6abd3e67a7b1d9a976ddf)
|
|
134
|
+
- name [`99208c8`](https://github.com/browserify/createECDH/commit/99208c8728a9e671cc46d4afe97c7a3b71974f3d)
|
|
135
|
+
- travis [`810fac1`](https://github.com/browserify/createECDH/commit/810fac1b8ff14ace34ddd88c49b09bed1a45e25b)
|
|
136
|
+
- rm console log [`c40a075`](https://github.com/browserify/createECDH/commit/c40a075e7bf3b16e5eb6024eb472f3106b0f0f26)
|
package/browser.js
CHANGED
|
@@ -1,124 +1,129 @@
|
|
|
1
|
-
|
|
2
|
-
var BN = require('bn.js')
|
|
1
|
+
'use strict';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
var elliptic = require('elliptic');
|
|
4
|
+
var BN = require('bn.js');
|
|
5
|
+
|
|
6
|
+
var isArray = Array.isArray;
|
|
7
7
|
|
|
8
8
|
var aliases = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
9
|
+
ed25519: {
|
|
10
|
+
byteLength: 32,
|
|
11
|
+
name: 'ed25519'
|
|
12
|
+
},
|
|
13
|
+
prime192v1: {
|
|
14
|
+
byteLength: 24,
|
|
15
|
+
name: 'p192'
|
|
16
|
+
},
|
|
17
|
+
prime256v1: {
|
|
18
|
+
byteLength: 32,
|
|
19
|
+
name: 'p256'
|
|
20
|
+
},
|
|
21
|
+
secp224r1: {
|
|
22
|
+
byteLength: 28,
|
|
23
|
+
name: 'p224'
|
|
24
|
+
},
|
|
25
|
+
secp256k1: {
|
|
26
|
+
byteLength: 32,
|
|
27
|
+
name: 'secp256k1'
|
|
28
|
+
},
|
|
29
|
+
secp384r1: {
|
|
30
|
+
byteLength: 48,
|
|
31
|
+
name: 'p384'
|
|
32
|
+
},
|
|
33
|
+
secp521r1: {
|
|
34
|
+
byteLength: 66,
|
|
35
|
+
name: 'p521'
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
aliases.p224 = aliases.secp224r1;
|
|
40
|
+
aliases.secp256r1 = aliases.prime256v1;
|
|
41
|
+
aliases.p256 = aliases.prime256v1;
|
|
42
|
+
aliases.secp192r1 = aliases.prime192v1;
|
|
43
|
+
aliases.p192 = aliases.prime192v1;
|
|
44
|
+
aliases.p384 = aliases.secp384r1;
|
|
45
|
+
aliases.p521 = aliases.secp521r1;
|
|
46
|
+
|
|
47
|
+
function formatReturnValue(bn, enc, len) {
|
|
48
|
+
var arr = isArray(bn) ? bn : bn.toArray();
|
|
49
|
+
var buf = new Buffer(arr);
|
|
50
|
+
if (len && buf.length < len) {
|
|
51
|
+
var zeros = new Buffer(len - buf.length);
|
|
52
|
+
zeros.fill(0);
|
|
53
|
+
buf = Buffer.concat([zeros, buf]);
|
|
54
|
+
}
|
|
55
|
+
if (!enc) {
|
|
56
|
+
return buf;
|
|
57
|
+
}
|
|
58
|
+
return buf.toString(enc);
|
|
59
|
+
|
|
37
60
|
}
|
|
38
61
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
62
|
+
function ECDH(curve) {
|
|
63
|
+
this.curveType = aliases[curve];
|
|
64
|
+
if (!this.curveType) {
|
|
65
|
+
this.curveType = {
|
|
66
|
+
name: curve
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
this.curve = new elliptic.ec(this.curveType.name); // eslint-disable-line new-cap
|
|
70
|
+
this.keys = void 0;
|
|
54
71
|
}
|
|
55
72
|
|
|
56
73
|
ECDH.prototype.generateKeys = function (enc, format) {
|
|
57
|
-
|
|
58
|
-
|
|
74
|
+
this.keys = this.curve.genKeyPair();
|
|
75
|
+
return this.getPublicKey(enc, format);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
function validPublicKey(curve, pubBuf) {
|
|
79
|
+
var key = curve.keyFromPublic(pubBuf);
|
|
80
|
+
// rejects the point at infinity, points not on the curve, and points outside the prime-order subgroup
|
|
81
|
+
var pub = key.getPublic();
|
|
82
|
+
// elliptic's Montgomery ladder wrongly reports n * (x = 0) as infinity, so that low-order point passes `validate`
|
|
83
|
+
if (!key.validate().result || (curve.curve.type === 'mont' && pub.getX().isZero())) {
|
|
84
|
+
throw new Error('Public key is not valid for specified curve');
|
|
85
|
+
}
|
|
86
|
+
return pub;
|
|
59
87
|
}
|
|
60
88
|
|
|
61
89
|
ECDH.prototype.computeSecret = function (other, inenc, enc) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
var out = otherPub.mul(this.keys.getPrivate()).getX()
|
|
68
|
-
return formatReturnValue(out, enc, this.curveType.byteLength)
|
|
69
|
-
}
|
|
90
|
+
var otherBuf = Buffer.isBuffer(other) ? other : new Buffer(other, inenc || 'utf8');
|
|
91
|
+
var otherPub = validPublicKey(this.curve, otherBuf);
|
|
92
|
+
var out = this.keys.derive(otherPub);
|
|
93
|
+
return formatReturnValue(out, enc, this.curveType.byteLength);
|
|
94
|
+
};
|
|
70
95
|
|
|
71
96
|
ECDH.prototype.getPublicKey = function (enc, format) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
97
|
+
var key = this.keys.getPublic(format === 'compressed', true);
|
|
98
|
+
if (format === 'hybrid') {
|
|
99
|
+
if (key[key.length - 1] % 2) {
|
|
100
|
+
key[0] = 7;
|
|
101
|
+
} else {
|
|
102
|
+
key[0] = 6;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return formatReturnValue(key, enc);
|
|
106
|
+
};
|
|
82
107
|
|
|
83
108
|
ECDH.prototype.getPrivateKey = function (enc) {
|
|
84
|
-
|
|
85
|
-
}
|
|
109
|
+
return formatReturnValue(this.keys.getPrivate(), enc);
|
|
110
|
+
};
|
|
86
111
|
|
|
87
112
|
ECDH.prototype.setPublicKey = function (pub, enc) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.keys._importPublic(pub)
|
|
93
|
-
return this
|
|
94
|
-
}
|
|
113
|
+
var pubBuf = Buffer.isBuffer(pub) ? pub : new Buffer(pub, enc || 'utf8');
|
|
114
|
+
this.keys.pub = validPublicKey(this.curve, pubBuf);
|
|
115
|
+
return this;
|
|
116
|
+
};
|
|
95
117
|
|
|
96
118
|
ECDH.prototype.setPrivateKey = function (priv, enc) {
|
|
97
|
-
|
|
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
|
-
}
|
|
119
|
+
var privBuf = Buffer.isBuffer(priv) ? priv : new Buffer(priv, enc || 'utf8');
|
|
108
120
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
if (!enc) {
|
|
120
|
-
return buf
|
|
121
|
-
} else {
|
|
122
|
-
return buf.toString(enc)
|
|
123
|
-
}
|
|
124
|
-
}
|
|
121
|
+
var privHex = new BN(privBuf).toString(16);
|
|
122
|
+
this.keys = this.curve.genKeyPair();
|
|
123
|
+
this.keys._importPrivate(privHex);
|
|
124
|
+
return this;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
module.exports = function createECDH(curve) {
|
|
128
|
+
return new ECDH(curve);
|
|
129
|
+
};
|
package/index.js
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var createECDH = require('crypto').createECDH;
|
|
4
|
+
|
|
5
|
+
// secp256k1 generator point, ie, the public key for a private key of 1
|
|
6
|
+
var G = '0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8';
|
|
7
|
+
|
|
8
|
+
// node < 5 does not compute the public key in `setPrivateKey`
|
|
9
|
+
function nativeIsCorrect() {
|
|
10
|
+
if (!createECDH) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
var ecdh = createECDH('secp256k1');
|
|
15
|
+
ecdh.setPrivateKey('01', 'hex');
|
|
16
|
+
return ecdh.getPublicKey('hex') === G;
|
|
17
|
+
} catch (e) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* istanbul ignore next */
|
|
23
|
+
module.exports = nativeIsCorrect() ? createECDH : require('./browser');
|
package/package.json
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-ecdh",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"description": "createECDH but browserifiable",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"browser": "browser.js",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"
|
|
8
|
+
"prepack": "npmignore --auto --commentLines=autogenerated",
|
|
9
|
+
"prepublishOnly": "safe-publish-latest",
|
|
10
|
+
"prepublish": "not-in-publish || npm run prepublishOnly",
|
|
11
|
+
"lint": "eslint .",
|
|
12
|
+
"pretest": "npm run lint",
|
|
13
|
+
"tests-only": "nyc tape 'test/**/*'",
|
|
14
|
+
"test": "npm run tests-only",
|
|
15
|
+
"posttest": "npx npm@\">= 10.2\" audit --production",
|
|
16
|
+
"version": "auto-changelog && git add CHANGELOG.md",
|
|
17
|
+
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
|
|
9
18
|
},
|
|
10
19
|
"repository": {
|
|
11
20
|
"type": "git",
|
|
12
21
|
"url": "https://github.com/crypto-browserify/createECDH.git"
|
|
13
22
|
},
|
|
23
|
+
"funding": {
|
|
24
|
+
"url": "https://github.com/sponsors/ljharb"
|
|
25
|
+
},
|
|
14
26
|
"keywords": [
|
|
15
27
|
"diffie",
|
|
16
28
|
"hellman",
|
|
@@ -24,12 +36,36 @@
|
|
|
24
36
|
},
|
|
25
37
|
"homepage": "https://github.com/crypto-browserify/createECDH",
|
|
26
38
|
"dependencies": {
|
|
27
|
-
"bn.js": "^4.
|
|
28
|
-
"elliptic": "^6.
|
|
39
|
+
"bn.js": "^4.12.5",
|
|
40
|
+
"elliptic": "^6.6.1"
|
|
29
41
|
},
|
|
30
42
|
"devDependencies": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
43
|
+
"@ljharb/eslint-config": "^22.2.5",
|
|
44
|
+
"auto-changelog": "^2.7.0",
|
|
45
|
+
"eslint": "^10.14.0",
|
|
46
|
+
"in-publish": "^2.0.1",
|
|
47
|
+
"jiti": "^0.0.0",
|
|
48
|
+
"npmignore": "^0.3.6",
|
|
49
|
+
"nyc": "^10.3.2",
|
|
50
|
+
"safe-publish-latest": "^2.0.0",
|
|
51
|
+
"tape": "^5.10.3"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">= 0.4"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"ignore": [
|
|
58
|
+
".github/workflows",
|
|
59
|
+
"eslint.config.mjs",
|
|
60
|
+
"test"
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
"auto-changelog": {
|
|
64
|
+
"output": "CHANGELOG.md",
|
|
65
|
+
"template": "keepachangelog",
|
|
66
|
+
"unreleased": false,
|
|
67
|
+
"commitLimit": false,
|
|
68
|
+
"backfillLimit": false,
|
|
69
|
+
"hideCredit": true
|
|
34
70
|
}
|
|
35
71
|
}
|
package/.travis.yml
DELETED
/package/{readme.md → README.md}
RENAMED
|
File without changes
|