Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit 01b7ec1

Browse files
authored
fix: browser compatibility (#226)
Use libp2p-crypto instead of the node crypto module for browser compat
1 parent ee3b374 commit 01b7ec1

File tree

3 files changed

+2
-5
lines changed

3 files changed

+2
-5
lines changed

.aegir.js

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ const esbuild = {
99
build.onResolve({ filter: /^stream$/ }, () => {
1010
return { path: require.resolve('readable-stream') }
1111
})
12-
build.onResolve({ filter: /^crypto$/ }, () => {
13-
return { path: require.resolve('crypto-browserify') }
14-
})
1512
}
1613
}
1714
]

src/routing-table/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const KBuck = require('k-bucket')
55
const { xor: uint8ArrayXor } = require('uint8arrays/xor')
66
const GENERATED_PREFIXES = require('./generated-prefix-list.json')
77
const { sha256 } = require('multiformats/hashes/sha2')
8-
const crypto = require('crypto')
8+
const crypto = require('libp2p-crypto')
99
const PeerId = require('peer-id')
1010
const utils = require('../utils')
1111
const debug = require('debug')

test/simulation/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const { convertBuffer } = require('../../src/utils')
1212
const { sortClosestPeers } = require('../../src/utils')
1313
const DHT = require('../../src')
1414
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
15+
const crypto = require('libp2p-crypto')
1516

1617
const NUM_PEERS = 10e3 // Peers to create, not including us
1718
const LATENCY_DEAD_NODE = 120e3 // How long dead nodes should take before erroring
@@ -134,7 +135,6 @@ async function GetClosestPeersSimulation () {
134135
* @returns {Array<PeerId>}
135136
*/
136137
function createPeers (num) {
137-
const crypto = require('crypto')
138138
const peers = [...new Array(num)].map(() => {
139139
return PeerId.createFromB58String(
140140
base58btc.baseEncode(crypto.randomBytes(34))

0 commit comments

Comments
 (0)