Files
amethyst/contextvm/build.gradle.kts
T
Claude a9a883cb66 feat(contextvm): add the module skeleton, wire constants and JSON-RPC codec
First increment of Stage 2a from quartz/plans/2026-09-17-cordn-interop.md:
build item 1 (constants, tags, JSON-RPC 2.0 codec) plus the kind 25910
envelope. Written from the ContextVM specification documents, not from the
LGPL-3.0 SDK, per the plan's clean-room rule.

- :contextvm is a KMP module (jvm + android host tests) mirroring :quic, with
  quartz as an api dependency. It takes its own kotlinx-serialization-json
  because quartz keeps that dependency `implementation`.
- CvmKinds/CvmTags carry the wire vocabulary: kind 25910, gift wraps 1059 and
  21059, announcements 11316-11320, NIP-65 10002, and the capability,
  discovery, pricing and NIP-73 tag names from the CEPs.
- JsonRpcCodec models JSON-RPC 2.0 with params/result left as a JSON tree,
  since ContextVM transports MCP unmodified. Ids keep their string-vs-number
  distinction instead of normalising, so decode/encode is a faithful round
  trip and CEP-8's canonical-identity rule stays expressible later.
- Decoding is strict: wrong version, result and error together, a method
  beside a response body, a success without an id, non-object params and a
  fractional id are all rejected rather than coerced.
- CvmMessageEvent maps the envelope, keeping content a stringified JSON-RPC
  message (the spec prints it unstringified for readability, which is the
  trap) and excluding routing tags from the CEP-35 discovery surface while
  preserving unknown ones.

29 tests, named for the CVM-CORE rule ids in the plan's §6.5 catalog so a
spec revision points at the failures. Verified by mutation: disabling the
version check and normalising ids to text turns 10 of them red. :quartz
jvmTest stays green at 5054 tests.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012BfD4txdnsaPRXmNXbup9n
2026-09-18 01:22:51 +00:00

106 lines
3.2 KiB
Kotlin

/*
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidKotlinMultiplatformLibrary)
alias(libs.plugins.serialization)
}
kotlin {
jvm {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_21)
}
}
android {
namespace = "com.vitorpamplona.contextvm"
compileSdk =
libs.versions.android.compileSdk
.get()
.toInt()
minSdk =
libs.versions.android.minSdk
.get()
.toInt()
compilerOptions {
jvmTarget.set(JvmTarget.JVM_21)
}
withHostTest {}
}
sourceSets {
commonMain {
dependencies {
implementation(libs.kotlin.stdlib)
implementation(libs.kotlinx.coroutines.core)
// The JSON-RPC layer works on a JSON tree: MCP `params`/`result` are
// arbitrary and pass through us untouched. quartz keeps its own
// serialization dep `implementation`, so it is not transitive here.
implementation(libs.kotlinx.serialization.json)
api(project(":quartz"))
}
}
commonTest {
dependencies {
implementation(libs.kotlin.test)
implementation(libs.kotlinx.coroutines.test)
}
}
val jvmAndroid =
create("jvmAndroid") {
dependsOn(commonMain.get())
}
jvmMain {
dependsOn(jvmAndroid)
}
androidMain {
dependsOn(jvmAndroid)
}
jvmTest {
dependencies {
implementation(libs.kotlin.test)
implementation(libs.kotlinx.coroutines.test)
implementation(libs.secp256k1.kmp.jni.jvm)
}
}
getByName("androidHostTest") {
dependencies {
implementation(libs.kotlin.test)
implementation(libs.kotlinx.coroutines.test)
implementation(libs.secp256k1.kmp.jni.jvm)
}
}
}
}