diff --git a/build.gradle.kts b/build.gradle.kts index 32da3930..ef7d06c7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -46,9 +46,16 @@ subprojects { config.setFrom("$rootDir/config/detekt.yml") } + kotlin { + jvmToolchain(17) + } + java { withJavadocJar() withSourcesJar() + + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } publishing { diff --git a/httpclient/build.gradle.kts b/httpclient/build.gradle.kts index 7240fd0f..ab97040d 100644 --- a/httpclient/build.gradle.kts +++ b/httpclient/build.gradle.kts @@ -3,8 +3,6 @@ plugins { id("java-library") } -version = "1.0" - repositories { mavenCentral() maven { @@ -22,7 +20,7 @@ dependencies { implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.2") implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.8") implementation("com.fasterxml.jackson.core:jackson-databind:2.15.2") - implementation("com.github.TBD54566975:web5-kt:0.0.4-beta") + implementation("com.github.TBD54566975:web5-kt:0.0.5-beta") implementation("decentralized-identity:did-common-java:1.9.0") // would like to grab this via web5 dids testImplementation(kotlin("test")) diff --git a/httpserver/build.gradle.kts b/httpserver/build.gradle.kts index 025b9e99..f3583d53 100644 --- a/httpserver/build.gradle.kts +++ b/httpserver/build.gradle.kts @@ -4,7 +4,6 @@ plugins { id("idea") } -version = "1.0" var ktorVersion = "2.3.4" repositories { diff --git a/httpserver/src/main/kotlin/tbdex/sdk/httpserver/Server.kt b/httpserver/src/main/kotlin/tbdex/sdk/httpserver/Server.kt index 8578e113..58eb81d6 100644 --- a/httpserver/src/main/kotlin/tbdex/sdk/httpserver/Server.kt +++ b/httpserver/src/main/kotlin/tbdex/sdk/httpserver/Server.kt @@ -1,4 +1,4 @@ -package tbdex.server.tbdex.sdk.http_server +package tbdex.sdk.httpserver import io.ktor.http.HttpStatusCode import io.ktor.server.application.Application diff --git a/httpserver/src/test/kotlin/tbdex/sdk/httpserver/ServerTest.kt b/httpserver/src/test/kotlin/tbdex/sdk/httpserver/ServerTest.kt index 209be988..223b1651 100644 --- a/httpserver/src/test/kotlin/tbdex/sdk/httpserver/ServerTest.kt +++ b/httpserver/src/test/kotlin/tbdex/sdk/httpserver/ServerTest.kt @@ -6,7 +6,6 @@ import io.ktor.server.application.Application import io.ktor.server.testing.handleRequest import io.ktor.server.testing.withTestApplication import org.junit.jupiter.api.Test -import tbdex.server.tbdex.sdk.http_server.module import kotlin.test.assertEquals class ServerTest { diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 00000000..1e41e00b --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,2 @@ +jdk: + - openjdk17 \ No newline at end of file diff --git a/protocol/build.gradle.kts b/protocol/build.gradle.kts index d911a3da..5e9c1007 100644 --- a/protocol/build.gradle.kts +++ b/protocol/build.gradle.kts @@ -3,8 +3,6 @@ plugins { id("java-library") } -version = "1.0" - repositories { mavenCentral() maven { @@ -16,11 +14,12 @@ repositories { } dependencies { - implementation("me.lessis:typeid:0.0.2") + api("me.lessis:typeid:0.0.2") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.2") implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.8") implementation("com.fasterxml.jackson.datatype:jackson-datatype-json-org:2.11.0") - implementation("com.github.TBD54566975:web5-kt:0.0.4-beta") + implementation("com.github.TBD54566975:web5-kt:0.0.5-beta") implementation("com.networknt:json-schema-validator:1.0.87") implementation("com.nimbusds:nimbus-jose-jwt:9.36") implementation("decentralized-identity:did-common-java:1.9.0") diff --git a/protocol/src/main/kotlin/tbdex/sdk/protocol/CryptoUtils.kt b/protocol/src/main/kotlin/tbdex/sdk/protocol/CryptoUtils.kt index 41ab3392..a640c16a 100644 --- a/protocol/src/main/kotlin/tbdex/sdk/protocol/CryptoUtils.kt +++ b/protocol/src/main/kotlin/tbdex/sdk/protocol/CryptoUtils.kt @@ -51,7 +51,7 @@ object CryptoUtils { // or just `#fragment`. See: https://www.w3.org/TR/did-core/#relative-did-urls. // Using a set for fast string comparison. DIDs can be long. val verificationMethodIds = setOf(parsedDidUrl.didUrlString, "#${parsedDidUrl.fragment}") - val assertionMethods = didResolutionResult.didDocument.assertionMethodVerificationMethodsDereferenced + val assertionMethods = didResolutionResult.didDocument.assertionMethodVerificationMethodsDereferenced ?: emptyList() var assertionMethod: VerificationMethod? = null for (method in assertionMethods) { diff --git a/protocol/src/main/kotlin/tbdex/sdk/protocol/models/Message.kt b/protocol/src/main/kotlin/tbdex/sdk/protocol/models/Message.kt index c73e6787..54815ca4 100644 --- a/protocol/src/main/kotlin/tbdex/sdk/protocol/models/Message.kt +++ b/protocol/src/main/kotlin/tbdex/sdk/protocol/models/Message.kt @@ -11,6 +11,7 @@ import tbdex.sdk.protocol.serialization.Json.jsonMapper import tbdex.sdk.protocol.serialization.dateTimeFormat import typeid.TypeID import web5.sdk.dids.Did +import java.security.MessageDigest import java.time.OffsetDateTime /** @@ -75,7 +76,8 @@ sealed class Message { val payload = mapOf("metadata" to this.metadata, "data" to this.data) val canonicalJsonSerializedPayload = JsonCanonicalizer(Json.stringify(payload)) - return canonicalJsonSerializedPayload.encodedUTF8 + val sha256 = MessageDigest.getInstance("SHA-256") + return sha256.digest(canonicalJsonSerializedPayload.encodedUTF8) } /** diff --git a/protocol/src/main/kotlin/tbdex/sdk/protocol/models/Resource.kt b/protocol/src/main/kotlin/tbdex/sdk/protocol/models/Resource.kt index b4f5f0a3..91851453 100644 --- a/protocol/src/main/kotlin/tbdex/sdk/protocol/models/Resource.kt +++ b/protocol/src/main/kotlin/tbdex/sdk/protocol/models/Resource.kt @@ -11,6 +11,7 @@ import tbdex.sdk.protocol.serialization.Json.jsonMapper import tbdex.sdk.protocol.serialization.dateTimeFormat import typeid.TypeID import web5.sdk.dids.Did +import java.security.MessageDigest import java.time.OffsetDateTime /** @@ -73,7 +74,8 @@ sealed class Resource { val payload = mapOf("metadata" to this.metadata, "data" to this.data) val canonicalJsonSerializedPayload = JsonCanonicalizer(Json.stringify(payload)) - return canonicalJsonSerializedPayload.encodedUTF8 + val sha256 = MessageDigest.getInstance("SHA-256") + return sha256.digest(canonicalJsonSerializedPayload.encodedUTF8) } /** diff --git a/protocol/src/test/resources/testVectors.json b/protocol/src/test/resources/testVectors.json index e01d85c7..906bfa2a 100644 --- a/protocol/src/test/resources/testVectors.json +++ b/protocol/src/test/resources/testVectors.json @@ -3,10 +3,10 @@ "offering": { "metadata": { "kind": "offering", - "from": "did:key:zQ3shYHEKhVFvDDvAEmyCTPB3kRkHZdD8QCbykAPpopj5ng4u", - "id": "offering_7zzzzzzwzyf678004shr000zqf", - "createdAt": "2023-10-20T19:28:09.594Z", - "updatedAt": "2023-10-20T19:28:09.594Z" + "from": "did:key:zQ3shhwZ18aebLvYzCDdkkUH78z6RXec843BQc9hybsMRSoxg", + "id": "offering_01hdh7fyftfkv8002wyr000nj5", + "createdAt": "2023-10-24T16:15:03.662Z", + "updatedAt": "2023-10-24T16:15:03.662Z" }, "data": { "description": "A sample offering", @@ -85,7 +85,7 @@ "id": "test-pd-id", "name": "simple PD", "purpose": "pd for testing", - "inputDescriptors": [ + "input_descriptors": [ { "id": "whatever", "purpose": "id for testing", @@ -102,21 +102,21 @@ ] } }, - "signature": "eyJraWQiOiJkaWQ6a2V5OnpRM3NoWUhFS2hWRnZERHZBRW15Q1RQQjNrUmtIWmREOFFDYnlrQVBwb3BqNW5nNHUjelEzc2hZSEVLaFZGdkREdkFFbXlDVFBCM2tSa0haZEQ4UUNieWtBUHBvcGo1bmc0dSIsImFsZyI6IkVTMjU2SyJ9..52s8dGKKDW7-8_qo4Mp1aAtvT6v6r7yQEJY6P8Xo-etFClntFm0031Wyl8a76mS6Wiq_0Zr84_6lAUBYo-rVNw" + "signature": "eyJraWQiOiJkaWQ6a2V5OnpRM3NoaHdaMThhZWJMdll6Q0Rka2tVSDc4ejZSWGVjODQzQlFjOWh5YnNNUlNveGcjelEzc2hod1oxOGFlYkx2WXpDRGRra1VINzh6NlJYZWM4NDNCUWM5aHlic01SU294ZyIsImFsZyI6IkVTMjU2SyJ9..MyaMT4LZAlkLj4w9LZMqQLsaklhHlsrob60p1XmKMKg249kweyXPGABpEnvKD_65_1s1RjdyKlEotgQT15xAYw" } }, "messages": { "rfq": { "metadata": { "kind": "rfq", - "to": "did:key:zQ3shYHEKhVFvDDvAEmyCTPB3kRkHZdD8QCbykAPpopj5ng4u", - "from": "did:key:zQ3shizeS6VFzTasyXFXcLgYaiLN5yK5PQe9v37VYy9yQzXQq", - "id": "rfq_7zzzzzzzqke7nr003hxc001mey", - "exchangeId": "rfq_7zzzzzzzqke7nr003hxc001mey", - "createdAt": "2023-10-20T19:28:09.969Z" + "to": "did:key:zQ3shhwZ18aebLvYzCDdkkUH78z6RXec843BQc9hybsMRSoxg", + "from": "did:key:zQ3shizfQYEiB8dqac96P6SHYtUCCsY7gSci4Qeaebgsfz1VC", + "id": "rfq_7zzzzzzyzte028007g0g001xdc", + "exchangeId": "rfq_7zzzzzzyzte028007g0g001xdc", + "createdAt": "2023-10-24T16:15:04.010Z" }, "data": { - "offeringId": "offering_7zzzzzzx7yff7r002bsw001f3s", + "offeringId": "offering_01hdh7fyzzek48003ms0001bv2", "payinSubunits": "1000", "payinMethod": { "kind": "BTC_ADDRESS", @@ -135,19 +135,19 @@ "presentation submission" ] }, - "signature": "eyJraWQiOiJkaWQ6a2V5OnpRM3NoaXplUzZWRnpUYXN5WEZYY0xnWWFpTE41eUs1UFFlOXYzN1ZZeTl5UXpYUXEjelEzc2hpemVTNlZGelRhc3lYRlhjTGdZYWlMTjV5SzVQUWU5djM3Vll5OXlRelhRcSIsImFsZyI6IkVTMjU2SyJ9.._lWN41pV9Vi9emli0c6ZyYq-D1Jvx6padYxnb9Zneh1aXgCAracsCf_ehemi7OLK5GaV0Kp0JX688DQp1SUe-A" + "signature": "eyJraWQiOiJkaWQ6a2V5OnpRM3NoaXpmUVlFaUI4ZHFhYzk2UDZTSFl0VUNDc1k3Z1NjaTRRZWFlYmdzZnoxVkMjelEzc2hpemZRWUVpQjhkcWFjOTZQNlNIWXRVQ0NzWTdnU2NpNFFlYWViZ3NmejFWQyIsImFsZyI6IkVTMjU2SyJ9..Y9gKs87CGalvHxlChHsL2fx2wtlPbY2-tBDciz7rSKRJkWmeIdyu-7NxwUdVMlQfJ58PTLoYPknXUKL8Hc0v4w" }, "quote": { "metadata": { "kind": "quote", - "to": "did:key:zQ3shizeS6VFzTasyXFXcLgYaiLN5yK5PQe9v37VYy9yQzXQq", - "from": "did:key:zQ3shYHEKhVFvDDvAEmyCTPB3kRkHZdD8QCbykAPpopj5ng4u", - "id": "quote_7zzzzzzz7zfj1r006cgc000c6d", - "exchangeId": "rfq_7zzzzzzd7zfwzr006f7w000tbk", - "createdAt": "2023-10-20T19:28:09.981Z" + "to": "did:key:zQ3shizfQYEiB8dqac96P6SHYtUCCsY7gSci4Qeaebgsfz1VC", + "from": "did:key:zQ3shhwZ18aebLvYzCDdkkUH78z6RXec843BQc9hybsMRSoxg", + "id": "quote_7zzzzzzpyrfy2r004fgm0013c7", + "exchangeId": "rfq_7zzzzzzzztfxx8001ff8000ex2", + "createdAt": "2023-10-24T16:15:04.024Z" }, "data": { - "expiresAt": "2023-10-21T19:28:09.981Z", + "expiresAt": "2023-10-25T16:15:04.024Z", "payin": { "currencyCode": "AUD", "amountSubunits": "1000", @@ -169,47 +169,47 @@ } } }, - "signature": "eyJraWQiOiJkaWQ6a2V5OnpRM3NoWUhFS2hWRnZERHZBRW15Q1RQQjNrUmtIWmREOFFDYnlrQVBwb3BqNW5nNHUjelEzc2hZSEVLaFZGdkREdkFFbXlDVFBCM2tSa0haZEQ4UUNieWtBUHBvcGo1bmc0dSIsImFsZyI6IkVTMjU2SyJ9..gl6vcasltpykqtIavynximjLKq41qPqlbZYmtg0AKu8OfTqOZvdjzmCzjMNMs8D6baZrSEfuyVLRq0medNA7CQ" + "signature": "eyJraWQiOiJkaWQ6a2V5OnpRM3NoaHdaMThhZWJMdll6Q0Rka2tVSDc4ejZSWGVjODQzQlFjOWh5YnNNUlNveGcjelEzc2hod1oxOGFlYkx2WXpDRGRra1VINzh6NlJYZWM4NDNCUWM5aHlic01SU294ZyIsImFsZyI6IkVTMjU2SyJ9..B2n8TL3Tk_Bq0uf8l-1IIj_p44fuLghihElbrF493N1b1TqexdHqkhUuevdh5DKsTi3DgiQyHd8Vijwnz6Ap_A" }, "order": { "metadata": { "kind": "order", - "to": "did:key:zQ3shYHEKhVFvDDvAEmyCTPB3kRkHZdD8QCbykAPpopj5ng4u", - "from": "did:key:zQ3shizeS6VFzTasyXFXcLgYaiLN5yK5PQe9v37VYy9yQzXQq", - "id": "order_7zzzzzzf9pf478000s1r00130t", - "exchangeId": "rfq_01hd78yxvcf71r0029rc001xcz", - "createdAt": "2023-10-20T19:28:09.988Z" + "to": "did:key:zQ3shhwZ18aebLvYzCDdkkUH78z6RXec843BQc9hybsMRSoxg", + "from": "did:key:zQ3shizfQYEiB8dqac96P6SHYtUCCsY7gSci4Qeaebgsfz1VC", + "id": "order_01hdh7fpzjeh980014a8000t9d", + "exchangeId": "rfq_7zzzzzzqvhffw8002vz0000mwp", + "createdAt": "2023-10-24T16:15:04.032Z" }, "data": {}, - "signature": "eyJraWQiOiJkaWQ6a2V5OnpRM3NoaXplUzZWRnpUYXN5WEZYY0xnWWFpTE41eUs1UFFlOXYzN1ZZeTl5UXpYUXEjelEzc2hpemVTNlZGelRhc3lYRlhjTGdZYWlMTjV5SzVQUWU5djM3Vll5OXlRelhRcSIsImFsZyI6IkVTMjU2SyJ9..pgQBsE39vG93VjmwHNzRzFc9OiXgOBhKIOorulVtuPhj9k-Ck4-k9naUtCIjR0MuQYeSbwOmtrGGKwJ-4EGjRw" + "signature": "eyJraWQiOiJkaWQ6a2V5OnpRM3NoaXpmUVlFaUI4ZHFhYzk2UDZTSFl0VUNDc1k3Z1NjaTRRZWFlYmdzZnoxVkMjelEzc2hpemZRWUVpQjhkcWFjOTZQNlNIWXRVQ0NzWTdnU2NpNFFlYWViZ3NmejFWQyIsImFsZyI6IkVTMjU2SyJ9..FLzrqCirBzDFix3AuIpv-1FtGSUNq7v6ckUQjzrGc5JLDSggS8P-MdVJ1gW5SVCusZCRhkjk6UX4qQXSFZ4X8w" }, "orderStatus": { "metadata": { "kind": "orderstatus", - "to": "did:key:zQ3shizeS6VFzTasyXFXcLgYaiLN5yK5PQe9v37VYy9yQzXQq", - "from": "did:key:zQ3shYHEKhVFvDDvAEmyCTPB3kRkHZdD8QCbykAPpopj5ng4u", - "id": "orderstatus_01hd78yz9ffv28003yrg001kwm", - "exchangeId": "rfq_7zzzzzzzfqe6zr002hqw00001x", - "createdAt": "2023-10-20T19:28:09.991Z" + "to": "did:key:zQ3shizfQYEiB8dqac96P6SHYtUCCsY7gSci4Qeaebgsfz1VC", + "from": "did:key:zQ3shhwZ18aebLvYzCDdkkUH78z6RXec843BQc9hybsMRSoxg", + "id": "orderstatus_01hdh7fzvffj3r005wgw000ac4", + "exchangeId": "rfq_01hdh7fqvzesf8002pbr001x7t", + "createdAt": "2023-10-24T16:15:04.034Z" }, "data": { "orderStatus": "PENDING" }, - "signature": "eyJraWQiOiJkaWQ6a2V5OnpRM3NoWUhFS2hWRnZERHZBRW15Q1RQQjNrUmtIWmREOFFDYnlrQVBwb3BqNW5nNHUjelEzc2hZSEVLaFZGdkREdkFFbXlDVFBCM2tSa0haZEQ4UUNieWtBUHBvcGo1bmc0dSIsImFsZyI6IkVTMjU2SyJ9..3zkNi8q9m7bfLoZhMxl-6FluTX16u86jEiro7O_SQJ0ovS0SmX4YRuR7_n7Zn85xF-IhzpM16jMIJj82fz9Tbw" + "signature": "eyJraWQiOiJkaWQ6a2V5OnpRM3NoaHdaMThhZWJMdll6Q0Rka2tVSDc4ejZSWGVjODQzQlFjOWh5YnNNUlNveGcjelEzc2hod1oxOGFlYkx2WXpDRGRra1VINzh6NlJYZWM4NDNCUWM5aHlic01SU294ZyIsImFsZyI6IkVTMjU2SyJ9..dSZEztUIOWMfb8fLuJSL5A9DblEH7ROszTUztv1b-21dgKEZMCZCAPeju2MEEIObtv7SKvWopenL7IqtP2RpVQ" }, "close": { "metadata": { "kind": "close", - "to": "did:key:zQ3shizeS6VFzTasyXFXcLgYaiLN5yK5PQe9v37VYy9yQzXQq", - "from": "did:key:zQ3shYHEKhVFvDDvAEmyCTPB3kRkHZdD8QCbykAPpopj5ng4u", - "id": "close_01hd78yfsfe2hr0050mc000034", - "exchangeId": "rfq_7zzzzzzfwzf1yr0078fm0012xm", - "createdAt": "2023-10-20T19:28:09.994Z" + "to": "did:key:zQ3shizfQYEiB8dqac96P6SHYtUCCsY7gSci4Qeaebgsfz1VC", + "from": "did:key:zQ3shhwZ18aebLvYzCDdkkUH78z6RXec843BQc9hybsMRSoxg", + "id": "close_7zzzzzzpvqf2480048h0001jm6", + "exchangeId": "rfq_01hdh7fqvpevq8003pxr001a45", + "createdAt": "2023-10-24T16:15:04.037Z" }, "data": { "reason": "test reason" }, - "signature": "eyJraWQiOiJkaWQ6a2V5OnpRM3NoWUhFS2hWRnZERHZBRW15Q1RQQjNrUmtIWmREOFFDYnlrQVBwb3BqNW5nNHUjelEzc2hZSEVLaFZGdkREdkFFbXlDVFBCM2tSa0haZEQ4UUNieWtBUHBvcGo1bmc0dSIsImFsZyI6IkVTMjU2SyJ9..zmfbOmR5qEpywemsDFQ4VOqJHtkLYHhFvpexNNVDm880TFik_df24bh8387GSy-U3WeRWEDDYMZ0k0k4KzyViA" + "signature": "eyJraWQiOiJkaWQ6a2V5OnpRM3NoaHdaMThhZWJMdll6Q0Rka2tVSDc4ejZSWGVjODQzQlFjOWh5YnNNUlNveGcjelEzc2hod1oxOGFlYkx2WXpDRGRra1VINzh6NlJYZWM4NDNCUWM5aHlic01SU294ZyIsImFsZyI6IkVTMjU2SyJ9..TDtaxXdl1Bljuft8bZlvxTXTK472fKOia12kG_mQA7UhGTVIfwO9cuDCS_86EZHPMhkAvYdOnIiUodouZVba_A" } } } \ No newline at end of file