Last active
July 9, 2024 05:23
-
-
Save ysm-dev/5fcf2feb87aea7bb2109630a23dac7eb to your computer and use it in GitHub Desktop.
Text(string) to CID (v1) TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CID } from "multiformats/cid"; | |
import * as raw from "multiformats/codecs/raw"; | |
import { sha256 } from "@noble/hashes/sha256"; | |
import { create } from "multiformats/hashes/digest"; | |
export const toCID = (txt: string) => { | |
return CID.createV1(raw.code, create(0x12, sha256(txt))).toString(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment