How to use the blockstack.decryptContent function in blockstack

To help you get started, we’ve selected a few blockstack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Graphite-Docs / graphite / web / src / components / helpers / helpers.js View on Github external
filePath: '/vault/index.json'
      }
      // //Call fetchFromProvider and wait for response.
      let fetchFile = await fetchFromProvider(object);
        console.log(fetchFile)
        //Now we need to determine if the response was from indexedDB or an API call:
        if(fetchFile) {
          if(JSON.parse(localStorage.getItem('storageProvider')) === 'google') {
            const decryptedContent = await JSON.parse(decryptContent(fetchFile, { privateKey: thisKey }))
            setGlobal({ files: decryptedContent, filteredVault: decryptedContent, loading: false })
          } else {
            if(fetchFile.loadLocal || JSON.parse(localStorage.getItem('storageProvider')) === 'ipfs') {
              if(JSON.parse(localStorage.getItem('storageProvider')) === 'ipfs') {
                let content = fetchFile.data.pinataContent ? fetchFile.data.pinataContent : fetchFile.data;
                console.log(content);
                const decryptedContent = await JSON.parse(decryptContent(content.content, { privateKey: thisKey }))
                setGlobal({ files: decryptedContent, filteredVault: decryptedContent, loading: false })
              } else {
                console.log("Loading local instance first");
                const decryptedContent = await JSON.parse(decryptContent(JSON.parse(fetchFile.data.content), { privateKey: thisKey }))
                setGlobal({ files: decryptedContent, filteredVault: decryptedContent, loading: false })
              }
            } else {
              //check if there is no file to load and set state appropriately.
              if(typeof fetchFile === 'string') {
                console.log("Nothing stored locally or in storage provider.")
                if(fetchFile.includes('error')) {
                  console.log("Setting state appropriately")
                  setGlobal({files: [], filteredVault: [], loading: false}, () => {
                    console.log("No files found");
                  })
                }
github Graphite-Docs / graphite / web / src / components / helpers / contacts.js View on Github external
// //Call fetchFromProvider and wait for response.
      let fetchFile = await fetchFromProvider(object);
      if(JSON.parse(localStorage.getItem('storageProvider')) === 'google') {
        if(fetchFile) {
          const decryptedContent = await JSON.parse(decryptContent(fetchFile, { privateKey: thisKey }))
          setGlobal({ contacts: decryptedContent, filteredContacts: decryptedContent, loading: false })
        } else {
          setGlobal({ loading: false })
        }
      } else {
        //Now we need to determine if the response was from indexedDB or an API call:
        if(fetchFile) {
          if(fetchFile.loadLocal || JSON.parse(localStorage.getItem('storageProvider')) === 'ipfs') {
            if(fetchFile.loadLocal) {
              console.log("Loading local instance first");
              const decryptedContent = await JSON.parse(decryptContent(JSON.parse(fetchFile.data.content), { privateKey: thisKey }))
              setGlobal({ contacts: decryptedContent, filteredContacts: decryptedContent, loading: false })
            } else {
              let content = fetchFile.data.pinataContent ? fetchFile.data.pinataContent : fetchFile.data;
              const decryptedContent = await JSON.parse(decryptContent(content.content, { privateKey: thisKey }))
              setGlobal({ contacts: decryptedContent, filteredContacts: decryptedContent, loading: false })
            }
          } else {
            //check if there is no file to load and set state appropriately.
            if(typeof fetchFile === 'string') {
              console.log("Nothing stored locally or in storage provider.")
              if(fetchFile.includes('error')) {
                console.log("Setting state appropriately")
                setGlobal({contacts: [], filteredContacts: [], loading: false})
              }
            } else {
              //No indexedDB data found, so we load and read from the API call.
github Graphite-Docs / graphite / web / src / components / onboarding / profiles / profiles.js View on Github external
if(res.data.length > 0) {
        console.log(res.data);
        localStorage.setItem('profileFound', JSON.stringify(true))
        let privateKey;
        if (authProvider === "uPort") {
          privateKey = JSON.parse(localStorage.getItem('graphite_keys')).GraphiteKeyPair.private
        } else {
          privateKey = loadUserData().appPrivateKey;
        }
        console.log(res.data)
        let decryptedToken;
        if(res.data[0].storageProvider === 'ipfs') {
          localStorage.setItem('storageProvider', JSON.stringify(res.data[0].storageProvider));
          localStorage.setItem('profileFound', JSON.stringify(true))
        } else {
          decryptedToken = decryptContent(res.data[0].refreshToken, { privateKey: privateKey })
          localStorage.setItem('storageProvider', JSON.stringify(res.data[0].storageProvider));
          localStorage.setItem('oauthData', decryptedToken);
        }
        
        // return true;
      } else {
        // Start the IPFS process here.
        if(profile.create) {
          postToIPFS(profile);
          localStorage.setItem('profileFound', JSON.stringify(true))
          return true;
        }
      }
    })
    .catch((error) => {
github Graphite-Docs / graphite / web / src / components / helpers / sharedDocs.js View on Github external
let publicKey = JSON.parse(localStorage.getItem('graphite_keys')).GraphiteKeyPair.public;
        let fileString = 'shareddocs.json'
        let file = publicKey + fileString;
        const directory = 'shared/' + file;
        const user = window.location.href.split('shared/')[1].split('#')[0];
        if(user.includes('did:')) {
            //the sharer is a uPort user and thus shared using IPFS. Need to fetch from there. 
            const params = {
                provider: 'ipfs',
                filePath: `/shared/${publicKey}/${fileString}`
                };
                //Call fetchFromProvider and wait for response.
            let fetchFile = await fetchFromProvider(params);
            console.log(fetchFile)
            if(fetchFile) {
                const decryptedContent = fetchFile.data.pinataContent ? await JSON.parse(decryptContent(fetchFile.data.pinataContent.content, { privateKey: thisKey })) : await JSON.parse(decryptContent(fetchFile.data.content, { privateKey: thisKey })) 
                console.log(decryptedContent);
                await setGlobal({ docs: decryptedContent, loading: false })
                } else {
                await setGlobal({ docs: [], loading: false })
                }
        } else {
            const options = { username: user, zoneFileLookupURL: "https://core.blockstack.org/v1/names", decrypt: false}
            lookupProfile(user, "https://core.blockstack.org/v1/names")
            .then((profile) => {
                let image = profile.image;
                if(profile.image){
                setGlobal({img: image[0].contentUrl})
                } else {
                setGlobal({ img: avatarFallbackImage })
                }
            })
github Graphite-Docs / graphite / web / src / components / helpers / singleDoc.js View on Github external
reader.onloadend = async evt => {
        let decryptedIndex;
        const thisKey = await JSON.parse(localStorage.getItem('graphite_keys')).GraphiteKeyPair.private;
        if(JSON.parse(localStorage.getItem('storageProvider')) === 'google') {
          decryptedIndex = await JSON.parse(decryptContent(fetchFile, { privateKey: thisKey }))
        } else {
          decryptedIndex = await JSON.parse(decryptContent(JSON.parse(evt.target.result), { privateKey: thisKey }))
        }
        console.log(decryptedIndex)
        await setGlobal(
        {
          value: decryptedIndex,
          filteredValue: decryptedIndex
        },
        async () => {
          const thisDoc = await decryptedIndex.find(doc => {
            if (typeof doc.id === "string") {
              if (doc.id) {
                if (window.location.href.split("doc/")[1].includes("#")) {
                  return (
                    doc.id ===
github Graphite-Docs / graphite / web / src / components / helpers / helpers.js View on Github external
if(JSON.parse(localStorage.getItem('storageProvider')) === 'google' || JSON.parse(localStorage.getItem('storageProvider')) === 'ipfs') {
          if(JSON.parse(localStorage.getItem('storageProvider')) === 'ipfs') {
            if(fetchFile.loadLocal) {
              let content = fetchFile.data.content;
              console.log(JSON.parse(content));
              const decryptedContent = await JSON.parse(decryptContent(JSON.parse(content), { privateKey: thisKey }))
              setGlobal({ value: decryptedContent, filteredValue: decryptedContent, countFilesDone: true, loading: false })
            } else {
              let content = fetchFile.data.pinataContent ? fetchFile.data.pinataContent : fetchFile.data;
              console.log(content);
              const decryptedContent = await JSON.parse(decryptContent(content.content, { privateKey: thisKey }))
              setGlobal({ value: decryptedContent, filteredValue: decryptedContent, countFilesDone: true, loading: false })
            }
          } else {
            console.log(fetchFile);
            const decryptedContent = await JSON.parse(decryptContent(fetchFile, { privateKey: thisKey }))
            setGlobal({ value: decryptedContent, filteredValue: decryptedContent, countFilesDone: true, loading: false })
          }
        } else {
          if(fetchFile.loadLocal) {
            console.log("Loading local instance first");
            const decryptedContent = await JSON.parse(decryptContent(JSON.parse(fetchFile.data.content), { privateKey: thisKey }))
            setGlobal({ value: decryptedContent, filteredValue: decryptedContent, countFilesDone: true, loading: false })
          } else {
            //check if there is no file to load and set state appropriately.
            if(typeof fetchFile === 'string') {
              console.log("Nothing stored locally or in storage provider.")
              if(fetchFile.includes('error')) {
                console.log("Setting state appropriately")
                setGlobal({value: [], filteredValue: [], countFilesDone: true, loading: false}, () => {
                  loadSheets();
                })
github Graphite-Docs / graphite / web / src / components / helpers / singleRTC.js View on Github external
const object = {
      provider: storageProvider,
      token: token,
      filePath: `/documents/single/${thisFile}.json`
    };
    //Call fetchFromProvider and wait for response.
    let fetchFile = await fetchFromProvider(object);
    console.log(fetchFile)
    //Now we need to determine if the response was from indexedDB or an API call:
    if (fetchFile.loadLocal || storageProvider === 'google' || storageProvider === 'ipfs') {
      let decryptedContent;
      if(storageProvider === 'google') {
        decryptedContent = await JSON.parse(decryptContent(fetchFile, { privateKey: thisKey }))
      } else {
        decryptedContent = await JSON.parse(
          decryptContent(JSON.parse(fetchFile.data.content), {
            privateKey: thisKey
          })
        );
      }
      
      setGlobal(
        {
          content: Value.fromJSON(decryptedContent.content),
          title: decryptedContent.title,
          tags: decryptedContent.tags,
          idToLoad: decryptedContent.id,
          singleDocIsPublic: decryptedContent.singleDocIsPublic, //adding this...
          docLoaded: true,
          readOnly: decryptedContent.readOnly, //NOTE: adding this, to setState of readOnly from getFile...
          rtc: decryptedContent.rtc || false,
          sharedWith: decryptedContent.sharedWith,
github Graphite-Docs / graphite / web / src / components / helpers / singleVaultFile.js View on Github external
reader.onloadend = async (evt) => {
              console.log("read success");
              const decryptedContent = await JSON.parse(decryptContent(JSON.parse(evt.target.result), { privateKey: thisKey }))
              await setGlobal({ 
                file: decryptedContent,
                name: decryptedContent.name,
                lastModifiedDate: decryptedContent.lastModifiedDate,
                size: decryptedContent.size,
                link: decryptedContent.link,
                type: decryptedContent.type,
                sharedWith: decryptedContent.sharedWith,
                tags: decryptedContent.tags,
                publicVaultFile: decryptedContent.publicVaultFile || false
              })
            };
            await console.log(reader.readAsText(blob2));
github blockstack-radiks / kanstack / radiks / helpers.js View on Github external
Object.keys(encrypted).forEach((key) => {
    const value = encrypted[key];
    const clazz = schema[key];
    if (clazz && !clazz.decrypted) {
      try {
        decrypted[key] = stringToValue(blockstack.decryptContent(value), clazz.type || clazz);
      } catch (error) {
        decrypted[key] = value;
      }
    }
  });
  return decrypted;
github Graphite-Docs / graphite / web / src / components / gaiaFunctions / storage.js View on Github external
if(options.key) {
          return decryptContent(JSON.parse(doc.data), {privateKey: options.key});
        } else {
          return decryptContent(JSON.parse(doc.data));
        }
      } else {
        return JSON.parse(doc.data);
      }
    });
  } else if(options.ipfs) {
    const fileBuffer = await node.files.cat(options.hash)
    if(options.decrypt) {
      if(options.key) {
        decryptContent(JSON.parse(fileBuffer), { privateKey: options.key });
      } else {
        decryptContent(JSON.parse(fileBuffer))
      }
    } else {
      return JSON.parse(fileBuffer);
    }
  } else if(options.gaia) {
    return getFile(options.filename, {decrypt: false}).then((data) => {
      if(options.decrypt) {
        if(options.key) {
          return decryptContent(JSON.parse(data), { privateKey: options.key });
        } else {
          return decryptContent(JSON.parse(data));
        }
      } else {
        return JSON.parse(data);
      }
    })