Skip to content

Instantly share code, notes, and snippets.

@ysm-dev
Last active July 9, 2024 05:23
Show Gist options
  • Save ysm-dev/5fcf2feb87aea7bb2109630a23dac7eb to your computer and use it in GitHub Desktop.
Save ysm-dev/5fcf2feb87aea7bb2109630a23dac7eb to your computer and use it in GitHub Desktop.
Text(string) to CID (v1) TypeScript
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