Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sentToEditor() {
if(this.state.teamCount < this.state.team.length) {
//Here we will want to cycle through the team file and send/encrypt the file to all teammates
const user = this.state.team[this.state.teamCount].name;
// const options = { username: user, zoneFileLookupURL: "https://core.blockstack.org/v1/names", decrypt: false}
const publicKey = this.state.team[this.state.teamCount].key;
const data = this.state.sentArticles;
const encryptedData = JSON.stringify(encryptECIES(publicKey, JSON.stringify(data)));
const file = user + 'submitted.json';
putFile(file, encryptedData, {encrypt: false})
.then(() => {
console.log("Sent!");
window.Materialize.toast('Article Submitted', 4000);
this.setState({ teamCount: this.state.teamCount + 1 });
this.sentToEditor();
})
.catch(e => {
console.log(e);
});
} else {
console.log("no more teammates");
let userRoot = loadUserData().username.split('.')[1] + "." + loadUserData().username.split('.')[2];
const options = { username: userRoot, zoneFileLookupURL: "https://core.blockstack.org/v1/names", decrypt: false }
getFile('key.json', options)
saveToEveryone() {
const { teamMateMostRecent, team, count } = this.state;
if(team.length > count) {
let user = team[count].name;
let pubKey = team[count].key;
console.log('Saving to ' + user);
if(loadUserData().username !== user) {
// const publicKey = this.state.pubKey;
console.log("Here's the public key: ");
console.log(team[count].key);
const data = this.state.file;
const encryptedData = JSON.stringify(encryptECIES(pubKey, JSON.stringify(data)));
const file = pubKey + '.json';
console.log(file);
putFile(file, encryptedData, {encrypt: false})
.then(() => {
console.log("Shared encrypted file ");
this.setState({ count: count + 1 });
setTimeout(this.saveToEveryone, 300)
})
.catch(error => {
console.log(error)
})
} else {
console.log("Teammate is logged in user");
this.setState({ count: count + 1 });
setTimeout(this.saveToEveryone, 300)
}
saveToAdmin() {
const userRoot = loadUserData().username.split('.')[1] + "." + loadUserData().username.split('.')[2];
const publicKey = this.state.pubKey;
const data = this.state.sentArticles;
const encryptedData = JSON.stringify(encryptECIES(publicKey, JSON.stringify(data)));
const file = userRoot + 'submitted.json';
putFile(file, encryptedData, {encrypt: false})
.then(() => {
console.log("Sent to admin!");
this.setState({ teamCount: 0 });
})
.catch(e => {
console.log(e);
});
}
export function saveNoteRiotIntegration() {
const data = this.state.docs;
const publicKey = this.state.noteRiotKey;
const encryptedData = JSON.stringify(encryptECIES(publicKey, JSON.stringify(data)));
const fileName = 'noteRiotIndex.json';
putFile(fileName, encryptedData, {encrypt: false})
.then(() => {
if(window.location.pathname === "/integrations") {
this.saveIntegrations();
}
})
.catch(e => {
console.log(e);
});
}
saveShared() {
const fileName = this.state.conversationUser.slice(0, -3) + '.json';
const publicKey = this.state.pubKey;
const data = this.state;
const encryptedData = JSON.stringify(encryptECIES(publicKey, JSON.stringify(data)));
const directory = '/shared/' + fileName;
putFile(directory, encryptedData)
.then(() => {
console.log("Shared encrypted file " + directory);
})
.catch(e => {
console.log(e);
});
}
sendFile() {
const user = this.state.receiverID;
const userShort = user.slice(0, -3);
const fileName = 'sharedvault.json'
const file = userShort + fileName;
const publicKey = this.state.pubKey;
const data = this.state.sharedCollection;
const encryptedData = JSON.stringify(encryptECIES(publicKey, JSON.stringify(data)));
const directory = '/shared/' + file;
putFile(directory, encryptedData, {encrypt: false})
.then(() => {
console.log("Shared encrypted file ");
window.Materialize.toast('File shared with ' + this.state.receiverID, 4000);
this.loadCollection();
this.setState({shareModal: "hide", loadingTwo: "", contactDisplay: ""});
})
.catch(e => {
console.log(e);
});
}
})
.catch(e => {
console.log("e");
console.log(e);
});
remoteStorage.access.claim(this.props.match.params.id, 'rw');
remoteStorage.caching.enable('/' + this.props.match.params.id + '/');
const client = remoteStorage.scope('/' + this.props.match.params.id + '/');
const content = this.state.content;
const title = this.state.title;
const singleDocIsPublic = (this.state.singleDocIsPublic === true ? "true" : "false"); //true or false, as a string...
const words = wordcount(this.state.content);
const updated = getMonthDayYear();
const id = parseInt(this.props.match.params.id, 10);
const publicKey = getPublicKeyFromPrivate(loadUserData().appPrivateKey);
client.storeFile('text/plain', 'content.txt', JSON.stringify(encryptECIES(publicKey, JSON.stringify(content))))
.then(() => { console.log("Upload done - content") });
client.storeFile('text/plain', 'title.txt', JSON.stringify(encryptECIES(publicKey, JSON.stringify(title))))
.then(() => { console.log("Upload done - title") });
client.storeFile('text/plain', 'singleDocIsPublic.txt', JSON.stringify(encryptECIES(publicKey, JSON.stringify(singleDocIsPublic))))
.then(() => { console.log("Upload done - singleDocIsPublic") });
client.storeFile('text/plain', 'wordCount.txt', JSON.stringify(encryptECIES(publicKey, JSON.stringify(words))))
.then(() => { console.log("Upload done - wordCount") });
client.storeFile('text/plain', 'updated.txt', JSON.stringify(encryptECIES(publicKey, JSON.stringify(updated))))
.then(() => { console.log("Upload done - updated") });
client.storeFile('text/plain', 'id.txt', JSON.stringify(encryptECIES(publicKey, JSON.stringify(id))))
.then(() => { console.log("Upload done - id") });
}
sendFile() {
const user = this.state.receiverID;
const userShort = user.slice(0, -3);
const fileName = 'sharedsheets.json'
const file = userShort + fileName;
const publicKey = this.state.pubKey;
const data = this.state.sharedCollection;
const encryptedData = JSON.stringify(encryptECIES(publicKey, JSON.stringify(data)));
const directory = '/shared/' + file;
putFile(directory, encryptedData, {encrypt: false})
.then(() => {
console.log("Shared encrypted file ");
this.setState({ loading: false }, () => {
this.loadCollection();
})
})
.catch(e => {
console.log(e);
});
}
shareSheet() {
const user = this.state.receiverID;
const userShort = user.slice(0, -3);
const fileName = 'sharedsheets.json'
const file = userShort + fileName;
putFile(file, JSON.stringify(this.state.shareFile), {encrypt: true})
.then(() => {
this.setState({ shareModal: "hide", loading: "hide", show: "", hideSheet: "" });
window.Materialize.toast('Sheet shared with ' + this.state.receiverID, 4000);
})
.catch(e => {
console.log(e);
});
const publicKey = this.state.pubKey;
const data = this.state.shareFile;
const encryptedData = JSON.stringify(encryptECIES(publicKey, JSON.stringify(data)));
const directory = '/shared/' + file;
putFile(directory, encryptedData, {encrypt: false})
.then(() => {
console.log("Shared encrypted file");
})
.catch(e => {
console.log(e);
});
putFile(this.props.match.params.id + 'sharedwith.json', JSON.stringify(this.state.sharedWith), {encrypt: true})
.then(() => {
console.log("Shared With File Updated")
this.handleAddItem();
})
.catch(e => {
console.log(e);
export function saveCoinsIntegration() {
const data = this.state.docs;
const publicKey = this.state.coinsKey;
const encryptedData = JSON.stringify(encryptECIES(publicKey, JSON.stringify(data)));
const fileName = 'coinsIndex.json';
putFile(fileName, encryptedData, {encrypt: false})
.then(() => {
if(window.location.pathname === "/integrations") {
window.Materialize.toast('Coins integration updated', 4000);
this.saveIntegrations();
}
})
.catch(e => {
console.log(e);
});
}