-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate CID #83
Comments
utils/calculateCid.tsimport {BackHoleBlockstore} from "blockstore-core/black-hole"
import {importer} from "ipfs-unixfs-importer"
export default async function calculateCid(files: Array<{name: string, read: () => Promise<Uint8Array>}>): Promise<string> {
const source = await Promise.all(
files.map(async file => ({
path: `./${file.name}`,
content: await file.read(),
}))
)
const blockstore = new BackHoleBlockstore()
for await (const entry of importer(source, blockstore)) {
if (entry.path === '' && entry.unixfs?.type === 'directory') return entry.cid.toString()
}
throw new Error("Failed to calculate directory CID: importer did not find a directory entry in the input files")
} |
I tried patching package.json, which worked up to a point. But the rabbit hole was too deep. It might be necessary to fork the packages and modify them. We can submit a pull request and use our fork in the meantime. The problem also occurs with some of the dependencies https://www.npmjs.com/package/ipfs-unixfs-importer?activeTab=dependencies |
Start with importing the multiformats library (which has no dependencies). Copy/paste this code from the README and create a method in import { CID } from 'multiformats/cid'
import * as json from 'multiformats/codecs/json'
import { sha256 } from 'multiformats/hashes/sha2'
export function cidFromData(data: any) {
const bytes = json.encode(data)
const hash = await sha256.digest(bytes)
return CID.create(1, json.code, hash)
} Try to build the project for Android ( |
There are issues with trying to use IPFS packages
blockstore-core
andipfs-unixfs-importer
in the react native app.package.json
isn't exportedmain
for these and other packages.exports
of package.json aren't being loaded.The text was updated successfully, but these errors were encountered: