(user, fromUserId)
| 64 | }, []); |
| 65 | |
| 66 | const sendMessageToUser = async (user, fromUserId) => { |
| 67 | // send message |
| 68 | const ourSecretKey = await getMySecretKey(); |
| 69 | if (!ourSecretKey) { |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | if (!user.publicKey) { |
| 74 | Alert.alert( |
| 75 | "The user haven't set his keypair yet", |
| 76 | "Until the user generates the keypair, you cannot securely send him messages" |
| 77 | ); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | console.log("private key", ourSecretKey); |
| 82 | |
| 83 | const sharedKey = box.before( |
| 84 | stringToUint8Array(user.publicKey), |
| 85 | ourSecretKey |
| 86 | ); |
| 87 | console.log("shared key", sharedKey); |
| 88 | |
| 89 | const encryptedMessage = encrypt(sharedKey, { message }); |
| 90 | console.log("encrypted message", encryptedMessage); |
| 91 | |
| 92 | const newMessage = await DataStore.save( |
| 93 | new Message({ |
| 94 | content: encryptedMessage, // <- this messages should be encrypted |
| 95 | userID: fromUserId, |
| 96 | forUserId: user.id, |
| 97 | chatroomID: chatRoom.id, |
| 98 | replyToMessageID: messageReplyTo?.id, |
| 99 | }) |
| 100 | ); |
| 101 | |
| 102 | // updateLastMessage(newMessage); |
| 103 | }; |
| 104 | |
| 105 | const sendMessage = async () => { |
| 106 | // get all the users of this chatroom |
no test coverage detected