How to use blockstack - 10 common examples

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 blockstack / radiks / test / setup.js View on Github external
beforeEach(async () => {
  const userSession = new UserSession({
    appConfig: new AppConfig(['store_write', 'publish_data']),
  });
  configure({
    userSession,
  });
  try {
    await collection.drop();
  } catch (error) {
    // collection doesn't exist
  }
  const appPrivateKey = makeECPrivateKey();
  const blockstackConfig = JSON.stringify({
    version: '1.0.0',
    userData: {
      appPrivateKey,
      username: faker.name.findName(),
github blockstack / radiks / test / setup.js View on Github external
beforeEach(async () => {
  const userSession = new UserSession({
    appConfig: new AppConfig(['store_write', 'publish_data']),
  });
  configure({
    userSession,
  });
  try {
    await collection.drop();
  } catch (error) {
    // collection doesn't exist
  }
  const appPrivateKey = makeECPrivateKey();
  const blockstackConfig = JSON.stringify({
    version: '1.0.0',
    userData: {
      appPrivateKey,
      username: faker.name.findName(),
      profile: {
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 / web / src / components / SSO.js View on Github external
componentDidMount() {
    if (isSignInPending()) {
      handlePendingSignIn().then((userData) => {
        window.location = window.location.href.split('=?')[0];
      });
    }
    // console.log(decodeToken(JSON.parse(localStorage.blockstack).authResponseToken).payload.public_keys[0])
    // console.log(new TokenVerifier('ES256K', decodeToken(JSON.parse(localStorage.blockstack).authResponseToken).payload.public_keys[0]).verify(JSON.parse(localStorage.blockstack).authResponseToken))
  }
github Graphite-Docs / graphite / src / components / documents / SingleDoc--NEW.js View on Github external
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)
github Graphite-Docs / graphite / src / components / forms / helpers / publicForm.js View on Github external
//console.log(host);
    let formId;
    if(window.location.href.includes('single')) {
        formId = window.location.href.split('forms/')[1].split('/')[1];
    } else {
        formId = window.location.href.split('forms/')[1].split('/')[1];
    }
    // const options = { username: host, zoneFileLookupURL: "https://core.blockstack.org/v1/names", decrypt: false}
    // let params = {
    //     fileName: `public/forms/${formId}.json`,
    //     options
    // }
    // let fetchedForm = await fetchData(params);
    // console.log(fetchedForm);
    // setGlobal({ publicForm: JSON.parse(fetchedForm), loading: false  });
    blockstack.lookupProfile(host, "https://core.blockstack.org/v1/names")
    .then((profile) => {
        //console.log(profile);
        //console.log(profile.apps[window.location.origin]);
        axios.get(`${profile.apps[window.location.origin]}public/forms/${formId}.json`)
        .then((response) => {
            //console.log(response);
            if(Object.keys(response.data).length > 0) {
                console.log(response.data);
                setGlobal({ publicForm: response.data, loading: false  });
            } else {
                console.log("error")
            }
        })
        .catch((error) => {
            console.log('error:', error);
        });
github Graphite-Docs / graphite / web / src / components / SSO.js View on Github external
componentDidMount() {
    if (isSignInPending()) {
      handlePendingSignIn().then((userData) => {
        window.location = window.location.href.split('=?')[0];
      });
    }
    // console.log(decodeToken(JSON.parse(localStorage.blockstack).authResponseToken).payload.public_keys[0])
    // console.log(new TokenVerifier('ES256K', decodeToken(JSON.parse(localStorage.blockstack).authResponseToken).payload.public_keys[0]).verify(JSON.parse(localStorage.blockstack).authResponseToken))
  }
github Graphite-Docs / graphite / web / src / components / vault / TestVault.js View on Github external
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(() =&gt; {
        console.log("Saved!");
        console.log(JSON.stringify(publicKey));
      })
      .catch(e =&gt; {
        console.log(e);
      });
    getFile("contact.json", {decrypt: true})
     .then((fileContents) =&gt; {
       let file = JSON.parse(fileContents || '{}');
       let contacts = file.contacts;
       if(contacts.length &gt; 0) {
         this.setState({ contacts: JSON.parse(fileContents || '{}').contacts });
       } else {
         this.setState({ contacts: [] });
       }
     })
      .catch(error =&gt; {
        console.log(error);
      });

    this.loadCollection();
  }
</a>
github Graphite-Docs / graphite / web / src / components / documents / Document.js View on Github external
saveNewFile() {
    // this.setState({ loading: "show" });
    // this.setState({ save: "hide"});
    blockstack.putFile("documents.json", JSON.stringify(this.state), true)
      .then(() => {
        console.log(JSON.stringify(this.state));
        window.location.href = '/';
      })
      .catch(e => {
        console.log("e");
        console.log(e);
        alert(e.message);
      });
  }
  handleCancel() {
github Graphite-Docs / graphite / web / src / components / helpers / singleVaultFile.js View on Github external
console.log(userShort + this.props.match.params.id + '.json')
        // console.log("Step Four: File Shared: " + getGlobal().shareFile);
        setGlobal({ shareModal: "hide", loading: "hide", show: "" });
        window.Materialize.toast('File shared with ' + getGlobal().receiverID, 4000);
      })
      .catch(e => {
        console.log("e");
        console.log(e);
      });
    const publicKey = getGlobal().pubKey;
    const data = getGlobal().shareFileIndex;
    const dataTwo = getGlobal().shareFile;
    const encryptedData = JSON.stringify(encryptECIES(publicKey, JSON.stringify(data)));
    const encryptedDataTwo = JSON.stringify(encryptECIES(publicKey, JSON.stringify(dataTwo)));
    const directory = '/shared/' + file;
    putFile(directory, encryptedData, {encrypt: false})
      .then(() => {

        console.log("Shared encrypted fileIndex" + directory);
      })
      .catch(e => {
        console.log(e);
      });
    putFile('/shared/' + userShort + this.props.match.params.id + '.json', encryptedDataTwo, {encrypt: false})
      .then(() => {
        console.log("Shared encrypted file");
        console.log(dataTwo);
        handleaddItem();
      })
      .catch(e => {
        console.log(e);
      });