@@ -485,10 +485,31 @@ class WebAppInterface(val act: MainActivity, val webView: WebView) {
485485 Bipf .list_append(lst, tst)
486486 Bipf .list_append(lst, Bipf .mkNone()) // placeholder for voice
487487
488- val body = Bipf .encode(lst)
489- if (body != null ) {
490- act.tinyNode.publish_public_content(body)
488+ // encrypt the entry such that only I can read it
489+ val recps = Bipf .mkList()
490+ val keys: MutableList <ByteArray > = mutableListOf ()
491+ val me = act.idStore.identity.toRef()
492+ Bipf .list_append(recps, Bipf .mkString(me))
493+ keys.add(me.deRef())
494+ Bipf .list_append(lst, recps)
495+
496+ val body_clear = Bipf .encode(lst)
497+ val encrypted = body_clear!! .let { act.idStore.identity.encryptPrivateMessage(it, keys) }
498+
499+ val body_encr = Bipf .encode(Bipf .mkBytes(encrypted))
500+
501+ // test if entry can be decrypted
502+ val clear = encrypted?.let { act.idStore.identity.decryptPrivateMessage(it) }
503+ if (clear != null ) {
504+ val clearList = Bipf .decode(clear)
505+ if (clearList != null ) {
506+ val clearJson = Bipf .bipf_list2JSON(clearList)
507+ Log .d(" trust_contact" , clearJson.toString())
508+ }
491509 }
510+
511+ if (body_encr != null )
512+ act.tinyNode.publish_public_content(body_encr)
492513 reloadContactsTrustLevel()
493514 }
494515
@@ -501,11 +522,23 @@ class WebAppInterface(val act: MainActivity, val webView: WebView) {
501522 if (lastSeq != null ) {
502523 for (i in lastSeq downTo 1 ) {
503524 var entry = userFeed.read_content(lastSeq)
504- val entryType = entry?.let { getFromEntry(it, 0 ) }
525+ // decode the entry using Bipf decode
526+ val decodedEntry = entry?.let { Bipf .decode(it) }
527+ Log .d(" decodedEntry" , decodedEntry.toString())
528+
529+ // get bytes from the decoded entry
530+ val entryBytes = decodedEntry?.let {it.getBytes()}
531+ Log .d(" entryBytes" , entryBytes.toString())
532+
533+ // decrypt the bytes to get the clear text
534+ val clear = entryBytes?.let { act.idStore.identity.decryptPrivateMessage(it) }
535+ Log .d(" clear" , clear.toString())
536+
537+ val entryType = clear?.let { getFromEntry(it, 0 ) }
505538 if (entryType == " TRT" ) {
506- if (entry is ByteArray ) {
507- val contactID = getFromEntry(entry , 2 )
508- val trustLevel = getFromEntry(entry , 3 )
539+ if (clear is ByteArray ) {
540+ val contactID = getFromEntry(clear , 2 )
541+ val trustLevel = getFromEntry(clear , 3 )
509542 if (contactID != null && trustLevel != null ) {
510543 contactsTrustLevel[contactID.toString()] = trustLevel.toString().toInt()
511544 }
@@ -663,6 +696,8 @@ class WebAppInterface(val act: MainActivity, val webView: WebView) {
663696 hdr.put(" fid" , " @" + fid.toBase64() + " .ed25519" )
664697 hdr.put(" ref" , mid.toBase64())
665698 hdr.put(" seq" , seq)
699+ Log .d(" decrypted log entry" , hdr.toString())
700+ Log .d(" decrypted log entry" , param.toString())
666701 return " {header:${hdr.toString()} , confid:${param.toString()} }"
667702 }
668703 }
0 commit comments