Getting Started with DIDComm Messaging

Here's a basic example of how to send a message using the library:

import zio._
import zio.json._
import fmgp.did._
import fmgp.did.comm._
import fmgp.did.comm.protocol.basicmessage2._

// Initialize a new message
val message = new BasicMessage(
  to = Set(TO("did:example:123")),
  content = "Hello, World!",
  from = Some(FROM("did:example:456")), 
)
// message: BasicMessage = BasicMessage(
//   id = "f7868506-cd1a-4a4c-b5da-24151ea8bc8d",
//   to = Set("did:example:123"),
//   from = Some(value = "did:example:456"),
//   lang = None,
//   created_time = None,
//   content = "Hello, World!"
// )


message.toPlaintextMessage.toJsonPretty
// res0: String = """{
//   "id" : "f7868506-cd1a-4a4c-b5da-24151ea8bc8d",
//   "type" : "https://didcomm.org/basicmessage/2.0/message",
//   "to" : [
//     "did:example:123"
//   ],
//   "from" : "did:example:456",
//   "body" : {
//     "content" : "Hello, World!"
//   }
// }"""

To receive messages, you can use the following code:

Further Resources

The library's documentation The DIDComm V2 specification - (https://identity.foundation/didcomm-messaging/spec/) The Decentralized Identity Foundation (DIF) - https://identity.foundation/