mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-17 01:21:58 +00:00
BREAKING CHANGE: uses the CID class from the new multiformats module Co-authored-by: Vasco Santos <vasco.santos@moxy.studio>
18 lines
403 B
JavaScript
18 lines
403 B
JavaScript
'use strict'
|
|
|
|
const { CID } = require('multiformats/cid')
|
|
const { sha256 } = require('multiformats/hashes/sha2')
|
|
|
|
/**
|
|
* Convert a namespace string into a cid.
|
|
*
|
|
* @param {string} namespace
|
|
* @returns {Promise<CID>}
|
|
*/
|
|
module.exports.namespaceToCid = async (namespace) => {
|
|
const bytes = new TextEncoder().encode(namespace)
|
|
const hash = await sha256.digest(bytes)
|
|
|
|
return CID.createV0(hash)
|
|
}
|