How to use the blockstack.loadUserData 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 / sheets / SingleSharedSheet.js View on Github external
.then((fileContents) => {
    let privateKey = loadUserData().appPrivateKey;
    console.log(JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))))
    this.setState({ shareFile: JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))) })
    console.log("loaded");
    let allSheets = this.state.shareFile;
    // let sheets = allSheets.shareFile;
    const thisSheet = allSheets.find((sheet) => { return sheet.id.toString() === window.location.href.split('shared/')[1].split('/')[1]}); //this is comparing strings
    let index = thisSheet && thisSheet.id;
    console.log(index);
    function findObjectIndex(sheet) {
        return sheet.id === index; //this is comparing numbers
    }
    this.setState({ grid: thisSheet && thisSheet.content, title: thisSheet && thisSheet.title, index: allSheets.findIndex(findObjectIndex), loading: false })
  })
  .catch(error => {
github Graphite-Docs / graphite / src / components / documents / SingleDoc--NEW.js View on Github external
handleAutoAdd() {
    console.warn('calling handleAutoAdd!!!')
    if (this.state.singleDocIsPublic === true) {
      this.sharePublicly()
    }
    const object = {};
    object.title = this.state.title;
    object.content = this.state.content;
    object.id = parseInt(this.props.match.params.id, 10);
    object.updated = getMonthDayYear();
    object.sharedWith = [];
    object.singleDocIsPublic = this.state.singleDocIsPublic; //true or false...
    object.author = loadUserData().username;
    // object.sharedWith = this.state.sharedWith;
    object.words = wordcount(this.state.content);
    object.tags = this.state.tags;
    this.setState({singleDoc: object});
    this.setState({autoSave: "Saving..."});
    const objectTwo = {};
    objectTwo.title = this.state.title;
    objectTwo.id = parseInt(this.props.match.params.id, 10);
    objectTwo.updated = getMonthDayYear();
    objectTwo.words = wordcount(this.state.content);
    objectTwo.sharedWith = [];
    objectTwo.singleDocIsPublic = this.state.singleDocIsPublic; //true or false...
    objectTwo.author = loadUserData().username;
    // objectTwo.sharedWith = this.state.sharedWith;
    objectTwo.tags = this.state.tags;
    const index = this.state.index;
github jehunter5811 / graphite-blockstack / src / components / messages / SingleConversation.js View on Github external
lookupProfile(username, "https://core.blockstack.org/v1/names")
    .then((profile) => {
      let image = profile.image;
      if(profile.image){
        this.setState({conversationUserImage: image[0].contentUrl})
      }
      this.setState({
        person: new Person(profile),
        username: username
      })
    })
    .catch((error) => {
      console.log('could not resolve profile')
    })
  const fileName = loadUserData().username.slice(0, -3) + '.json';
  const privateKey = loadUserData().appPrivateKey;
  const directory = '/shared/' + fileName;
  getFile(directory, options)
    .then((file) => {
      console.log("Shared file: " + file);
      // console.log("Shared messages: " + JSON.parse(decryptECIES(privateKey, JSON.parse(file))));
      console.log("fetched!");

      this.setState({ tempMessages: JSON.parse(decryptECIES(privateKey, JSON.parse(file))) });
      let temp = this.state.tempMessages;
      this.setState({ sharedMessages: temp.messages});
      this.setState({ combinedMessages: [...this.state.myMessages, ...this.state.sharedMessages] });
      this.setState({ loading: "hide", show: "" });
      this.scrollToBottom();
    })
    .catch((error) => {
github Graphite-Docs / graphite / web / src / components / helpers / sharedVaultFiles.js View on Github external
export async function loadSharedVault() {
  const authProvider = JSON.parse(localStorage.getItem('authProvider'));
  setGlobal({ loading: true });
  await loadVault();
  setGlobal({ user: window.location.href.split('shared/')[1].split('#')[0] });
  let fileID;
  if(authProvider === 'uPort') {
    fileID = JSON.parse(localStorage.getItem('uPortUser')).payload.did;
  } else {
    fileID = loadUserData().username;
  }
  console.log(fileID);
  let fileString = 'sharedvault.json'
  let file = fileID.replace('.', '_') + fileString;
  const directory = '/shared/' + file;
  const options = { username: window.location.href.split('shared/')[1], zoneFileLookupURL: "https://core.blockstack.org/v1/names", decrypt: false}
  if(window.location.href.includes('did:')) {
    if(authProvider === 'uPort') {
      
    } else {
      const privateKey = loadUserData().appPrivateKey;
      //the sharer is a uPort user and thus shared using IPFS. Need to fetch from there. 
      const params = {
        provider: 'ipfs',
        filePath: `${file}`
        };
github jehunter5811 / graphite-blockstack / src / components / messages / Contacts.js View on Github external
renderView() {
    let contacts = this.state.filteredContacts;
    console.log(loadUserData().username);
    const userData = blockstack.loadUserData();
    const person = new blockstack.Person(userData.profile);
    let show = this.state.show;
    let showResults = "";
    let loading = this.state.loading;
    let results = this.state.results;
    let newContact = this.state.newContact;
    let showFirstLink = this.state.showFirstLink;
    let showSecondLink = this.state.showSecondLink;

    if(newContact.length < 1) {
      showResults = "hide";
    } else {
      showResults = "";
    }

    if(this.state.add == true){
github Graphite-Docs / graphite / src / components / journalism / EditorCollection.js View on Github external
loadTeamFiles() {
    if(this.state.count < this.state.team.length) {
      console.log(this.state.team[this.state.count].name);
      const file = loadUserData().username + 'submitted.json';
      console.log(file);
      const options = { username: this.state.team[this.state.count].name, zoneFileLookupURL: "https://core.blockstack.org/v1/names", decrypt: false}
        getFile(file, options)
         .then((fileContents) => {
           let privateKey = loadUserData().appPrivateKey;
           if(JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).length > 0) {
             this.setState({ newMatePosts: JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))) })
           } else {
             this.setState({ newMatePosts: [] })
           }
           this.setState({count: this.state.count + 1});
         })
          .then(() => {
            console.log(this.state.matePosts);
            let finalMatePosts = this.state.matePosts.concat(this.state.newMatePosts);
            this.setState({ matePosts: finalMatePosts});
github Graphite-Docs / graphite / web / src / components / documents / SingleSharedDoc.js View on Github external
getOther() {
  let fileID = loadUserData().username;
  console.log(this.state.user);
  let fileString = 'shareddocs.json'
  let file = fileID.slice(0, -3) + fileString;
  const directory = '/shared/' + file;
  const options = { username: this.state.user, zoneFileLookupURL: "https://core.blockstack.org/v1/names", decrypt: false}
    getFile(directory, options)
     .then((fileContents) => {
       let privateKey = loadUserData().appPrivateKey;
        this.setState({ sharedFile: JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))) })
        let docs = this.state.sharedFile;
        const thisDoc = docs.find((doc) => { return doc.id.toString() === this.props.match.params.id}); //comparing strings
        let index = thisDoc && thisDoc.id;
        function findObjectIndex(doc) {
            return doc.id === index; //comparing numbers
        }
        this.setState({ content: thisDoc && thisDoc.content, title: thisDoc && thisDoc.title, index: docs.findIndex(findObjectIndex) })
github Graphite-Docs / graphite / src / components / documents / SingleDoc--NEW.js View on Github external
this.saveCollection();
    })
    .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") });
  }
github Graphite-Docs / graphite / web / src / enterpriseModel / teams.js View on Github external
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';