-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#6] Out of band didcomm message encoding
- Loading branch information
Showing
36 changed files
with
1,246 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 0 additions & 102 deletions
102
core/src/main/kotlin/org/nessus/didcomm/aries/AriesAgent.kt
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
core/src/main/kotlin/org/nessus/didcomm/model/MessageParser.kt
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
core/src/main/kotlin/org/nessus/didcomm/model/MessageReader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.nessus.didcomm.model | ||
|
||
import com.google.gson.Gson | ||
import org.didcommx.didcomm.message.Message | ||
|
||
/** | ||
* Parses a JSON string to a DIDComm Message | ||
*/ | ||
object MessageReader { | ||
|
||
private val gson = Gson() | ||
|
||
fun fromJson(json: String) : Message { | ||
val jsonMap: MutableMap<String, Any> = mutableMapOf() | ||
gson.fromJson(json, Map::class.java).forEach { en -> | ||
val enval = en.value!! | ||
when(val key: String = en.key.toString()) { | ||
"created_time" -> jsonMap[key] = (enval as Double).toLong() | ||
"expires_time" -> jsonMap[key] = (enval as Double).toLong() | ||
"custom_headers" -> if (enval is Map<*, *> && enval.isNotEmpty()) { | ||
jsonMap[key] = enval | ||
} | ||
else -> jsonMap[key] = enval | ||
} | ||
} | ||
return Message.parse(jsonMap) | ||
} | ||
|
||
fun <T> fromJson(json: String, type: Class<T>) : T { | ||
return gson.fromJson(json, type) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
core/src/main/kotlin/org/nessus/didcomm/model/MessageType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.nessus.didcomm.model | ||
|
||
abstract class MessageType ( | ||
|
||
/** | ||
* The header conveying the DIDComm Message Type URI. | ||
* REQUIRED | ||
*/ | ||
val type: String | ||
) { | ||
companion object { | ||
const val OUT_OF_BAND_INVITATION = "https://didcomm.org/out-of-band/2.0/invitation" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
core/src/main/kotlin/org/nessus/didcomm/service/AgentService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.nessus.didcomm.service | ||
|
||
import org.didcommx.didcomm.message.Message | ||
import org.nessus.didcomm.wallet.NessusWallet | ||
|
||
/** | ||
* An Agent can create, send, receive DIDComMessages | ||
*/ | ||
interface AgentService : Service { | ||
|
||
companion object { | ||
val type: Class<AgentService> = AgentService::class.java | ||
} | ||
|
||
override val type: Class<AgentService> | ||
get() = Companion.type | ||
|
||
fun createMessage(wallet: NessusWallet, type: String, body: Map<String, Any> = mapOf()) : Message | ||
} |
20 changes: 20 additions & 0 deletions
20
core/src/main/kotlin/org/nessus/didcomm/service/ServiceRegistry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.nessus.didcomm.service | ||
|
||
// [TODO] document all services | ||
interface Service { | ||
val type: Class<out Service> | ||
} | ||
|
||
// [TODO] document ServiceRegistry | ||
object ServiceRegistry { | ||
|
||
private val registry : MutableMap<String, Service> = mutableMapOf() | ||
|
||
fun <T : Service> getService(type : Class<T>) : T { | ||
return registry[type.name] as T | ||
} | ||
|
||
fun <T : Service> addService(service: T) { | ||
registry[service.type.name] = service | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
core/src/main/kotlin/org/nessus/didcomm/service/WalletService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.nessus.didcomm.service | ||
|
||
import org.nessus.didcomm.wallet.NessusWallet | ||
import org.nessus.didcomm.wallet.WalletException | ||
import org.nessus.didcomm.wallet.WalletRegistry | ||
|
||
interface WalletService : Service { | ||
|
||
companion object { | ||
val type: Class<WalletService> = WalletService::class.java | ||
val registry = WalletRegistry() | ||
} | ||
|
||
override val type: Class<WalletService> | ||
get() = Companion.type | ||
|
||
fun assertConfigValue(config: Map<String, Any?>, key: String) : Any { | ||
return config[key] ?: throw WalletException("No config value for: $key") | ||
} | ||
|
||
fun getConfigValue(config: Map<String, Any?>, key: String) : Any? { | ||
return config[key] | ||
} | ||
|
||
fun hasConfigValue(config: Map<String, Any?>, key: String) : Boolean { | ||
return config[key] != null | ||
} | ||
|
||
fun createWallet(config: Map<String, Any?>): NessusWallet | ||
|
||
fun publicDid(wallet: NessusWallet): String? | ||
|
||
fun closeAndRemove(wallet: NessusWallet?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.