Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit a10e3d5

Browse files
alanshawdaviddias
authored andcommitted
validates and serializes cid argument to provide
1 parent dfad55e commit a10e3d5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/dht/provide.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4+
const CID = require('cids')
45

56
module.exports = (send) => {
67
return promisify((cids, opts, callback) => {
@@ -20,6 +21,13 @@ module.exports = (send) => {
2021
cids = [cids]
2122
}
2223

24+
// Validate CID(s) and serialize
25+
try {
26+
cids = cids.map(cid => new CID(cid).toBaseEncodedString('base58btc'))
27+
} catch (err) {
28+
return callback(err)
29+
}
30+
2331
send({
2432
path: 'dht/provide',
2533
args: cids,

0 commit comments

Comments
 (0)