Skip to content

Commit

Permalink
Merge main into ATL-6049
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianIOHK committed Jan 2, 2024
2 parents 8c6008f + 55dafc2 commit d213866
Show file tree
Hide file tree
Showing 156 changed files with 4,983 additions and 598 deletions.
50 changes: 26 additions & 24 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,49 @@ on:
mediatorOobUrl:
required: true
description: Mediator out-of-band url
default: https://sit-prism-mediator.atalaprism.io/invitationOOB
default: https://beta-mediator.atalaprism.io/invitationOOB
prismAgentUrl:
required: true
description: Prism-agent server url
default: https://sit-prism-agent-issuer.atalaprism.io/prism-agent
default: https://sit-prism-agent-issuer.atalaprism.io/prism-agent/
apiKey:
required: false
description: Authorization key
publishedDid:
required: false
description: Published DID
default: did:prism:dac7505c41dd8e380b187544e8ae77e1ff8e39f62cd4d8d83310e23
schemaId:
jwtSchemaGuid:
required: false
description: Schema ID
default: 99647c77-5074-369f-85ed-067bfe062f77
apiKey:
description: JWT schema GUID
anoncredDefinitionGuid:
required: false
description: Authorization key
default: 1gnp5fzLTwNBvLBXLk9THLgxe9SLoh+7
description: Anoncred definition GUID
push:
branches:
- main
- prerelease
- release

env:
JAVA_VERSION: 11
ATALA_GITHUB_ACTOR: ${{ secrets.ATALA_GITHUB_ACTOR }}
ATALA_GITHUB_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }}
GITHUB_ACTOR: ${{ secrets.ATALA_GITHUB_ACTOR }}
GITHUB_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }}
MEDIATOR_OOB_URL: ${{ inputs.mediatorOobUrl || vars.MEDIATOR_OOB_URL }}
PRISM_AGENT_URL: ${{ inputs.prismAgentUrl || vars.PRISM_AGENT_URL }}
PUBLISHED_DID: ${{ inputs.publishedDid || vars.PUBLISHED_DID }}
SCHEMA_ID: ${{ inputs.schemaId || vars.SCHEMA_ID }}
APIKEY: ${{ inputs.apiKey || secrets.APIKEY }}
NODE_AUTH_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }}

jobs:
run-e2e-tests:
name: "Run"
name: 'Run'
runs-on: ubuntu-latest

steps:
- name: Mask apikey
env:
APIKEY: ${{ inputs.apiKey || secrets.APIKEY }}
run: echo "::add-mask::${{env.APIKEY}}"

- name: Install Java ${{ env.JAVA_VERSION }}
- name: Install Java 11
uses: actions/setup-java@v3
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: "adopt"
java-version: 11
distribution: 'adopt'

- name: Checkout Code
uses: actions/checkout@v3
Expand All @@ -72,11 +67,18 @@ jobs:
uses: gradle/gradle-build-action@v2

- name: Publish to maven local
if: github.event_name == 'pull_request'
if: github.event_name == 'push' || github.event_name == 'schedule'
run: |
./gradlew publishToMavenLocal
- name: Run tests
env:
MEDIATOR_OOB_URL: ${{ inputs.mediatorOobUrl || vars.MEDIATOR_OOB_URL }}
PRISM_AGENT_URL: ${{ inputs.prismAgentUrl || vars.PRISM_AGENT_URL }}
PUBLISHED_DID: ${{ inputs.publishedDid || vars.PUBLISHED_DID }}
JWT_SCHEMA_GUID: ${{ inputs.jwtSchemaGuid || vars.SCHEMA_ID }}
ANONCRED_DEFINITION_GUID: ${{ inputs.anoncredDefinitionGuid || vars.ANONCRED_DEFINITION_GUID }}
APIKEY: ${{ inputs.apiKey || secrets.APIKEY }}
working-directory: tests/end-to-end
run: |
./gradlew test --tests "TestSuite"
Expand All @@ -91,4 +93,4 @@ jobs:
with:
name: atala-prism-sdk-kmm
path: tests/end-to-end/target/site/serenity
if-no-files-found: error
if-no-files-found: 'error'
3 changes: 2 additions & 1 deletion .releaserc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
branches:
- name: "main"
- name: "beta"
- name: "release"
- name: "prerelease"
prerelease: "snapshot"

plugins:
Expand Down
2 changes: 1 addition & 1 deletion atala-prism-sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ tasks.withType<DokkaTask>().configureEach {
}
}

val buildProtoLibsGen by tasks.creating {
val buildProtoLibsGen: Task by tasks.creating {
group = "build"
this.dependsOn(":protosLib:generateProto")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ package io.iohk.atala.prism.walletsdk.domain.models
import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.okhttp.OkHttp

/**
* Creates an HTTP client with the specified configuration.
*
* @param config The configuration block for the HTTP client.
* @return The created HTTP client.
*/
actual fun httpClient(config: HttpClientConfig<*>.() -> Unit) = io.ktor.client.HttpClient(OkHttp) {
config(this)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
package io.iohk.atala.prism.walletsdk.domain.models

/**
* The `Platform` object represents the platform on which the code is running.
*/
actual object Platform {
/**
* This variable represents the operating system on which the code is currently running.
*
* On Android, it returns a string with the Android version followed by the SDK level.
* For example: "Android 10"
*
* @return The operating system of the device.
*/
actual val OS: String
get() = "Android"
get() = "Android ${android.os.Build.VERSION.SDK_INT}"

/**
* Represents the platform type.
*
* This actual property represents the current platform type. It is used to determine the type of the platform on which
* the application is being executed. The possible platform types are JVM, ANDROID, IOS, and WEB.
*
* This property is read-only and can be accessed using the `type` property of the `PlatformType` class.
*
* Example usage:
* ```
* val platformType = PlatformType.ANDROID
* ```
*
* @see PlatformType
*/
actual val type: PlatformType
get() = PlatformType.ANDROID
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import com.squareup.sqldelight.db.SqlDriver
import io.iohk.atala.prism.walletsdk.PrismPlutoDb
import io.iohk.atala.prism.walletsdk.domain.models.PlutoError

/**
* DbConnection class represents a connection to the database.
*/
actual class DbConnection actual constructor() {
actual var driver: SqlDriver? = null
actual suspend fun connectDb(context: Any?): PrismPlutoDb {
Expand All @@ -16,5 +19,14 @@ actual class DbConnection actual constructor() {
}
}

/**
* Represents the connection status of an SQL driver.
*/
actual val SqlDriver.isConnected: Boolean
get() = true
get() {
try {
return this.executeQuery(null, "SELECT 1", 0).next()
} catch (ex: Exception) {
return false
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.iohk.atala.prism.walletsdk.apollo

import io.iohk.atala.prism.apollo.derivation.HDKey
import io.iohk.atala.prism.apollo.derivation.Mnemonic
import io.iohk.atala.prism.apollo.derivation.MnemonicHelper
import io.iohk.atala.prism.apollo.derivation.MnemonicLengthException
import io.iohk.atala.prism.walletsdk.apollo.helpers.BytesOps
import io.iohk.atala.prism.walletsdk.apollo.utils.Ed25519KeyPair
Expand Down Expand Up @@ -39,7 +39,7 @@ class ApolloImpl : Apollo {
* @return An array of mnemonic phrases.
*/
override fun createRandomMnemonics(): Array<String> {
return Mnemonic.createRandomMnemonics().toTypedArray()
return MnemonicHelper.createRandomMnemonics().toTypedArray()
}

/**
Expand All @@ -52,7 +52,7 @@ class ApolloImpl : Apollo {
*/
@Throws(MnemonicLengthException::class)
override fun createSeed(mnemonics: Array<String>, passphrase: String): Seed {
return Seed(Mnemonic.createSeed(mnemonics.asList(), passphrase))
return Seed(MnemonicHelper.createSeed(mnemonics.asList(), passphrase))
}

/**
Expand All @@ -66,20 +66,40 @@ class ApolloImpl : Apollo {
return SeedWords(
mnemonics,
Seed(
value = Mnemonic.createSeed(
value = MnemonicHelper.createSeed(
mnemonics = mnemonics.asList(),
passphrase = passphrase ?: ""
)
)
)
}

/**
* Creates a private key based on the provided properties.
*
* @param properties A map of properties used to create the private key. The map should contain the following keys:
* - "type" (String): The type of the key ("EC" or "Curve25519").
* - "curve" (String): The curve of the key.
* - "rawKey" (ByteArray): The raw key data (optional).
* - "index" (Int): The index for the key (only applicable for EC keys with curve "secp256k1").
* - "derivationPath" (String): The derivation path for the key (only applicable for EC keys with curve "secp256k1").
* - "seed" (String): The seed for the key (only applicable for EC keys with curve "secp256k1").
*
* @return The created private key.
*
* @throws ApolloError.InvalidKeyType If the provided key type is invalid.
* @throws ApolloError.InvalidKeyCurve If the provided key curve is invalid.
* @throws ApolloError.InvalidRawData If the provided raw key data is invalid.
* @throws ApolloError.InvalidIndex If the provided index is invalid.
* @throws ApolloError.InvalidDerivationPath If the provided derivation path is invalid.
* @throws ApolloError.InvalidSeed If the provided seed is invalid.
*/
override fun createPrivateKey(properties: Map<String, Any>): PrivateKey {
if (!properties.containsKey(TypeKey().property)) {
throw ApolloError.InvalidKeyType(TypeKey().property, KeyTypes.values().map { it.type }.toTypedArray())
throw ApolloError.InvalidKeyType(TypeKey().property)
}
if (!properties.containsKey(CurveKey().property)) {
throw ApolloError.InvalidKeyCurve(CurveKey().property, Curve.values().map { it.value }.toTypedArray())
throw ApolloError.InvalidKeyCurve(CurveKey().property)
}

val keyType = properties[TypeKey().property]
Expand Down Expand Up @@ -148,17 +168,38 @@ class ApolloImpl : Apollo {
return keyPair.privateKey
}
}
throw ApolloError.InvalidKeyType(TypeKey().property, KeyTypes.values().map { it.type }.toTypedArray())
throw ApolloError.InvalidKeyType(TypeKey().property)
}

/**
* Checks if the provided data is associated with a private key identified by the given identifier.
*
* @param identifier The identifier for the private key.
* @param data The data to check.
* @return True if the data is associated with a private key, false otherwise.
*/
override fun isPrivateKeyData(identifier: String, data: ByteArray): Boolean {
return identifier.endsWith("priv")
}

/**
* Checks if the provided data is associated with a public key identified by the given identifier.
*
* @param identifier The identifier for the public key.
* @param data The data to check.
* @return True if the data is associated with a public key, false otherwise.
*/
override fun isPublicKeyData(identifier: String, data: ByteArray): Boolean {
return identifier.endsWith("pub")
}

/**
* Restores a private key based on the provided storable key.
*
* @param key The storable key to restore the private key from.
* @return The restored private key.
* @throws ApolloError.RestorationFailedNoIdentifierOrInvalid If the restoration identifier is missing or invalid.
*/
override fun restorePrivateKey(key: StorableKey): PrivateKey {
return when (key.restorationIdentifier) {
"secp256k1+priv" -> {
Expand All @@ -179,6 +220,13 @@ class ApolloImpl : Apollo {
}
}

/**
* Restores a public key based on the provided storable key.
*
* @param key The storable key to restore the public key from.
* @return The restored public key.
* @throws ApolloError.RestorationFailedNoIdentifierOrInvalid If the restoration identifier is missing or invalid.
*/
override fun restorePublicKey(key: StorableKey): PublicKey {
return when (key.restorationIdentifier) {
"secp256k1+pub" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package io.iohk.atala.prism.walletsdk.apollo.config

import com.ionspin.kotlin.bignum.integer.BigInteger

/**
* The ECConfig object provides configuration properties and constants related to elliptic curve cryptography (ECC).
*/
object ECConfig {
val PRIVATE_KEY_BYTE_SIZE: Int = 32
internal val PUBLIC_KEY_COORDINATE_BYTE_SIZE: Int = 32
internal val PUBLIC_KEY_COMPRESSED_BYTE_SIZE: Int = PUBLIC_KEY_COORDINATE_BYTE_SIZE + 1
val SIGNATURE_MAX_BYTE_SIZE: Int = 72
val PUBLIC_KEY_BYTE_SIZE: Int = PUBLIC_KEY_COORDINATE_BYTE_SIZE * 2 + 1
const val PRIVATE_KEY_BYTE_SIZE: Int = 32
internal const val PUBLIC_KEY_COORDINATE_BYTE_SIZE: Int = 32
internal const val PUBLIC_KEY_COMPRESSED_BYTE_SIZE: Int = PUBLIC_KEY_COORDINATE_BYTE_SIZE + 1
const val SIGNATURE_MAX_BYTE_SIZE: Int = 72
const val PUBLIC_KEY_BYTE_SIZE: Int = PUBLIC_KEY_COORDINATE_BYTE_SIZE * 2 + 1

// Field characteristic p (prime) is equal to 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1
internal val p = BigInteger.parseString("115792089237316195423570985008687907853269984665640564039457584007908834671663", 10)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package io.iohk.atala.prism.walletsdk.apollo.helpers

/**
* Pads the current ByteArray with the specified padValue at the beginning,
* making it equal to or larger than the specified length.
*
* @param length The desired length for the new ByteArray.
* @param padValue The value used to pad the ByteArray.
* @return The padded ByteArray with the specified length.
*/
fun ByteArray.padStart(length: Int, padValue: Byte): ByteArray {
return if (size >= length) {
this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package io.iohk.atala.prism.walletsdk.apollo.helpers

import java.math.BigInteger

/**
* Converts a Kotlin BigInteger to a Java BigInteger.
*
* @return the converted Java BigInteger.
*/
fun com.ionspin.kotlin.bignum.integer.BigInteger.toJavaBigInteger(): BigInteger {
return BigInteger(this.signum(), this.toByteArray())
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@ import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.KeyPair
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.PrivateKey
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.PublicKey

/**
* Represents a pair of Ed25519 private and public keys.
*/
class Ed25519KeyPair(
override var privateKey: PrivateKey,
override var publicKey: PublicKey
) : KeyPair() {

companion object {
/**
* Generates a pair of Ed25519 private and public keys.
*
* @return The generated Ed25519KeyPair.
*/
@JvmStatic
fun generateKeyPair(): Ed25519KeyPair {
val pair = KMMEdKeyPair.generateKeyPair()

Expand Down
Loading

0 comments on commit d213866

Please sign in to comment.