-
Notifications
You must be signed in to change notification settings - Fork 5
/
ForwardMessage.kt
43 lines (37 loc) · 1.35 KB
/
ForwardMessage.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package io.iohk.atala.prism.walletsdk.mercury.forward
import io.iohk.atala.prism.walletsdk.domain.models.AttachmentDescriptor
import io.iohk.atala.prism.walletsdk.domain.models.AttachmentJsonData
import io.iohk.atala.prism.walletsdk.domain.models.DID
import io.iohk.atala.prism.walletsdk.domain.models.Message
import io.ktor.http.ContentType
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.util.UUID
class ForwardMessage @JvmOverloads constructor(
val body: ForwardBody,
val from: DID,
val to: DID,
val encryptedMessage: String,
val id: String = UUID.randomUUID().toString()
) {
fun makeMessage(): Message {
val forwardBody = Json.encodeToString(body)
val attachmentData = AttachmentJsonData(encryptedMessage)
val attachment = AttachmentDescriptor(UUID.randomUUID().toString(), ContentType.Application.Json.toString(), attachmentData)
val message = Message(
id = id,
piuri = type,
from = from,
to = to,
body = forwardBody,
attachments = arrayOf(attachment)
)
return message
}
@Serializable
data class ForwardBody(val next: String)
companion object {
const val type = "https://didcomm.org/routing/2.0/forward"
}
}