Skip to content

Instantly share code, notes, and snippets.

@dantrevino
Last active August 15, 2018 17:55
Show Gist options
  • Save dantrevino/231c057de177a6ce741ca7b3af4fb04d to your computer and use it in GitHub Desktop.
Save dantrevino/231c057de177a6ce741ca7b3af4fb04d to your computer and use it in GitHub Desktop.
Blockstack data sharing

Load the public key for Graphite (note: I'm using the stealthy example here)

export function loadKey() {
  axios.get(url + 'pk.txt') // target app gaia hub url and public key
  .then((response) => {
    this.setState({
      stealthyKey: response.data,
      stealthyConnected: true
    })
  })
  .then(() => {
    this.loadSharedDocs();
  })
  .catch((error) => {
    console.log('error:', error);
  });
}

Then load the files to be sent to the other app

export function loadSharedDocs() {
  getFile("documentscollection.json", {decrypt: true})
   .then((fileContents) => {
     if(JSON.parse(fileContents || '{}').value) {
       this.setState({
         docs: JSON.parse(fileContents || '{}').value
       })
     } else {
       console.log("No saved files");
     }
   })
    .then(() => {
      this.saveStealthyIntegration();
    })
    .catch(error => {
      console.log(error);
    });
}

Finally, save the collection with the receiving app's public key

export function saveStealthyIntegration() {
  const data = this.state.docs;
  const publicKey = this.state.stealthyKey;
  const encryptedData = JSON.stringify(encryptECIES(publicKey, JSON.stringify(data)));
  const fileName = 'stealthyIndex.json';
  putFile(fileName, encryptedData, {encrypt: false})
  .then(() => {
    if(window.location.pathname === "/integrations") {
      window.Materialize.toast('Stealthy integration updated', 4000);
      this.saveIntegrations();
    }
  })
  .catch(e => {
    console.log(e);
  });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment