import 'dart:convert'; import 'package:omemo_dart/omemo_dart.dart'; /// This example aims to demonstrate how omemo_dart is used. Since omemo_dart is not /// dependent on any XMPP library, you need to convert stanzas to the appropriate /// intermediary format and back. void main() async { const aliceJid = 'alice@some.server'; const bobJid = 'bob@other.serve'; // You are Alice and want to begin using OMEMO, so you first create a SessionManager final aliceSession = await OmemoSessionManager.generateNewIdentity( // The bare Jid of Alice as a String aliceJid, // The trust manager we want to use. In this case, we use the provided one that // implements "Blind Trust Before Verification". To make things simpler, we keep // no persistent data and can thus use the MemoryBTBVTrustManager. If we wanted to keep // the state, we would have to override BlindTrustBeforeVerificationTrustManager. MemoryBTBVTrustManager(), // Here we specify how many Onetime Prekeys we want to have. XEP-0384 recommends around // 100 OPKs, so let's generate 100. The parameter defaults to 100. //opkAmount: 100, ); // Alice now wants to chat with Bob at his bare Jid "bob@other.server". To make things // simple, we just generate the identity bundle ourselves. In the real world, we would // request it using PEP and then convert the device bundle into a OmemoBundle object. final bobSession = await OmemoSessionManager.generateNewIdentity( bobJid, MemoryBTBVTrustManager(), // Just for illustrative purposes opkAmount: 1, ); // Alice prepares to send the message to Bob, so she builds the message stanza and // collects all the children of the stanza that should be encrypted into a string. const aliceMessageStanzaBody = ''' Hello Bob, it's me, Alice! '''; // Since OMEMO 0.8.3 mandates usage of XEP-0420: Stanza Content Encryption, we have to // wrap our acual payload - aliceMessageStanzaBody - into an SCE envelope. Note that // the rpad element must contain a random string. See XEP-0420 for recommendations. // OMEMO makes the