-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bea3dde
Showing
29 changed files
with
1,812 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: Kotlin CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main, develop ] | ||
release: | ||
types: [ published ] | ||
|
||
jobs: | ||
build: | ||
runs-on: macos-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Validate Gradle Wrapper | ||
uses: gradle/wrapper-validation-action@v1 | ||
|
||
- name: Configure JDK | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'temurin' | ||
cache: gradle | ||
|
||
# Build | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
- name: Test | ||
run: ./gradlew build | ||
|
||
- name: Save Test Reports | ||
if: failure() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: test-reports | ||
path: '**/build/reports' | ||
|
||
publish: | ||
runs-on: macos-latest | ||
needs: build | ||
if: ${{ github.event_name == 'release' }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Configure JDK | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'temurin' | ||
cache: gradle | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
- name: Publish to Maven Central | ||
run: ./gradlew clean publishAllPublicationsToMavenCentral --stacktrace | ||
env: | ||
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }} | ||
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} | ||
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ARTIFACT_SIGNING_PRIVATE_KEY }} | ||
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.ARTIFACT_SIGNING_PRIVATE_KEY_ID }} | ||
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.ARTIFACT_SIGNING_PRIVATE_KEY_PASSWORD }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# Build Files | ||
/build | ||
*/build | ||
/.gradle | ||
|
||
# IDE Files | ||
/.idea | ||
|
||
# Local Only Files | ||
local.properties | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Web3Kt | ||
Multiplatform Web3 Library | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
kotlin("multiplatform") version "1.9.0" apply false | ||
id("com.vanniktech.maven.publish") version "0.25.3" apply false | ||
} | ||
|
||
//tasks.register("clean", Delete::class) { | ||
// delete(rootProject.buildDir) | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
plugins { | ||
kotlin("multiplatform") | ||
kotlin("plugin.serialization") version "1.9.0" | ||
id("com.vanniktech.maven.publish") | ||
} | ||
|
||
val artifactId: String by project | ||
|
||
kotlin { | ||
jvm { | ||
jvmToolchain(11) | ||
withJava() | ||
testRuns["test"].executionTask.configure { | ||
useJUnitPlatform() | ||
} | ||
} | ||
listOf( | ||
iosX64(), | ||
iosArm64(), | ||
iosSimulatorArm64(), | ||
macosX64(), | ||
macosArm64() | ||
).forEach { | ||
it.binaries.framework { | ||
baseName = artifactId | ||
} | ||
} | ||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0-RC") | ||
} | ||
} | ||
val commonTest by getting { | ||
dependencies { | ||
implementation(kotlin("test")) | ||
} | ||
} | ||
} | ||
} | ||
|
||
mavenPublishing { | ||
coordinates(group as String, artifactId, version as String) | ||
} |
23 changes: 23 additions & 0 deletions
23
core/src/commonMain/kotlin/com/funkatronics/publickey/PublicKey.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.funkatronics.publickey | ||
|
||
/** | ||
* PublicKey Interface | ||
* | ||
* @author Funkatronics | ||
*/ | ||
interface PublicKey { | ||
/** | ||
* byte length of the public key | ||
*/ | ||
val length: Number | ||
|
||
/** | ||
* the bytes making up the public key | ||
*/ | ||
val bytes: ByteArray | ||
|
||
/** | ||
* returns a string representation of the Public Key | ||
*/ | ||
fun string(): String | ||
} |
20 changes: 20 additions & 0 deletions
20
core/src/commonMain/kotlin/com/funkatronics/serialization/ByteStringSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.funkatronics.serialization | ||
|
||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.builtins.ByteArraySerializer | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
open class ByteStringSerializer(val length: Int) : KSerializer<ByteArray> { | ||
override val descriptor: SerialDescriptor = ByteArraySerializer().descriptor | ||
|
||
override fun deserialize(decoder: Decoder) = | ||
ByteArray(length) { | ||
decoder.decodeByte() | ||
} | ||
|
||
override fun serialize(encoder: Encoder, value: ByteArray) { | ||
value.forEach { encoder.encodeByte(it) } | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
core/src/commonMain/kotlin/com/funkatronics/serialization/CompactArraySerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.funkatronics.serialization | ||
|
||
import com.funkatronics.util.asVarint | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.builtins.ByteArraySerializer | ||
import kotlinx.serialization.builtins.ListSerializer | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
class CompactArraySerializer<T>(val valueSerializer: KSerializer<T>) : KSerializer<Collection<T>> { | ||
override val descriptor: SerialDescriptor = ListSerializer(valueSerializer).descriptor | ||
|
||
override fun deserialize(decoder: Decoder): Collection<T> { | ||
var size = 0 // decoder.decodeByte().toInt() | ||
var shift = 0 | ||
do { | ||
val b = decoder.decodeByte().toInt() and 0xFF | ||
size = ((b and 0x7f) shl shift) or size | ||
shift += 7 | ||
} while (b and 0x80 != 0) | ||
|
||
return List(size) { | ||
decoder.decodeSerializableValue(valueSerializer) | ||
} | ||
} | ||
|
||
override fun serialize(encoder: Encoder, value: Collection<T>) { | ||
value.size.asVarint().forEach { encoder.encodeByte(it) } | ||
value.forEach { encoder.encodeSerializableValue(valueSerializer, it) } | ||
} | ||
} | ||
|
||
object CompactByteArraySerializer : KSerializer<ByteArray> { | ||
override val descriptor: SerialDescriptor = ByteArraySerializer().descriptor | ||
|
||
override fun deserialize(decoder: Decoder): ByteArray { | ||
var size = 0 // decoder.decodeByte().toInt() | ||
var shift = 0 | ||
do { | ||
val b = decoder.decodeByte().toInt() and 0xFF | ||
size = ((b and 0x7f) shl shift) or size | ||
shift += 7 | ||
} while (b and 0x80 != 0) | ||
|
||
return ByteArray(size) { | ||
decoder.decodeByte() | ||
} | ||
} | ||
|
||
override fun serialize(encoder: Encoder, value: ByteArray) { | ||
value.size.asVarint().forEach { encoder.encodeByte(it) } | ||
value.forEach { encoder.encodeByte(it) } | ||
} | ||
} | ||
|
||
object CompactSignatureArraySerializer : KSerializer<List<ByteArray>> { | ||
override val descriptor: SerialDescriptor = ByteArraySerializer().descriptor | ||
|
||
override fun deserialize(decoder: Decoder): List<ByteArray> { | ||
var size = 0 // decoder.decodeByte().toInt() | ||
var shift = 0 | ||
do { | ||
val b = decoder.decodeByte().toInt() and 0xFF | ||
size = ((b and 0x7f) shl shift) or size | ||
shift += 7 | ||
} while (b and 0x80 != 0) | ||
|
||
return List(size) { | ||
ByteArray(64) { | ||
decoder.decodeByte() | ||
} | ||
} | ||
} | ||
|
||
override fun serialize(encoder: Encoder, value: List<ByteArray>) { | ||
value.size.asVarint().forEach { encoder.encodeByte(it) } | ||
value.forEach { it.forEach { encoder.encodeByte(it) } } | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
core/src/commonMain/kotlin/com/funkatronics/signer/Ed25519Signer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.funkatronics.signer | ||
|
||
abstract class Ed25519Signer : Signer { | ||
override val ownerLength = 32 | ||
override val signatureLength = 64 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.funkatronics.signer | ||
|
||
interface Signer { | ||
val publicKey: ByteArray | ||
val ownerLength: Number | ||
val signatureLength: Number | ||
suspend fun signPayload(payload: ByteArray): ByteArray | ||
} |
39 changes: 39 additions & 0 deletions
39
core/src/commonMain/kotlin/com/funkatronics/util/Varint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.funkatronics.util | ||
|
||
import kotlin.experimental.and | ||
import kotlin.math.ceil | ||
|
||
object Varint { | ||
|
||
fun encode(value: Int): ByteArray { | ||
if (value == 0) return byteArrayOf(0) | ||
var num = value | ||
val encodedSize = ceil((Int.SIZE_BITS - value.countLeadingZeroBits()) / 7f).toInt() | ||
return ByteArray(encodedSize) { | ||
(num and 0x7F or if (num < 128) 0 else 128).toByte().also { | ||
num /= 128 | ||
} | ||
} | ||
} | ||
|
||
fun encode(value: Long): ByteArray { | ||
if (value == 0L) return byteArrayOf(0) | ||
var num = value | ||
val encodedSize = ceil((Long.SIZE_BITS - value.countLeadingZeroBits()) / 7f).toInt() | ||
return ByteArray(encodedSize) { | ||
(num and 0x7F or if (num < 128) 0 else 128).toByte().also { | ||
num /= 128 | ||
} | ||
} | ||
} | ||
|
||
fun decode(bytes: ByteArray): Long = | ||
bytes.takeWhile { it and 0x80.toByte() < 0 }.run { | ||
this + bytes[this.size] | ||
}.foldIndexed(0L) { index, value, byte -> | ||
((byte and 0x7f).toLong() shl (7*index)) or value | ||
} | ||
} | ||
|
||
fun Int.asVarint() = Varint.encode(this) | ||
fun Long.asVarint() = Varint.encode(this) |
Oops, something went wrong.