plebbit / plebbit-js

A Javascript API to build applications using plebbit
GNU General Public License v2.0
41 stars 7 forks source link

implement subplebbit.updateCid: string | undefined #42

Closed estebanabaroa closed 1 month ago

estebanabaroa commented 3 months ago

this is needed for the subplebbit uptime monitor to call https://delegated-ipfs.dev/routing/v1/providers/<cid> and know how many peers are seeding an IPNS record, and display this data.

Rinse12 commented 3 months ago

How do we figure out what updateCid is before publishing to IPNS? Or is this meant for Subplebbit class instance?

estebanabaroa commented 2 months ago

How do we figure out what updateCid is before publishing to IPNS? Or is this meant for Subplebbit class instance?

it's not part of the IPFS file, it would just be on the instance, because obviously the cid of the ipfs file cannot be inside the ipfs file.

I'm using this code to get a CID in the uptime monitor, you could probably use it but change base32 for base58 because we use base58 everywhere else

import {CID} from 'multiformats/cid'
import {sha256} from 'multiformats/hashes/sha2'
import {base32} from 'multiformats/bases/base32'
const cidVersion = 1
const multicodec = 0x55
export const stringToCid = async (string) => {
  const bytes = new TextEncoder().encode(string)
  const hash = await sha256.digest(bytes)
  const cid = CID.create(cidVersion, multicodec, hash)
  return cid.toString(base32)
}

I believe to get the same CID as kubo gives out for comments the settings would be cidVersion = 0 and multicodec = 0x70, this is the CID of a plebbit comment created by kubo https://cid.ipfs.tech/#Qma8niEWEVdyJ8o9ZzNe9RT81cbWmEk1ZKnfnVwzdssZ2t

Rinse12 commented 1 month ago

Oops, I implemented this but as Subplebbit.cid not Subplebbit.updateCid. Should I change it or not worth the time? Would have to update the tests as well

estebanabaroa commented 1 month ago

Oops, I implemented this but as Subplebbit.cid not Subplebbit.updateCid. Should I change it or not worth the time? Would have to update the tests as well

I think updateCid is better than cid. cid is too similar to comment.cid which is static

the updateCid is also not that useful, most people wont use it, so it shouldn't have a short unspecific name, that should be reserved for APIs that are used a lot

Rinse12 commented 1 month ago

Implemented