Browse Source

ecrypt with followers key and code cleanup

rohit.gowda 4 years ago
parent
commit
b9ef00d002

+ 0 - 3
app/src/pages/home/home.ts

@@ -93,12 +93,9 @@ export class HomePage {
 
   privateTweetOnly(){
     this.privateTweet = !this.privateTweet;
-    console.log("this.privateTweets",this.privateTweets);
-
     const loading = this.loadingCtrl.create();
     loading.present();
     this.tweets = this.privateTweets;
-    console.log("privateTweet color",this.privateTweet)
     loading.dismiss();
 
     if(this.privateTweet)

+ 0 - 10
app/src/pages/settings/settings.ts

@@ -41,15 +41,12 @@ export class SettingsPage {
   async loadValuesFromStorage() {
     this.privateKey = await this.storage.get("privateKey");
     this.publicKey = await this.storage.get("publicKey");
-    console.log("private key", this.privateKey);
-    console.log("public key", this.publicKey);
     this.keywords = await this.storage.get("keywords");
     this.email = await this.storage.get("email");
   }
 
   generateKeys() {
     if (!this.email) {
-      console.log("email is not provided or not valid");
       return;
     } else {
       this.storage.set("email", this.email);
@@ -84,9 +81,6 @@ export class SettingsPage {
     this.publicKey = keys.publicKeyArmored;
     this.revocationCertificate = keys.revocationCertificate;
     this.keyid = keys.key.primaryKey.keyid;
-    console.log('key id is:',this.keyid);
-    console.log("private key", this.privateKey);
-    console.log("public key", this.publicKey);
   }
 
 
@@ -96,8 +90,6 @@ export class SettingsPage {
     this.storage.set("keyid", this.keyid);
     this.storage.set("revocationCert", this.revocationCertificate);
     this.storage.set("keywords", this.keywords ? this.keywords.trim() : "");
-
-    
     this.showToast("Successfully saved!");
   }
 
@@ -106,11 +98,9 @@ export class SettingsPage {
     this.showToast("Publc key published");
 
     const userId = await this.storage.get("userId");
-    console.log("userid is:",userId);
     await this.gun.setEmail(userId, this.email);
     //test if stored in gun
     const email = await this.gun.getEmail(userId);
-    console.log("email:",email);
   }
 
   exportPrivateKey() {

+ 0 - 13
app/src/pages/write-tweet/write-tweet.ts

@@ -131,7 +131,6 @@ export class WriteTweetPage {
   }
 
   async submitTweet() {
-    console.log('Submitting tweet')
     const loading = this.loadingCtrl.create();
     loading.present();
 
@@ -141,15 +140,10 @@ export class WriteTweetPage {
         (await this.cryptoUtils.isPrivateKeySet()) &&
         (await this.cryptoUtils.isPublicKeyPublished())
       ) {
-        console.log("yes in if");
         loading.setContent("Publish private tweet...");
         let result = await this.tweetPrivate();
-        // console.log("this result is", result, result.data);
-
-        // this.storeIPFS(result);
 
       } else {
-        console.log("in else block");
         loading.dismiss();
         const alert = this.alertCtrl.create({
           title: "Oooops...",
@@ -173,26 +167,21 @@ export class WriteTweetPage {
 
   private async tweetPrivate() {
     const tweet = await this.buildPrivateTweet();
-    console.log('private tweet is:', tweet.full_text);
     const privateKey = await this.storage.get("privateKey");
     //fetch followers and their public keys
     //encrypting for self
     let email = await this.storage.get("email");
     await this.opnpgp.lookupKeys(email);
-    // await this.opnpgp.lookupKeys("rohit.shiva.gowda@gmail.com");
     //encrypt the tweet with multiple keys
     let encryptedTweet = await this.opnpgp.encrypt(JSON.stringify(tweet));
 
     this.storeIPFS(encryptedTweet, tweet)
     return encryptedTweet;
-    
-    
   }
 
   private async storeIPFS(result, tweet){
 
     const res = await this.ipfs.storeTweet(result);
-    console.log("pvt tweet hash is",res);
     this.gun.storeLastTweetHashForUser(
       tweet.user_id,
       res["Hash"],
@@ -200,8 +189,6 @@ export class WriteTweetPage {
     );
 
     this.gun.publishHashtags(tweet.entities.hashtags);
-
-
   }
 
   private async buildPrivateTweet() {

+ 0 - 2
app/src/providers/crypto/crypto.ts

@@ -136,7 +136,6 @@ export class CryptoProvider {
   }
 
   public async generatePgpKeys(email) {
-    console.log("this is the mail of the iser ", email);
     let options = {
       userIds: [{ name: 'Rohithosn', email: email }], // multiple user IDs
       curve: "ed25519", // ECC curve name
@@ -144,7 +143,6 @@ export class CryptoProvider {
     };
 
     let a = await openpgp.generateKey(options);
-    console.log('resolved a = ', a);
     return a;
   }
 

+ 8 - 9
app/src/providers/feed/feed.ts

@@ -90,7 +90,6 @@ export class FeedProvider {
       .map(friend => friend.id_str)
       .concat([this.userId]);
 
-      console.log('fetch hometimeline private tweets');
     // Fetch ipfs hashs for period
     const promises: Promise < object[] > [] = friendsAndUserIds.map(accountId => {
       return this.gun.fetchPrivateTweetHashsForUserInInterval(
@@ -111,7 +110,6 @@ export class FeedProvider {
 
     if (privateTweetHashs.length > 0) {
       const privateTweets = await this.fetchPrivateTweets(privateTweetHashs);
-      console.log("private tweets returned are:",privateTweets);
       // Combine and sort tweets
        return tweets
         .concat(privateTweets)
@@ -131,9 +129,16 @@ export class FeedProvider {
     });
 
      const resolvedPromises = await Promise.all(emailPromises);
-     console.log("resolved promises",resolvedPromises);
+      for (let i = 0; i < resolvedPromises.length; i++) {
+        if(resolvedPromises[i]){
+          let email = resolvedPromises[i]["email"];
+           this.opnpgp.lookupKeys(email);
+        }
+        
+      }
   }
 
+
   private async fetchPrivateTweets(privateTweetsData: object[]) {
     const privateTweets = [];
 
@@ -147,19 +152,14 @@ export class FeedProvider {
       const encryptedTweet = await this.ipfs.fetchTweet(hash);
 
       if(!encryptedTweet){
-        console.log('encrypted tweet:',encryptedTweet)
         return;
       }
 
       // Fetch public key history for user
-    
-
-      console.log('decrypting private tweets');
       let pvtKey = await this.storage.get("privateKey");
 
       try{
          const decryptedTweet = await this.opnpgp.decrypt(encryptedTweet,pvtKey);
-         console.log("decrypted tweet is:",decryptedTweet);
          if(decryptedTweet)
           privateTweets.push(JSON.parse(decryptedTweet));
       }
@@ -168,7 +168,6 @@ export class FeedProvider {
       }
       
     }
-    console.log("privateTweets:",privateTweets);
     if(privateTweets.length>0){
        // Add retweeted/quoted status
       privateTweets.map(async tweet => await this.addQuotedStatusToTweet(tweet));

+ 7 - 4
app/src/providers/p2p-database-gun/p2p-database-gun.ts

@@ -77,15 +77,18 @@ export class P2pDatabaseGunProvider {
         .map(key => this.gun.get(key).then())
       );
 
-      return entries
+         return entries
         .filter(entry => {
-          const createdAtDate = new Date(entry["created_at"]);
-          return createdAtDate < intervalStart && createdAtDate >= intervalEnd;
+          if(entry){
+            const createdAtDate = new Date(entry["created_at"]);
+            return createdAtDate < intervalStart && createdAtDate >= intervalEnd;
+          }
         })
         .map(entry => {
           entry.userId = userId;
           return entry;
         });
+     
     } else {
       return [];
     }
@@ -144,7 +147,7 @@ export class P2pDatabaseGunProvider {
     let entry = await this.gun
       .get(this.osnPrefix)
       .get("email");
-    console.log("get the email entry from gun :",entry);
+      
     const emailEntry = await this.gun
       .get(this.osnPrefix)
       .get("email")

+ 0 - 1
app/src/providers/p2p-storage-ipfs/p2p-storage-ipfs.ts

@@ -12,7 +12,6 @@ export class P2pStorageIpfsProvider {
    * @param tweet tweet object
    */
   public storeTweet(tweet) {
-    console.log('storing tweet');
     return this.storeOnIPFS(tweet);
   }
 

+ 2 - 13
app/src/providers/pgp-key-server/pgp-key-server.ts

@@ -19,26 +19,23 @@ export class PgpKeyServerProvider {
     };
 
     let a = await openpgp.generateKey(options);
-    console.log('the key generated is:', a);
     return a;
   }
 
   public async publishPubKey(pubkey) {
-    console.log('passing pubkey to uplaoded : ', pubkey);
     this.hkp.upload(pubkey).then(function(result) {
       console.log('public key successfully uploaded',result);
     });
   }
 
   public async lookupKeys(email: string) {
-    console.log('looking up keys for',email);
+    // console.log('looking up keys for',email);
     var options = {
       query: email
     };
     try{
       let armoredPubkey = await this.hkp.lookup(options);
       let pubkey = (await openpgp.key.readArmored(armoredPubkey)).keys[0];
-      console.log('Found latest public key:', pubkey);
       this.pk.push(pubkey);
       return pubkey;
     }
@@ -55,33 +52,26 @@ export class PgpKeyServerProvider {
    * @param privateKey private key
    */
   public async encrypt(plainText) {
-    console.log('pk is:', this.pk);
     if(!this.pk){ console.log("this.pk is empty"); return;}
-    // this.lookupKeys('rohit.shiva.gowda@gmail.com');
+
     const options = {
       message: openpgp.message.fromText(plainText), // input as Message object
       publicKeys: await Promise.all(this.pk), // for encryption
       // privateKey s: [privKeyObj] // for signing (optional)
     }
-    // console.log('options are:', options);
     const ciphertext = await openpgp.encrypt(options);
-    console.log('encrypted text is:', ciphertext);
     return ciphertext.data;
   }
 
   public async decrypt(encrypted: string,a) {
     const privKeyObj = (await openpgp.key.readArmored(a)).keys[0];
-    console.log('privKeyObj', privKeyObj);
     await privKeyObj.decrypt(this.passphrase);
-    // console.log('a is:',a);
     const options2 = {
       message: await openpgp.message.readArmored(encrypted), // parse armored message
       privateKeys: [privKeyObj] // for decryption
     }
-    // console.log('options2 is: ', options2);
     try{
        let plaintext = await openpgp.decrypt(options2);
-      console.log('decrypted text is:', plaintext);
       return plaintext.data // 'Hello, World!'
     }
      catch(err){
@@ -94,7 +84,6 @@ export class PgpKeyServerProvider {
     //using revocation certificate
     let pubkey = await this.storage.get("publicKey");
     let atest = (await openpgp.key.readArmored(pubkey)).keys[0];
-    console.log('inside revoke key pubkey is:', atest);
     let revocatnCert = this.storage.get("revocationCert");
     try {
       var options = {