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);
});
}