Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentDidMount() {
window.$('.button-collapse').sideNav({
menuWidth: 400, // Default is 300
edge: 'left', // Choose the horizontal origin
closeOnClick: false, // Closes side-nav on <a> clicks, useful for Angular/Meteor
draggable: true, // Choose whether you can drag to open on touch screens
}
);
const publicKey = getPublicKeyFromPrivate(loadUserData().appPrivateKey)
putFile('key.json', JSON.stringify(publicKey), {encrypt: false})
.then(() => {
console.log("Saved!");
console.log(JSON.stringify(publicKey));
})
.catch(e => {
console.log(e);
});
getFile("contact.json", {decrypt: true})
.then((fileContents) => {
let file = JSON.parse(fileContents || '{}');
let contacts = file.contacts;
if(contacts.length > 0) {
this.setState({ contacts: JSON.parse(fileContents || '{}').contacts });
} else {
this.setState({ contacts: [] });</a>
export function checkForLatest() {
this.setState({ checking: true });
console.log("Polling teammates...")
const { team, count } = this.state;
console.log("Team length greater than count?");
console.log(team.length > count);
if(team.length > count) {
let user = team[count].blockstackId;
const options = { username: user, zoneFileLookupURL: "https://core.blockstack.org/v1/names", decrypt: false };
const privateKey = loadUserData().appPrivateKey;
if(loadUserData().username !== user) {
console.log('Checking file from: ' + team[count].name);
const file = getPublicKeyFromPrivate(loadUserData().appPrivateKey) + '.json';
getFile(file, options)
.then((fileContents) => {
if(fileContents){
console.log('Newer file? ' + JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).lastUpdated > this.state.lastUpdated);
if(JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).lastUpdated > this.state.lastUpdated) {
console.log('Setting teammate with the most recent file: ' + user);
this.setState({
teamMateMostRecent: user,
count: this.state.count + 1
});
setTimeout(this.checkForLatest, 300);
} else {
this.setState({ count: this.state.count + 1 });
setTimeout(this.checkForLatest, 300);
}
} else {
componentDidMount() {
const publicKey = getPublicKeyFromPrivate(loadUserData().appPrivateKey)
putFile('key.json', JSON.stringify(publicKey))
.then(() => {
console.log("Saved!");
console.log(JSON.stringify(publicKey));
})
.catch(e => {
console.log(e);
});
getFile("documents.json", {decrypt: true})
.then((fileContents) => {
if(fileContents) {
this.setState({ value: JSON.parse(fileContents || '{}').value });
this.setState({filteredValue: this.state.value})
this.setState({ loading: "hide" });
} else {
componentDidMount() {
const publicKey = getPublicKeyFromPrivate(loadUserData().appPrivateKey)
putFile('key.json', JSON.stringify(publicKey))
.then(() => {
console.log("Saved!");
console.log(JSON.stringify(publicKey));
})
.catch(e => {
console.log(e);
});
getFile("spread.json", {decrypt: true})
.then((fileContents) => {
if(fileContents) {
console.log("Files are here");
this.setState({ sheets: JSON.parse(fileContents || '{}').sheets });
this.setState({filteredSheets: this.state.sheets})
export async function createTeam(teamName) {
//First check if shared key exists
//The check will differ depending on whether the user is the root user or not.
let name = blockstack.loadUserData().username;
if (name.split(".").length > 2) {
//This means the user is not the root user.
//need to find logged in user's appPubKey
let userPubKey = blockstack.getPublicKeyFromPrivate(blockstack.loadUserData().appPrivateKey)
//file name for the root level team key.
let fileName = `${userPubKey}/keys/root/teamkey.json`;
//will always be looking this up from root level user.
let user = `${blockstack.loadUserData().username.split('.')[1]}.${blockstack.loadUserData().username.split('.')[2]}`
let encryptedKey = await getUserKey(fileName, user);
pubKey = await blockstack.decryptContent(JSON.stringify(encryptedKey), {
privateKey: blockstack.loadUserData().appPrivateKey
});
const object = {};
object.id = uuidv4();
object.name = teamName;
object.teamPath = teamName ? `Teams/${teamName}` : 'Teams/Administrators';
object.members = [];
await this.setState({ teams: [...this.state.teams, object] }, () => {
let data = this.state.teams;
let file = "Administrators/teams.json";
export async function startTrial() {
const { userSession } = getGlobal();
const privateKey = makeECPrivateKey();
const publicKey = getPublicKeyFromPrivate(privateKey);
const name = document.getElementById('trial-name').value;
const organization = document.getElementById('trial-org').value;
const email = document.getElementById('trial-email').value;
const trialObject = {
orgId: uuid(),
userId: uuid(),
name,
organization,
email,
blockstackId: getGlobal().userSession.loadUserData().username,
pubKey: blockstack.getPublicKeyFromPrivate(userSession.loadUserData().appPrivateKey),
teamPubKey: publicKey
}
let trialParams = {
fileName: "account.json",
encrypt: true,
body: JSON.stringify(trialObject)
}
let postTrial = await postData(trialParams);
console.log(postTrial);
const data = {
profile: userSession.loadUserData().profile,
username: userSession.loadUserData().username,
pubKey: getPublicKeyFromPrivate(privateKey)
.then((file) => {
if(file) {
//Check if the key has already been created.
console.log("Root level team key found.")
const encryptedKey = blockstack.encryptContent(file, {
publicKey: pubKey
});
blockstack.putFile(`${pubKey}/${fileName}`, encryptedKey, {encrypt: false})
rootKey = blockstack.getPublicKeyFromPrivate(JSON.parse(file));
} else {
alert('Error fetching key');
}
})
.then(() => {
function writeCollectionKeysToAppStorage(appPrivateKey, hubConfig, keyFile) {
const publicKey = getPublicKeyFromPrivate(appPrivateKey)
const encryptedKeyFile = encryptContent(JSON.stringify(keyFile), { publicKey })
return uploadToGaiaHub(
GAIA_HUB_COLLECTION_KEY_FILE_NAME,
encryptedKeyFile,
hubConfig,
'application/json'
)
}
await asyncForEach(contacts, async contact => {
const userToLoadFrom = contact.contact;
const fileString = 'shareddocs.json';
const file = blockstack.getPublicKeyFromPrivate(userSession.loadUserData().appPrivateKey) + fileString;
const privateKey = userSession.loadUserData().appPrivateKey;
const directory = `shared/${file}`;
const options = { username: userToLoadFrom, zoneFileLookupURL: "https://core.blockstack.org/v1/names", decrypt: false}
let params = {
fileName: directory,
options
}
let sharedCollection = await fetchData(params);
if(sharedCollection) {
let decryptedContent = JSON.parse(userSession.decryptContent(sharedCollection, {privateKey: privateKey}));
let filteredDocs = decryptedContent.filter(a => a.sharedBy);
sharedDocs = sharedDocs.concat(filteredDocs);
}
export function loadTeamDocs() {
const { team, count } = global;
if(team.length > count) {
let publicKey = getPublicKeyFromPrivate(loadUserData().appPrivateKey);
let fileString = 'shareddocs.json'
let file = publicKey + fileString;
const directory = 'shared/' + file;
const user = team[count].blockstackId;
const options = { username: user, zoneFileLookupURL: "https://core.blockstack.org/v1/names", decrypt: false}
getFile(directory, options)
.then((fileContents) => {
let privateKey = loadUserData().appPrivateKey;
setGlobal({
docs: getGlobal().docs.concat(JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents)))),
count: getGlobal().count + 1
})
})
.then(() => {
this.loadTeamDocs();
})