Ejemplo n.º 1
0
    def test_cids(self):
        assert cidValid(
            'bafkriqa2hf4uwu2dd2nlynbwr3kietn2ywowyzaxperhtmhmfsi5n22yv5zptvfr4o3bhicyshbmdil2qif47au4wmr4ikm3egpfvmuzpfcyc'
        )
        assert cidValid(
            'bafkreihszin3nr7ja7ig3l7enb7fph6oo2zx4tutw5qfaiw2kltmzqtp2i')
        assert cidValid(
            'bafkrgqaohz2sgsv4nd2dpcugwp2lgkqzrorqdbc3btlokaig5b2divyazrtghkdmd2qslxc6sk7bpsmptihylsu5l5mv3mqbf56mgvyzixasg'
        )
        assert cidValid(
            'bafkr2qffyprvhimferhyfkg6af63marfiplxn6euhncxwy3izaefj3g73ilqlzo5kfgvbbyrnwwmw7nm4wwufkyxfp7htiwabn5b5hdw4rvvk'
        )
        p = IPFSPath(
            'bafkr2qffyprvhimferhyfkg6af63marfiplxn6euhncxwy3izaefj3g73ilqlzo5kfgvbbyrnwwmw7nm4wwufkyxfp7htiwabn5b5hdw4rvvk'
        )
        assert p.valid

        p = IPFSPath(
            'bafk4bzacia2aon3c3n5pkaemoij7sm4q4dt3omcr5tkc2sptmm6ifsnpbsx7h77xj4e4pjx7olxtbgsyjsg35mgl3j2q7mel3kuiz2v7ztngkdbv'
        )
        assert p.valid

        p = IPFSPath(
            '/ipfs/bafykbzaced4xstofs4tc5q4irede6uzaz3qzcdvcb2eedxgfakzwdyjnxgohq/'
        )
        assert p.valid

        cid = getCID(
            'bafykbzaced4xstofs4tc5q4irede6uzaz3qzcdvcb2eedxgfakzwdyjnxgohq')
        m = multihash.decode(cid.multihash)
        assert m.name == 'blake2b-256'
Ejemplo n.º 2
0
    async def _searchSubDag(self,
                            pdag,
                            root,
                            regexp,
                            path=None,
                            dateFrom=None,
                            dateTo=None):

        for sname, section in root.items():
            lkeys = [key for key in section.keys() if not key.startswith('_')]

            for key in lkeys:
                ma = regexp.search(key)

                if not ma:
                    continue

                seeds = section[key]

                for idx, entry in enumerate(seeds):
                    meta = entry['_metadata']
                    datecreated = meta['datecreated']

                    link = entry['seedlink'].get('/')

                    if not cidValid(link):
                        continue

                    date = parseDate(datecreated)

                    if date and dateFrom and dateTo:
                        if date >= dateFrom and date <= dateTo:
                            yield sname, key, datecreated, link
                    else:
                        yield sname, key, datecreated, link
Ejemplo n.º 3
0
 def onCIDChanged(self, text):
     if cidhelpers.cidValid(text):
         self.ui.validity.setText('Valid CID')
         self.validCid = True
     else:
         self.ui.validity.setText('Invalid CID')
         self.validCid = False
Ejemplo n.º 4
0
    def changeCid(self, cid):
        if cidValid(cid):
            self.rootHash = cid
            self.rootPath = IPFSPath(self.rootHash, autoCidConv=True)
            self.cid = cidhelpers.getCID(self.rootHash)

            self.pinButton.changeObject(self.rootPath)

            self.initModel()
Ejemplo n.º 5
0
    async def pubKeyCid(self, ipfsop):
        if self.pubKeyCidCached and cidValid(self.pubKeyCidCached):
            return self.pubKeyCidCached

        try:
            entry = await ipfsop.addBytes(self.pubKeyPem)
            self._pubKeyCidCached = entry['Hash']
            return self.pubKeyCidCached
        except Exception as err:
            self.debug(f'Cannot import pubkey: {err}')
Ejemplo n.º 6
0
    def changeMultihash(self, cid):
        if cidValid(cid):
            self.parentMultihash = self.rootHash

            if self.parentMultihash is not None:
                self.parentMultihashSet.emit(self.parentMultihash)

            self.rootHash = cid
            self.rootPath = IPFSPath(self.rootHash, autoCidConv=True)
            self.cid = cidhelpers.getCID(self.rootHash)
            self.initModel()
Ejemplo n.º 7
0
    async def setupRepository(self, op):
        pubsubEnabled = True  # mandatory now ..
        hExchEnabled = self.settingsMgr.isTrue(CFG_SECTION_IPFS,
                                               CFG_KEY_HASHMARKSEXCH)

        self.ipfsCtx.resources['ipfs-logo-ice'] = await self.importQtResource(
            '/share/icons/ipfs-logo-128-ice.png')
        self.ipfsCtx.resources['ipfs-cube-64'] = await self.importQtResource(
            '/share/icons/ipfs-cube-64.png')
        self.ipfsCtx.resources['atom-feed'] = await self.importQtResource(
            '/share/icons/atom-feed.png')
        self.ipfsCtx.resources['markdown-reference'] = \
            await self.importQtResource(
                '/share/static/docs/markdown-reference.html')

        await self.ipfsCtx.setup(pubsubEnable=pubsubEnabled,
                                 pubsubHashmarksExch=hExchEnabled,
                                 offline=self.offline)
        await self.ipfsCtx.profilesInit()
        await self.qSchemeHandler.start()
        await self.importLdContexts()

        self.feedFollower = FeedFollower(self)
        self.feedFollowerTask = await self.scheduler.spawn(
            self.feedFollower.process())

        await self.ipfsCtx.ipfsRepositoryReady.emit()
        self.ipfsCtx._ipfsRepositoryReady.emit()

        #
        # If the application's binary name is a valid CID, pin it!
        # This happens when running the AppImage and ensures
        # self-seeding of the image!
        #

        if isinstance(self.progName, str):
            progNameClean = re.sub(r'[\.\/]*', '', self.progName)
            if cidhelpers.cidValid(progNameClean):
                self._progCid = progNameClean
                log.debug("Auto pinning program's CID: {0}".format(
                    self.progCid))
                await self.ipfsCtx.pin(joinIpfs(self.progCid),
                                       False,
                                       self.onAppReplication,
                                       qname='self-seeding')

        if self.cmdArgs.seed and self.cmdArgs.appimage:
            await self.seedAppImage()
Ejemplo n.º 8
0
    async def dagInit(self, ipfsop):
        log.debug('Creating new DAG')
        try:
            # Create empty DAG
            cid = await ipfsop.dagPut({}, offline=self.dagOffline, pin=False)
        except aioipfs.APIError:
            # 911
            log.debug('Cannot create DAG ?')
        else:
            if cidhelpers.cidValid(cid):
                self.dagCid = cid
                self._dag = DAGPortal(self.dagCid)

                await ipfsop.sleep()
                await self.dag.load()
                await self.dag.waitLoaded()
Ejemplo n.º 9
0
 def onCIDChanged(self, text):
     """
     When the CID input text changes we verify if it's a valid CID and
     update the validity label
     """
     if cidhelpers.cidValid(text):
         cid = self.getCID()
         if cid:
             self.ui.validity.setText('Valid CID version {}'.format(
                 cid.version))
             self.validCid = True
         else:
             # Unlikely
             self.ui.validity.setText('Unknown CID type')
             self.validCid = False
     else:
         self.ui.validity.setText('Invalid CID')
         self.validCid = False
Ejemplo n.º 10
0
    async def post(self, op, message):
        profile = op.ctx.currentProfile
        username = profile.userInfo.username

        links = []
        words = message.split()
        for word in words:
            if cidValid(word):
                links.append(joinIpfs(word))

        await self.database.add(
            {
                'author': username,
                'post': message,
                'links': links,
                'date': isoformat(datetime.now(), timespec='seconds')
            })
        self.newMessages.emit(0)
Ejemplo n.º 11
0
        async def process(data):
            if isinstance(data, dict):
                for objKey, objValue in data.copy().items():
                    if objKey == '@context' and isinstance(objValue, dict):
                        link = objValue.get('/')
                        if isinstance(link, str) and cidValid(link):
                            try:
                                ctx = await self.catObject(link)
                                if ctx:
                                    data.update(orjson.loads(ctx.decode()))
                            except Exception as err:
                                self.debug('ldInline error: {}'.format(
                                    str(err)))

                            await self.sleep()
                    else:
                        await process(objValue)
            elif isinstance(data, list):
                for node in data:
                    await process(node)

            return data
Ejemplo n.º 12
0
def ipfspathnorm(input):
    if isinstance(input, str):
        if cidValid(input):
            return joinIpfs(input)
        elif isIpfsPath(input) or isIpnsPath(input):
            return input
Ejemplo n.º 13
0
    def docCid(self, cid):
        self.message('Updating DIDDoc CID from {prev} to {n}'.format(
            prev=self._docCid, n=cid))

        if cidValid(cid):
            self._docCid = cid
Ejemplo n.º 14
0
 def onCopyItemHash(self):
     currentItem = self.ui.dagTree.currentItem()
     value = currentItem.text(1)
     if cidhelpers.cidValid(value):
         self.app.setClipboardText(value)