js-libp2p/src/circuit/utils.js

18 lines
395 B
JavaScript
Raw Normal View History

'use strict'
const CID = require('cids')
const multihashing = require('multihashing-async')
/**
* Convert a namespace string into a cid.
2020-10-07 17:58:11 +02:00
*
* @param {string} namespace
2020-10-07 17:58:11 +02:00
* @returns {Promise<CID>}
*/
module.exports.namespaceToCid = async (namespace) => {
const bytes = new TextEncoder('utf8').encode(namespace)
const hash = await multihashing(bytes, 'sha2-256')
return new CID(hash)
}