Skip to content

Commit

Permalink
use pb-grpc-client-kotlin (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
celloman authored Oct 24, 2023
1 parent a3d1a51 commit 06fcc84
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 254 deletions.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ dependencies {
libs.bundles.kotlinLibs,
libs.bundles.provenance,
libs.bundles.grpc,
libs.bundles.bouncycastle,

libs.figure.hdwallet,

libs.reflections,
libs.commons,
libs.protobuf,
libs.bouncycastle,

// third party plugins that this plugin will apply
libs.shadow,
Expand Down
1 change: 1 addition & 0 deletions example-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ allprojects {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://s01.oss.sonatype.org/content/groups/staging/" }
maven { url 'https://javadoc.jitpack.io' }
}
}
Expand Down
2 changes: 1 addition & 1 deletion example-kotlin/contracts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
dependencies {
api project(':protos')

implementation("io.provenance.scope:contract-base:0.7.0-rc1")
implementation("io.provenance.scope:contract-base:0.7.0-rc2")
}

publishing {
Expand Down
2 changes: 1 addition & 1 deletion example-kotlin/protos/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sourceSets.main.java.srcDirs += 'build/generated/source/proto/main/java'
sourceSets.main.java.srcDirs += 'src/main/kotlin'

dependencies {
implementation("io.provenance.scope:contract-base:0.7.0-rc1")
implementation("io.provenance.scope:contract-base:0.7.0-rc2")

api "com.google.protobuf:protobuf-java:$protobuf_version"
api "com.google.protobuf:protobuf-java-util:$protobuf_version"
Expand Down
17 changes: 10 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[versions]
kotlin = "1.9.10"
reflections = "0.9.10"
provenance-scope-sdk = "0.7.0-rc1"
provenance-scope-sdk = "0.7.0-rc2"
provenance-client = "2.4.0-rc1"
provenance-protobuf = "1.5.0"
figure-hdwallet = "0.4.3"
grpc = "1.58.0"
commons = "2.14.0"
protobuf = "3.24.4"
bouncycastle = "1.70"
shadow = "8.1.1"
kethereum = "0.83.4"
kethereum = "0.86.0"
jackson = "2.15.3"
kotest = "5.7.2"
kotest-4 = "4.4.+"
Expand All @@ -25,13 +26,16 @@ provenance-scope = { module = "io.provenance.scope:util", version.ref = "provena
provenance-client = { module = "io.provenance.client:pb-grpc-client-kotlin", version.ref = "provenance-client" }
provenance-protobuf = { module = "io.provenance.protobuf:pb-proto-java", version.ref = "provenance-protobuf" }

figure-hdwallet = { module = "tech.figure.hdwallet:hdwallet", version.ref = "figure-hdwallet" }

grpc-protobuf = { module = "io.grpc:grpc-protobuf", version.ref = "grpc" }
grpc-stub = { module = "io.grpc:grpc-stub", version.ref = "grpc" }
grpc-netty-shaded = { module = "io.grpc:grpc-netty-shaded", version.ref = "grpc" }

commons = { module = "commons-io:commons-io", version.ref = "commons" }
protobuf = { module = "com.google.protobuf:protobuf-java", version.ref = "protobuf" }
bouncycastle = { module = "org.bouncycastle:bcprov-jdk15on", version.ref = "bouncycastle" }
bouncycastle-bcprov = { module = "org.bouncycastle:bcprov-jdk15on", version.ref = "bouncycastle" }
bouncycastle-bcpkix = { module = "org.bouncycastle:bcpkix-jdk15on", version.ref = "bouncycastle" }

shadow = { module = "com.github.johnrengelman:shadow", version.ref = "shadow" }

Expand All @@ -51,10 +55,9 @@ kotest-runner4 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kot

[bundles]
kotlinLibs = ["kotlinLibs-std", "kotlinLibs-reflect"]
provenance = ["provenance-sdk", "provenance-scope",
# "provenance-client", # todo: add back on once this is used
"provenance-protobuf"]
provenance = ["provenance-sdk", "provenance-scope", "provenance-client", "provenance-protobuf"]
grpc = ["grpc-protobuf", "grpc-stub", "grpc-netty-shaded"]
kethereum = ["kethereum-crypto", "kethereum-crypto-api", "kethereum-crypto-bouncycastle"]
jackson = ["jackson-core", "jackson-databind", "jackson-datatype-jsr310", "jackson-kotlin", "jackson-annotations"]
kotest = ["kotest-runner", "kotest-assertions", "kotest-property"]
kotest = ["kotest-runner", "kotest-assertions", "kotest-property"]
bouncycastle = ["bouncycastle-bcprov", "bouncycastle-bcpkix"]
11 changes: 6 additions & 5 deletions src/main/kotlin/io/provenance/p8e/plugin/Bootstrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.provenance.p8e.plugin
import com.google.protobuf.ByteString
import com.google.protobuf.Message
import io.grpc.ManagedChannelBuilder
import io.provenance.client.grpc.BaseReqSigner
import io.provenance.metadata.v1.ContractSpecification
import io.provenance.metadata.v1.ContractSpecificationRequest
import io.provenance.metadata.v1.DefinitionType
Expand All @@ -15,7 +16,6 @@ import io.provenance.metadata.v1.MsgWriteScopeSpecificationRequest
import io.provenance.metadata.v1.RecordSpecification
import io.provenance.metadata.v1.ScopeSpecification
import io.provenance.metadata.v1.ScopeSpecificationRequest
import io.provenance.scope.contract.annotations.ScopeSpecification as ScopeSpecificationReference
import io.provenance.scope.contract.annotations.ScopeSpecificationDefinition
import io.provenance.scope.contract.proto.Commons.ProvenanceReference
import io.provenance.scope.contract.proto.Specifications.ContractSpec
Expand Down Expand Up @@ -55,6 +55,7 @@ import java.security.PublicKey
import java.security.Security
import java.util.UUID
import java.util.concurrent.TimeUnit
import io.provenance.scope.contract.annotations.ScopeSpecification as ScopeSpecificationReference

fun ContractSpec.uuid(): UUID = toByteArray().sha256LoBytes().toUuid()
fun ContractSpec.hashString(): String = toByteArray().sha256LoBytes().base64EncodeString()
Expand Down Expand Up @@ -139,7 +140,7 @@ internal class Bootstrapper(

val encryptionKeyPair = getKeyPair(location.encryptionPrivateKey!!)
val signingKeyPair = getKeyPair(location.signingPrivateKey!!)
val pbSigner = signingKeyPair.toSignerMeta()
val pbSigner = BaseReqSigner(JavaKeyPairSigner(signingKeyPair, config.mainNet))
val pbAddress = getAddress(signingKeyPair.public, config.mainNet)
val affiliate = Affiliate(
signingKeyRef = DirectKeyRef(signingKeyPair.public, signingKeyPair.private),
Expand Down Expand Up @@ -221,7 +222,7 @@ internal class Bootstrapper(
.build()
}.chunked(location.txBatchSize.toInt()).forEach { batch ->
try {
client.writeTx(pbAddress, pbSigner, batch.toTxBody())
client.writeTx(pbSigner, batch.toTxBody())
} catch (e: Exception) {
project.logger.info("sent messages = $batch")
throw e
Expand Down Expand Up @@ -347,7 +348,7 @@ internal class Bootstrapper(

messages.chunked(location.txBatchSize.toInt()).forEach { batch ->
try {
client.writeTx(pbAddress, pbSigner, batch.toTxBody())
client.writeTx(pbSigner, batch.toTxBody())
} catch (e: Exception) {
project.logger.info("sent messages = $batch")
throw e
Expand Down Expand Up @@ -384,7 +385,7 @@ internal class Bootstrapper(

contractSpecToScopeSpecMessages.chunked(location.txBatchSize.toInt()).forEach { batch ->
try {
client.writeTx(pbAddress, pbSigner, batch.toTxBody())
client.writeTx(pbSigner, batch.toTxBody())
} catch (e: Exception) {
project.logger.info("sent messages = $batch")
throw e
Expand Down
26 changes: 26 additions & 0 deletions src/main/kotlin/io/provenance/p8e/plugin/JavaKeyPairSigner.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.provenance.p8e.plugin

import com.google.protobuf.ByteString
import cosmos.crypto.secp256k1.Keys
import io.provenance.client.grpc.Signer
import io.provenance.scope.encryption.util.getAddress
import tech.figure.hdwallet.common.hashing.sha256
import tech.figure.hdwallet.ec.extensions.toECPrivateKey
import tech.figure.hdwallet.ec.extensions.toECPublicKey
import tech.figure.hdwallet.signer.BCECSigner
import java.security.KeyPair

class JavaKeyPairSigner(private val keyPair: KeyPair, private val mainNet: Boolean) : Signer {
override fun address(): String = keyPair.public.getAddress(mainNet)

override fun pubKey(): Keys.PubKey = Keys.PubKey
.newBuilder()
.setKey(ByteString.copyFrom(keyPair.public.toECPublicKey().compressed()))
.build()

override fun sign(data: ByteArray): ByteArray =
BCECSigner()
.sign(keyPair.private.toECPrivateKey(), data.sha256())
.encodeAsBTC()
.toByteArray()
}
Loading

0 comments on commit 06fcc84

Please sign in to comment.