Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update did peer library version #128

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.iohk.atala.prism.apollo.hashing.internal.toHexString
import io.iohk.atala.prism.didcomm.didpeer.DIDCommServicePeerDID
import io.iohk.atala.prism.didcomm.didpeer.DIDDocPeerDID
import io.iohk.atala.prism.didcomm.didpeer.MalformedPeerDIDException
import io.iohk.atala.prism.didcomm.didpeer.ServiceEndpoint
import io.iohk.atala.prism.didcomm.didpeer.VerificationMaterialAgreement
import io.iohk.atala.prism.didcomm.didpeer.VerificationMaterialAuthentication
import io.iohk.atala.prism.didcomm.didpeer.VerificationMaterialFormatPeerDID
Expand Down Expand Up @@ -198,9 +199,9 @@ internal class CastorShared {
id = service.id,
type = arrayOf(service.type),
serviceEndpoint = DIDDocument.ServiceEndpoint(
uri = service.serviceEndpoint,
accept = service.accept.toTypedArray(),
routingKeys = service.routingKeys.toTypedArray()
uri = service.serviceEndpoint.uri,
accept = service.serviceEndpoint.accept.toTypedArray(),
routingKeys = service.serviceEndpoint.routingKeys.toTypedArray()
)
)
)
Expand Down Expand Up @@ -553,13 +554,17 @@ internal class CastorShared {
encryptionKeys = encryptionKeys,
signingKeys = signingKeys,
service = services.map {
val serviceEndpoint = ServiceEndpoint(
uri = it.serviceEndpoint.uri,
routingKeys = it.serviceEndpoint.routingKeys?.toList() ?: listOf(),
accept = it.serviceEndpoint.accept?.asList() ?: listOf()
)

Json.encodeToString(
DIDCommServicePeerDID(
id = it.id,
type = it.type[0],
serviceEndpoint = it.serviceEndpoint.uri,
routingKeys = it.serviceEndpoint.routingKeys?.toList() ?: listOf(),
accept = it.serviceEndpoint.accept?.asList() ?: listOf()
serviceEndpoint = serviceEndpoint
).toDict().toJsonElement()
)
}.firstOrNull()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package io.iohk.atala.prism.walletsdk.castor

import io.iohk.atala.prism.apollo.base64.base64UrlDecodedBytes
import io.iohk.atala.prism.walletsdk.apollo.ApolloImpl
import io.iohk.atala.prism.walletsdk.apollo.utils.Ed25519KeyPair
import io.iohk.atala.prism.walletsdk.apollo.utils.Ed25519PrivateKey
import io.iohk.atala.prism.walletsdk.apollo.utils.Ed25519PublicKey
import io.iohk.atala.prism.walletsdk.apollo.utils.X25519KeyPair
import io.iohk.atala.prism.walletsdk.apollo.utils.X25519PrivateKey
import io.iohk.atala.prism.walletsdk.apollo.utils.X25519PublicKey
import io.iohk.atala.prism.walletsdk.domain.models.CastorError
import io.iohk.atala.prism.walletsdk.domain.models.Curve
import io.iohk.atala.prism.walletsdk.domain.models.DIDDocument
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.CurveKey
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.KeyPair
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.KeyTypes
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.RawKey
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.TypeKey
import io.iohk.atala.prism.walletsdk.prismagent.DIDCOMM_MESSAGING
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
Expand All @@ -22,23 +29,207 @@ class DIDCreateTest {
@Test
fun it_should_create_peerDID_correctly() = runTest {
val keyAgreementKeyPair = X25519KeyPair(
X25519PrivateKey(byteArrayOf(-24, 18, -94, -98, 106, 49, -55, -55, -6, -66, 75, 73, -120, -96, 33, 28, -55, -109, 105, -67, 9, 28, 88, -98, 43, -4, -6, 75, 65, -68, 112, 92)),
X25519PublicKey(byteArrayOf(-16, 16, 107, -82, -125, 83, 101, -94, -103, -112, 47, 117, -90, -100, 64, 77, 62, -4, 11, 101, -53, -64, -2, -77, -106, -16, -63, -54, -42, -59, 80, 23))
X25519PrivateKey(
byteArrayOf(
-24,
18,
-94,
-98,
106,
49,
-55,
-55,
-6,
-66,
75,
73,
-120,
-96,
33,
28,
-55,
-109,
105,
-67,
9,
28,
88,
-98,
43,
-4,
-6,
75,
65,
-68,
112,
92
)
),
X25519PublicKey(
byteArrayOf(
-16,
16,
107,
-82,
-125,
83,
101,
-94,
-103,
-112,
47,
117,
-90,
-100,
64,
77,
62,
-4,
11,
101,
-53,
-64,
-2,
-77,
-106,
-16,
-63,
-54,
-42,
-59,
80,
23
)
)
)

val authenticationKeyPair = Ed25519KeyPair(
Ed25519PrivateKey(byteArrayOf(-68, 7, 65, -41, -60, -42, -9, 55, -113, -80, -86, -106, -40, 97, 81, -13, -22, -124, -58, -39, -64, -126, 75, 88, 126, 39, 51, -52, 121, -64, -5, 35)),
Ed25519PublicKey(byteArrayOf(-8, 10, 34, 65, -42, -19, -92, 1, -48, -59, -10, -99, -8, -88, -32, 119, 50, -15, -93, 56, -121, -51, 78, -93, 42, -86, -37, 20, 34, -94, 108, -68))
Ed25519PrivateKey(
byteArrayOf(
-68,
7,
65,
-41,
-60,
-42,
-9,
55,
-113,
-80,
-86,
-106,
-40,
97,
81,
-13,
-22,
-124,
-58,
-39,
-64,
-126,
75,
88,
126,
39,
51,
-52,
121,
-64,
-5,
35
)
),
Ed25519PublicKey(
byteArrayOf(
-8,
10,
34,
65,
-42,
-19,
-92,
1,
-48,
-59,
-10,
-99,
-8,
-88,
-32,
119,
50,
-15,
-93,
56,
-121,
-51,
78,
-93,
42,
-86,
-37,
20,
34,
-94,
108,
-68
)
)
)

val keyPairs: Array<KeyPair> = arrayOf(keyAgreementKeyPair, authenticationKeyPair)

val castor = CastorImpl(ApolloMock())
val did = castor.createPeerDID(keyPairs, emptyArray())
val validPeerDID = "did:peer:2.Ez6LSsqHXypzFPGA7RdCu2NHUf2cK8dAW1AdHa5JDCRnXQ2yk.Vz6Mkw9W7jaqZ7hF5bSKeSpnqNxhFTiVMy3aBZjyEhrMxUQAF"
val validPeerDID =
"did:peer:2.Ez6LSsqHXypzFPGA7RdCu2NHUf2cK8dAW1AdHa5JDCRnXQ2yk.Vz6Mkw9W7jaqZ7hF5bSKeSpnqNxhFTiVMy3aBZjyEhrMxUQAF"
assertEquals(validPeerDID, did.toString())
}

@Test
fun testPeerDIDCreation_whenServicesProvided_thenCreatedCorrectly() = runTest {
val apollo = ApolloImpl()

val properties: MutableMap<String, Any> = mutableMapOf()
properties[TypeKey().property] = KeyTypes.Curve25519
properties[RawKey().property] = "COd9Xhr-amD7fuswWId2706JBUY_tmjp9eiNEieJeEE".base64UrlDecodedBytes
properties[CurveKey().property] = Curve.X25519.value
val keyAgreementPrivateKey = apollo.createPrivateKey(properties)
val keyAgreementKeyPair = X25519KeyPair(
privateKey = keyAgreementPrivateKey,
publicKey = keyAgreementPrivateKey.publicKey()
)

val properties2: MutableMap<String, Any> = mutableMapOf()
properties2[TypeKey().property] = KeyTypes.EC
properties2[RawKey().property] = "JLIJQ5jlkyqtGmtOth6yggJLLC0zuRhUPiBhd1-rGPs".base64UrlDecodedBytes
properties2[CurveKey().property] = Curve.ED25519.value
val authenticationPrivateKey = apollo.createPrivateKey(properties2)
val authenticationKeyPair = Ed25519KeyPair(
privateKey = authenticationPrivateKey,
publicKey = authenticationPrivateKey.publicKey()
)

val keyPairs: Array<KeyPair> = arrayOf(keyAgreementKeyPair, authenticationKeyPair)

val service = DIDDocument.Service(
id = "didcomm",
type = arrayOf(DIDCOMM_MESSAGING),
serviceEndpoint = DIDDocument.ServiceEndpoint(
uri = "https://example.com/endpoint",
accept = emptyArray(),
routingKeys = arrayOf("did:example:somemediator#somekey")
)
)

val castor = CastorImpl(apollo)
val did = castor.createPeerDID(keyPairs, arrayOf(service))
val expectedPeerDID =
"did:peer:2.Ez6LSoHkfN1Y4nK9RCjx7vopWsLrMGNFNgTNZgoCNQrTzmb1n.Vz6MknRZmapV7uYZQuZez9n9N3tQotjRN18UGS68Vcfo6gR4h.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6Imh0dHBzOi8vZXhhbXBsZS5jb20vZW5kcG9pbnQiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5Il0sImEiOltdfX0"
assertEquals(expectedPeerDID, did.toString())
}

@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun it_should_throw_errors_if_wrong_keys_are_provided() = runTest {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android.useAndroidX = true
kotlin.mpp.enableCInteropCommonization = true
kotlin.native.cacheKind.iosSimulatorArm64 = none
apollo_version = 1.0.15
didpeer_version = 1.0.5-alpha
didpeer_version = 1.1.1
kotlin.mpp.androidSourceSetLayoutVersion = 2
kotlinx.atomicfu.enableJvmIrTransformation = true
kotlinx.atomicfu.enableJsIrTransformation = true
Loading