Skip to content

Commit ecc6fda

Browse files
James Hallidaymafintosh
James Halliday
authored andcommitted
swap out crypto for specific modules (hypercore-protocol#1)
1 parent e5085a7 commit ecc6fda

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ var inherits = require('inherits')
33
var duplexify = require('duplexify')
44
var lpstream = require('length-prefixed-stream')
55
var stream = require('readable-stream')
6-
var crypto = require('crypto')
6+
var randomBytes = require('randombytes')
7+
var createHmac = require('create-hmac')
78
var encryption = require('sodium-encryption')
89
var increment = require('increment-buffer')
910
var equals = require('buffer-equals')
@@ -61,7 +62,7 @@ function use (extensions) {
6162
this.remote = -1
6263
this.buffer = []
6364

64-
this._nonce = crypto.randomBytes(24)
65+
this._nonce = randomBytes(24)
6566
this._remoteNonce = null
6667

6768
this._firstNonce = Buffer(24)
@@ -148,7 +149,7 @@ function use (extensions) {
148149
this.channels = {}
149150
this.private = opts.private !== false
150151

151-
this.id = opts.id || crypto.randomBytes(32)
152+
this.id = opts.id || randomBytes(32)
152153
this.remoteId = null
153154

154155
this._finalized = false
@@ -508,7 +509,7 @@ function use (extensions) {
508509
}
509510

510511
function discoveryKey (key) {
511-
return crypto.createHmac('sha256', key).update('hypercore').digest()
512+
return createHmac('sha256', key).update('hypercore').digest()
512513
}
513514

514515
function isEncoder (val) {

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
"dependencies": {
77
"brfs": "^1.4.3",
88
"buffer-equals": "^1.0.3",
9+
"create-hmac": "^1.1.4",
910
"duplexify": "^3.4.3",
1011
"increment-buffer": "^1.0.0",
1112
"inherits": "^2.0.1",
1213
"length-prefixed-stream": "^1.5.0",
1314
"passthrough-encoding": "^1.2.0",
1415
"protocol-buffers": "^3.1.6",
16+
"randombytes": "^2.0.3",
1517
"readable-stream": "^2.1.4",
1618
"sodium-encryption": "^1.1.0",
1719
"varint": "^4.0.0",

0 commit comments

Comments
 (0)