Having trouble compiling my KmsDriverFactory implementation

We are developing an implementation of the KmsDriver extension based on this doc: Canton KMS Driver Developer Guide — Daml SDK 2.10.0 documentation

The implementation for the KmsDriver interface was pretty straightforward, but we are having trouble getting the Factory to compile:

[error] -- [E172] Type Error: /Users/jimzhang/workspace.daml/kaleido-canton-kms-scala/src/main/scala/aws/kms/AwsKmsDriverFactory.scala:35:71 
[error] 35 |  override def configReader = pureconfig.ConfigReader.mapReader[String]
[error]    |                                                                       ^
[error]    |Cannot find an implicit instance of pureconfig.ConfigReader[String].
[error]    |If you are trying to read or write a case class or sealed trait consider using PureConfig's auto derivation by adding `import pureconfig.generic.auto._`.
[error]    |I found:
[error]    |
[error]    |    pureconfig.Derivation.materializeDerivation[A]
[error]    |
[error]    |But method materializeDerivation in object Derivation does not match type pureconfig.Derivation[pureconfig.ConfigReader[String]].

This was after we’ve added the import import pureconfig.generic.auto._ which according to online searches was the recommendation for errors like this.

Here’s the build.sbt file for the project config:

ThisBuild / version := "0.1.0-SNAPSHOT"

ThisBuild / scalaVersion := "3.3.5"

lazy val root = (project in file("."))
  .settings(
    name := "kaleido-canton-kms",
    idePackagePrefix := Some("io.kaleido.canton.kms")
  )

libraryDependencies += "com.daml" % "canton-community-util-logging_2.13" % "3.3.0-adhoc.20250314.13658.0.v2ae85555"
libraryDependencies += "com.github.pureconfig" %% "pureconfig-core" % "0.17.8"
libraryDependencies += "io.opentelemetry" % "opentelemetry-context" % "1.48.0"
libraryDependencies += "org.scala-lang.modules" % "scala-java8-compat_3" % "1.0.2"
libraryDependencies += "software.amazon.awssdk" % "kms" % "2.29.45"
scalacOptions += "-explain"

Any pointers would be much appreciated!

Jim

Hi Jim

how did you define ConfigType in the driver factory?

In case of ConfigType = String the following works for me to just use the built-in String config reader/writer:

  override def configReader: ConfigReader[String] = ConfigReader[String]

  override def configWriter(confidential: Boolean): ConfigWriter[String] = ConfigWriter[String]

In case of ConfigType = Map[String, String] you can do use the mapReader and mapWriter methods which apply to the value in the Map:

  override def configReader: ConfigReader[Map[String, String]] = ConfigReader.mapReader[String]

  override def configWriter(confidential: Boolean): ConfigWriter[Map[String, String]] =
    ConfigWriter.mapWriter[String]

I noticed that you are building a KMS driver for AWS KMS, note that the Canton enterprise edition has already built-in support for AWS KMS.

1 Like

Thanks @soren for your response. Our Scala developer has since resolved the issue by finding the right place to initialize the implicit variable. Yes our goal was to have additional capabilities for signing/encryption as needed by our platform. We were just using the AWS SDK as an exercise to understand the expected behavior of the Canton KmsDriver interface.

Best,
Jim