Browse Source

Private tweet with encyption in pgp functional

rohit.gowda 4 years ago
parent
commit
f82c4c8977

+ 7 - 6
app/src/pages/write-tweet/write-tweet.ts

@@ -144,7 +144,7 @@ export class WriteTweetPage {
         console.log("yes in if");
         loading.setContent("Publish private tweet...");
         let result = await this.tweetPrivate();
-        console.log("this result is", result, result.data);
+        // console.log("this result is", result, result.data);
 
         // this.storeIPFS(result);
 
@@ -176,14 +176,15 @@ export class WriteTweetPage {
     console.log('private tweet is:', tweet.full_text);
     const privateKey = await this.storage.get("privateKey");
     //fetch followers and their public keys
-    //assuming the email id of rohit.shiva.gowda
-    await this.opnpgp.lookupKeys("rohit.hosn@gmail.com");
-    await this.opnpgp.lookupKeys("rohit.shiva.gowda@gmail.com");
+    //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(tweet.full_text);
+    let encryptedTweet = await this.opnpgp.encrypt(JSON.stringify(tweet));
 
     this.storeIPFS(encryptedTweet, tweet)
-    return await this.opnpgp.encrypt(tweet.full_text);
+    return encryptedTweet;
     
     
   }

+ 3 - 6
app/src/providers/feed/feed.ts

@@ -126,6 +126,7 @@ export class FeedProvider {
 
     // Load private tweets from P2P storage
     for (let i = 0; i < privateTweetsData.length; i++) {
+      console.log("privateTweetsData.length:",privateTweetsData.length);
       const hash = privateTweetsData[i]["hash"];
       const userId = privateTweetsData[i]["userId"];
       const timestamp = privateTweetsData[i]["created_at"];
@@ -142,16 +143,12 @@ export class FeedProvider {
       // Fetch public key history for user
     
 
-      // Decrypt tweets
-      // const decryptedTweet = this.cryptoUtils.decrypt(
-      //   encryptedTweet,
-      //   this.getPublicKeyAt(timestamp, publicKeyHistory)
-      // );
       console.log('decrypting private tweets');
       let pvtKey = await this.storage.get("privateKey");
 
        const decryptedTweet = await this.opnpgp.decrypt(encryptedTweet,pvtKey);
-      // privateTweets.push(JSON.parse(decryptedTweet));
+        if(decryptedTweet)
+         privateTweets.push(JSON.parse(decryptedTweet));
     }
 
     if(privateTweets.length>0){

+ 1 - 1
app/src/providers/p2p-database-gun/p2p-database-gun.ts

@@ -5,7 +5,7 @@ import "gun/lib/then";
 @Injectable()
 export class P2pDatabaseGunProvider {
   private gun;
-  osnPrefix: string = "hybridOSN-v1.0.0";
+  osnPrefix: string = "hybridOSN-v2.0.0";
 
   constructor() {
     this.gun = Gun(["https://hosn-twitter-app.herokuapp.com/gun"]);