diff --git a/atala-prism-sdk/src/commonMain/kotlin/io/iohk/atala/prism/walletsdk/apollo/ApolloImpl.kt b/atala-prism-sdk/src/commonMain/kotlin/io/iohk/atala/prism/walletsdk/apollo/ApolloImpl.kt index b62ef16d7..362aa48b2 100644 --- a/atala-prism-sdk/src/commonMain/kotlin/io/iohk/atala/prism/walletsdk/apollo/ApolloImpl.kt +++ b/atala-prism-sdk/src/commonMain/kotlin/io/iohk/atala/prism/walletsdk/apollo/ApolloImpl.kt @@ -85,23 +85,17 @@ class ApolloImpl : Apollo { override fun createKeyPair(seed: Seed?, privateKey: PrivateKey): KeyPair { return when (privateKey.keyCurve.curve) { Curve.SECP256K1 -> { - val derivationPath = DerivationPath.fromPath("m/${privateKey.keyCurve.index}'/0'/0'") - if (seed == null) { - throw ApolloError.InvalidMnemonicWord() - } - val extendedKey = KeyDerivation.deriveKey(seed.value, derivationPath) - val kmmKeyPair = extendedKey.keyPair() - val mPrivateKey = kmmKeyPair.privateKey as KMMECSecp256k1PrivateKey - val mPublicKey = kmmKeyPair.publicKey as KMMECSecp256k1PublicKey + val kmmPrivateKey = KMMECSecp256k1PrivateKey.secp256k1FromBytes(privateKey.value) + KeyPair( keyCurve = privateKey.keyCurve, privateKey = PrivateKey( keyCurve = privateKey.keyCurve, - value = mPrivateKey.getEncoded(), + value = kmmPrivateKey.getEncoded(), ), publicKey = PublicKey( curve = privateKey.keyCurve, - value = mPublicKey.getEncoded(), + value = kmmPrivateKey.getPublicKey().getEncoded(), ), ) } diff --git a/atala-prism-sdk/src/commonTest/kotlin/io/iohk/atala/prism/walletsdk/apollo/ApolloTests.kt b/atala-prism-sdk/src/commonTest/kotlin/io/iohk/atala/prism/walletsdk/apollo/ApolloTests.kt index 340f6b196..e52708efd 100644 --- a/atala-prism-sdk/src/commonTest/kotlin/io/iohk/atala/prism/walletsdk/apollo/ApolloTests.kt +++ b/atala-prism-sdk/src/commonTest/kotlin/io/iohk/atala/prism/walletsdk/apollo/ApolloTests.kt @@ -118,6 +118,19 @@ class ApolloTests { assertEquals(32, publicKey.value.size) } + @Test + fun testCreateKeyPair_whenSecp256k1FromPrivateKey_thenPublicKeyCorrect() { + val seed = apollo.createRandomSeed() + val keyPair = apollo.createKeyPair(seed = seed.seed, curve = KeyCurve(Curve.SECP256K1)) + val expectedPrivateKey = keyPair.privateKey + val expectedPublicKey = keyPair.publicKey + + val resultKeyPair = apollo.createKeyPair(privateKey = keyPair.privateKey) + + assertEquals(expectedPublicKey, resultKeyPair.publicKey) + assertEquals(expectedPrivateKey, resultKeyPair.privateKey) + } + @Test fun testCreateKeyPair_whenUsingSeedAndMnemonics_thenKeyPairIsCorrect() { val mnemonics = arrayOf("blade", "multiply", "coil", "rare", "fox", "doll", "tongue", "please", "icon", "mind", "gesture", "moral", "old", "laugh", "symptom", "assume", "burden", "appear", "always", "oil", "ticket", "vault", "return", "height")