Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getConfig = (peerInfo) => mergeOptions(baseOptions, {
peerInfo,
modules: {
peerDiscovery: [MulticastDNS]
},
config: {
peerDiscovery: {
autoDial: false,
mdns: {
enabled: true,
interval: 200, // discover quickly
// use a random tag to prevent CI collision
serviceTag: crypto.randomBytes(10).toString('hex')
}
}
}
})
async protect (connection) {
assert(connection, Errors.NO_HANDSHAKE_CONNECTION)
// Exchange nonces
log('protecting the connection')
const localNonce = crypto.randomBytes(NONCE_LENGTH)
const shake = handshake(connection)
shake.write(localNonce)
const result = await shake.reader.next(NONCE_LENGTH)
const remoteNonce = result.value.slice()
shake.rest()
// Create the boxing/unboxing pipe
log('exchanged nonces')
const [internal, external] = duplexPair()
pipe(
external,
// Encrypt all outbound traffic
createBoxStream(localNonce, this.psk),
shake.stream,
static generateOptions () {
const options = Object.assign({}, defaultOptions)
const saltLength = Math.ceil(NIST.minSaltLength / 3) * 3 // no base64 padding
options.dek.salt = crypto.randomBytes(saltLength).toString('base64')
return options
}
const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const MemoryDatastore = require('interface-datastore').MemoryDatastore
const crypto = require('libp2p-crypto')
const Shared = require('../src/collaboration/shared')
const Store = require('../src/collaboration/store')
const CRDT = require('../src/collaboration/crdt')
const Keys = require('../src/keys')
require('./utils/fake-crdt')
const key = crypto.randomBytes(16)
const iv = crypto.randomBytes(16)
const storeOptions = {
maxDeltaRetention: 0,
deltaTrimTimeoutMS: 0,
createCipher: () => {
return new Promise((resolve, reject) => {
crypto.aes.create(Buffer.from(key), Buffer.from(iv), (err, key) => {
if (err) {
return reject(err)
}
resolve(key)
})
})
}
}
'use strict'
const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const MemoryDatastore = require('interface-datastore').MemoryDatastore
const crypto = require('libp2p-crypto')
const Shared = require('../src/collaboration/shared')
const Store = require('../src/collaboration/store')
const CRDT = require('../src/collaboration/crdt')
const Keys = require('../src/keys')
require('./utils/fake-crdt')
const key = crypto.randomBytes(16)
const iv = crypto.randomBytes(16)
const storeOptions = {
maxDeltaRetention: 0,
deltaTrimTimeoutMS: 0,
createCipher: () => {
return new Promise((resolve, reject) => {
crypto.aes.create(Buffer.from(key), Buffer.from(iv), (err, key) => {
if (err) {
return reject(err)
}
resolve(key)
})
})
}
}
PeerId.createFromPrivKey(key.bytes, (err, id) => {
if (err) {
return callback(err)
}
let rec
try {
rec = new Record(k, crypto.randomBytes(10), id)
} catch (err) {
return callback(err)
}
callback(null, rec)
})
}
before(() => {
const key = crypto.randomBytes(16)
const iv = crypto.randomBytes(16)
storeOptions = Object.assign({}, _storeOptions, {
createCipher: () => {
return new Promise((resolve, reject) => {
crypto.aes.create(Buffer.from(key), Buffer.from(iv), (err, key) => {
if (err) {
return reject(err)
}
resolve(key)
})
})
}
})
})
before(() => {
const key = crypto.randomBytes(16)
const iv = crypto.randomBytes(16)
storeOptions = Object.assign({}, _storeOptions, {
createCipher: () => {
return new Promise((resolve, reject) => {
crypto.aes.create(Buffer.from(key), Buffer.from(iv), (err, key) => {
if (err) {
return reject(err)
}
resolve(key)
})
})
}
})
})
async function ping (node, peer) {
log('dialing %s to %s', PROTOCOL, peer.id.toB58String())
const { stream } = await node.dialProtocol(peer, PROTOCOL)
const start = new Date()
const data = crypto.randomBytes(PING_LENGTH)
const [result] = await pipe(
[data],
stream,
toBuffer,
collect
)
const end = Date.now()
if (!data.equals(result)) {
throw errCode(new Error('Received wrong ping ack'), 'ERR_WRONG_PING_ACK')
}
return end - start
}
exports.randomSeqno = () => {
return crypto.randomBytes(20)
}