How to use the blockstack.getPublicKeyFromPrivate 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 / vault / TestVault.js View on Github external
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(() =&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: [] });</a>
github Graphite-Docs / graphite / web / src / components / helpers / teamsync.js View on Github external
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 {
github jehunter5811 / graphite-blockstack / src / components / documents / Collections.js View on Github external
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 {
github jehunter5811 / graphite-blockstack / src / components / sheets / SheetsCollections.js View on Github external
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})
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';
    object.members = [];
    await this.setState({ teams: [...this.state.teams, object] }, () => {
      let data = this.state.teams;
      let file = "Administrators/teams.json";
github Graphite-Docs / graphite / src / components / pro / helpers / trialSignUps.js View on Github external
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)
github Graphite-Docs / graphite / web / src / enterpriseModel / people.js View on Github external
.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(() => {
github blockstack / blockstack-browser / app / js / utils / collection-utils.js View on Github external
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'
  )
}
github Graphite-Docs / graphite / src / components / docs / helpers / sharedDocsCollection.js View on Github external
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);
        }
github Graphite-Docs / graphite / web / src / components / helpers / documents.js View on Github external
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();
     })