Skip to content
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

wip: update ipfs #1024

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ const config: NuxtConfig = {
extend(conf, _) {
// @ts-ignore
conf.resolve.alias.vue = `vue/dist/vue.common`
// @ts-ignore
conf.module.noParse = /ipfs-core/
},
splitChunks: {
commons: true,
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"postinstall": "husky install"
},
"dependencies": {
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
"@babel/plugin-proposal-optional-chaining": "^7.18.6",
"@braintree/sanitize-url": "^6.0.0",
"@nuxtjs/dotenv": "^1.4.1",
"@nuxtjs/robots": "^2.5.0",
Expand All @@ -65,7 +67,7 @@
"dompurify": "^2.3.8",
"highlight.js": "^11.5.1",
"intl-tel-input": "^17.0.16",
"ipfs-core": "0.14.3",
"ipfs-core": "0.15.4",
"libsodium-wrappers": "^0.7.10",
"lodash": "^4.17.21",
"marked": "^4.0.17",
Expand Down
18 changes: 9 additions & 9 deletions src/backend/utilities/ipfs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Options, IPFS, CID } from 'ipfs-core'
import type { Options, IPFS } from 'ipfs-core'
import { CID } from 'multiformats/cid'
import { bootstrapNodes } from './config'

export interface IPFSInterface {
Expand All @@ -13,7 +14,7 @@ export interface IPFSInterface {
const ipfsConfig: Options = {
start: false,
libp2p: {
peerStore: { persistence: false },
// peerStore: { persistence: false },
},
init: { algorithm: `Ed25519` },
preload: {
Expand All @@ -25,10 +26,11 @@ const ipfsConfig: Options = {
}

async function loadAndInitIPFS() {
const { create, CID: CIDObj } = await import(`ipfs-core`)
const { default: res } = await import(`ipfs-core`)
const { create } = res
const ipfs = await create(ipfsConfig)

return { ipfs, CIDObj }
return { ipfs }
}

/**
Expand All @@ -38,7 +40,6 @@ async function loadAndInitIPFS() {
function createIPFSInterface(): IPFSInterface {
let ipfsInitialised = false
let node: IPFS | null = null
let CIDClass: typeof CID | null = null

const promise = loadAndInitIPFS()

Expand Down Expand Up @@ -119,10 +120,10 @@ function createIPFSInterface(): IPFSInterface {
}

const getJSONData = async <T>(cid: string) => {
if (!node || !CIDClass) {
if (!node) {
throw new Error(`Not initialised!`)
}
const res = await node.dag.get(CIDClass.parse(cid))
const res = await node.dag.get(CID.parse(cid))
if (!res.value) {
throw new Error(`No data found!`)
}
Expand Down Expand Up @@ -153,9 +154,8 @@ function createIPFSInterface(): IPFSInterface {
return peers.length
}

const initResult = promise.then(async ({ ipfs, CIDObj }) => {
const initResult = promise.then(async ({ ipfs }) => {
node = ipfs
CIDClass = CIDObj

await node.start()
ipfsInitialised = true
Expand Down
2 changes: 1 addition & 1 deletion src/backend/utilities/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function loadAndInitLibSodium() {
await res.ready

const { crypto_sign_verify_detached, crypto_sign_detached } = res
// @ts-ignore

return { crypto_sign_verify_detached, crypto_sign_detached, ready: res.ready }
}

Expand Down
Loading