From c61204c422aae406a07d713f929252a625507aa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Ribo=CC=81?= Date: Mon, 30 Sep 2024 17:45:28 +0200 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20ed25519=20for=20JS=20fixes=20on=20si?= =?UTF-8?q?gnatures=20Signed-off-by:=20Javier=20Ribo=CC=81=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../identus/apollo/utils/KMMEdPrivateKey.kt | 2 +- .../identus/apollo/utils/KMMEdPublicKey.kt | 5 +- .../apollo/utils/external/Ellipticjs.kt | 2 +- .../identus/apollo/utils/KMMEdKeyPairTests.kt | 79 ++++++++----------- 4 files changed, 39 insertions(+), 49 deletions(-) diff --git a/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPrivateKey.kt b/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPrivateKey.kt index d23cd4a36..22e80ea1d 100644 --- a/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPrivateKey.kt +++ b/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPrivateKey.kt @@ -49,7 +49,7 @@ actual class KMMEdPrivateKey(bytes: ByteArray) { actual fun sign(message: ByteArray): ByteArray { val sig = keyPair.sign(Buffer.from(message)) - return sig.toHex().encodeToByteArray() + return sig.toBytes().toByteArray() } /** diff --git a/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPublicKey.kt b/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPublicKey.kt index 6b3f0a358..46c7d213e 100644 --- a/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPublicKey.kt +++ b/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPublicKey.kt @@ -46,6 +46,9 @@ actual class KMMEdPublicKey(bytes: ByteArray) { * @return Boolean */ actual fun verify(message: ByteArray, sig: ByteArray): Boolean { - return keyPair.verify(Buffer.from(message), sig.decodeToString()) + return keyPair.verify( + Buffer.from(message), + sig.toHexString() + ) } } diff --git a/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/external/Ellipticjs.kt b/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/external/Ellipticjs.kt index 1006fc84f..deed952b8 100644 --- a/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/external/Ellipticjs.kt +++ b/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/external/Ellipticjs.kt @@ -279,7 +279,7 @@ open external class eddsa(name: String /* "ed25519" */) { open fun isPoint(param_val: Any): Boolean open class Signature { constructor(eddsa: eddsa, sig: _eddsa_Signature) - constructor(eddsa: eddsa, sig: String) + constructor(eddsa: eddsa, sig: Any) open fun toBytes(): Buffer open fun toHex(): String } diff --git a/apollo/src/jsTest/kotlin/org/hyperledger/identus/apollo/utils/KMMEdKeyPairTests.kt b/apollo/src/jsTest/kotlin/org/hyperledger/identus/apollo/utils/KMMEdKeyPairTests.kt index 374dfb9d2..c51c9ba60 100644 --- a/apollo/src/jsTest/kotlin/org/hyperledger/identus/apollo/utils/KMMEdKeyPairTests.kt +++ b/apollo/src/jsTest/kotlin/org/hyperledger/identus/apollo/utils/KMMEdKeyPairTests.kt @@ -2,26 +2,25 @@ package org.hyperledger.identus.apollo.utils -import node.buffer.Buffer +import org.hyperledger.identus.apollo.base64.base64DecodedBytes +import org.hyperledger.identus.apollo.base64.base64UrlDecodedBytes +import org.hyperledger.identus.apollo.base64.base64UrlEncoded import kotlin.test.Test import kotlin.test.assertFalse import kotlin.test.assertNotNull import kotlin.test.assertTrue class KMMEdKeyPairTests { - private val raw = arrayOf(234, 155, 38, 115, 124, 211, 171, 185, 149, 186, 77, 255, 240, 94, 209, 65, 63, 214, 168, 213, 146, 68, 68, 196, 167, 211, 183, 80, 14, 166, 239, 217) - private val rawBytes = Buffer.from(raw).toByteArray() - private val encoded = arrayOf(54, 112, 115, 109, 99, 51, 122, 84, 113, 55, 109, 86, 117, 107, 51, 95, 56, 70, 55, 82, 81, 84, 95, 87, 113, 78, 87, 83, 82, 69, 84, 69, 112, 57, 79, 51, 85, 65, 54, 109, 55, 57, 107) - private val encodedBytes = Buffer.from(encoded).toByteArray() - private val publicRaw = arrayOf(207, 230, 188, 131, 200, 191, 223, 38, 163, 19, 244, 3, 35, 18, 5, 238, 195, 245, 155, 246, 139, 41, 51, 159, 202, 2, 46, 72, 150, 167, 68, 8) - private val publicRawBytes = Buffer.from(publicRaw).toByteArray() - private val publicEncoded = arrayOf(122, 45, 97, 56, 103, 56, 105, 95, 51, 121, 97, 106, 69, 95, 81, 68, 73, 120, 73, 70, 55, 115, 80, 49, 109, 95, 97, 76, 75, 84, 79, 102, 121, 103, 73, 117, 83, 74, 97, 110, 82, 65, 103) - private val publicEncodedBytes = Buffer.from(publicEncoded).toByteArray() + val rawMessage = "Hello".encodeToByteArray() + val rawSK = "M7+EvGp9vjLyx5SQ1xiKhRUN+YQ0kjx6d21WgX8P1hE".base64DecodedBytes + val rawSKEncoded = rawSK.base64UrlEncoded + val rawPk = "6kXLIS4a3UAzHm/5XTcvjCTGoAQ+yqPTT0YsM76EeuQ".base64DecodedBytes + val rawPKEncoded = rawPk.base64UrlEncoded + val rawSig = "rQHC0fmOclPBFiPVJCK_WJB0NgTAxSqpggPwRotNdncKrhgM2eECtr3j7UBTBmDdPTmpXGwQvyhTRTG8cymeBA".base64UrlDecodedBytes @Test fun testGenerateKeyPair() { val keyPair = KMMEdKeyPair.generateKeyPair() - assertNotNull(keyPair) assertNotNull(keyPair.privateKey) assertNotNull(keyPair.publicKey) @@ -29,78 +28,66 @@ class KMMEdKeyPairTests { @Test fun testConstructorRaw() { - val key = KMMEdPrivateKey(rawBytes) - - assertTrue(key.raw.toByteArray() contentEquals rawBytes) - assertTrue(key.getEncoded().toByteArray() contentEquals encodedBytes) + val key = KMMEdPrivateKey(rawSK) + val rawKeyBytes = key.raw.toByteArray() + val rawKeyEncodedBytes = key.getEncoded().toByteArray().decodeToString() + assertTrue(rawKeyBytes contentEquals rawSK) + assertTrue(rawKeyEncodedBytes contentEquals rawSKEncoded) } @Test fun testConstructorEncoded() { - val key = KMMEdPrivateKey(encodedBytes) - - assertTrue(key.raw.toByteArray() contentEquals rawBytes) - assertTrue(key.getEncoded().toByteArray() contentEquals encodedBytes) + val key = KMMEdPrivateKey(rawSKEncoded.base64UrlDecodedBytes) + assertTrue(key.raw.toByteArray() contentEquals rawSK) + assertTrue(key.getEncoded().toByteArray().decodeToString() contentEquals rawSKEncoded) } @Test fun testGetEncoded() { - val key = KMMEdPrivateKey(rawBytes) - - assertTrue(key.getEncoded().toByteArray() contentEquals encodedBytes) + val key = KMMEdPrivateKey(rawSK) + assertTrue(key.getEncoded().toByteArray().decodeToString() contentEquals rawSKEncoded) } + @Test fun testPublicKey() { - val privateKey = KMMEdPrivateKey(rawBytes) + val privateKey = KMMEdPrivateKey(rawSK) val publicKey = privateKey.publicKey() - - assertTrue(publicKey.raw.toByteArray() contentEquals publicRawBytes) - assertTrue(publicKey.getEncoded().toByteArray() contentEquals publicEncodedBytes) + assertTrue(publicKey.raw.toByteArray() contentEquals rawPk) + assertTrue(publicKey.getEncoded().toByteArray().decodeToString() contentEquals rawPKEncoded) } @Test fun testSignMessage() { val keyPair = KMMEdKeyPair.generateKeyPair() - val message = "testing".encodeToByteArray() - val sig = keyPair.sign(message) - + val sig = keyPair.sign(rawMessage) assertNotNull(sig) } + @Test fun testSignMessageKnownValue() { - val privateKey = KMMEdPrivateKey(rawBytes) - val message = "testing".encodeToByteArray() - val sig = privateKey.sign(message) - val sigStr = Buffer.from(sig).toString() - val expectedBytes = byteArrayOf(67, 68, 57, 67, 68, 69, 52, 67, 49, 54, 50, 51, 65, 69, 57, 65, 51, 48, 55, 51, 69, 66, 50, 52, 49, 48, 67, 53, 53, 48, 52, 57, 53, 52, 70, 51, 57, 69, 68, 67, 68, 55, 66, 68, 57, 49, 57, 67, 54, 67, 49, 54, 67, 68, 54, 51, 52, 56, 48, 55, 50, 56, 53, 69, 66, 51, 70, 57, 69, 69, 51, 52, 52, 51, 57, 49, 66, 55, 65, 51, 55, 69, 54, 53, 53, 70, 56, 51, 49, 70, 68, 48, 57, 70, 50, 50, 52, 53, 68, 55, 66, 70, 50, 67, 48, 57, 70, 66, 69, 67, 57, 55, 55, 51, 50, 50, 49, 69, 65, 48, 52, 50, 70, 69, 69, 49, 48, 48) - val expectedStr = Buffer.from(expectedBytes).toString() - + val privateKey = KMMEdPrivateKey(rawSK) + val sig = privateKey.sign(rawMessage) assertNotNull(sig) - assertTrue(expectedBytes contentEquals sig) - assertTrue(expectedStr contentEquals sigStr) + assertTrue(sig contentEquals rawSig) } @Test fun testVerifyMessage() { val keyPair = KMMEdKeyPair.generateKeyPair() - val msgHash = "testing".encodeToByteArray() - val sig = keyPair.sign(msgHash) - val verified = keyPair.verify(msgHash, sig) - + val sig = keyPair.sign(rawMessage) + val verified = keyPair.verify(rawMessage, sig) assertTrue(verified) } + @Test fun testVerifyWithAnotherKeyPairFails() { val keyPair = KMMEdKeyPair.generateKeyPair() - val msgHash = "testing".encodeToByteArray() - val sig = keyPair.sign(msgHash) - + val sig = keyPair.sign(rawMessage) val wrongKeyPair = KMMEdKeyPair.generateKeyPair() - val verified = wrongKeyPair.verify(msgHash, sig) - + val verified = wrongKeyPair.verify(rawMessage, sig) assertFalse(verified) } } From 8a81816582f8e85257778c25f4766cfaad7b2751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Ribo=CC=81?= Date: Thu, 3 Oct 2024 15:10:12 +0200 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20improve=20submodules=20Signed-off-by?= =?UTF-8?q?:=20Javier=20Ribo=CC=81=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rust-ed25519-bip32 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-ed25519-bip32 b/rust-ed25519-bip32 index ac791dc55..1186ed95d 160000 --- a/rust-ed25519-bip32 +++ b/rust-ed25519-bip32 @@ -1 +1 @@ -Subproject commit ac791dc551c5f7aa6e9ddfc83c32a2629d710ccb +Subproject commit 1186ed95d1dcc47e63f1a218002f4c543cabce86 From 8cf5da6f263aacbe3ea382556a1b4ae174bad535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Ribo=CC=81?= Date: Wed, 23 Oct 2024 11:23:10 +0200 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20building=20on=20more=20recent=20maco?= =?UTF-8?q?s=20version=20Signed-off-by:=20Javier=20Ribo=CC=81=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pull-request.yml | 2 +- .github/workflows/release.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 6b69c76b0..cf493802f 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -26,7 +26,7 @@ jobs: include: - os: ubuntu-latest os-type: linux - - os: macos-13 + - os: macos-latest os-type: macos fail-fast: false runs-on: ${{ matrix.os }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4bbfd54f5..f5d29890b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,7 +31,7 @@ permissions: jobs: release: - runs-on: macos-13 + runs-on: macos-latest steps: - name: "Checkout the repo" uses: actions/checkout@v4 @@ -59,7 +59,7 @@ jobs: - name: "Install autoconf, automake, libtool, rustup" run: | - brew install autoconf automake libtool rustup + brew install autoconf automake libtool rustup@1.27.0 - name: "Install Mac ToolChain" run: | From 610c49a458605c57d8d19cdbaa68fe576af616e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Ribo=CC=81?= Date: Wed, 23 Oct 2024 11:46:03 +0200 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20remove=20rustup=20custom=20version?= =?UTF-8?q?=20Signed-off-by:=20Javier=20Ribo=CC=81=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f5d29890b..b151d2cdb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -59,7 +59,7 @@ jobs: - name: "Install autoconf, automake, libtool, rustup" run: | - brew install autoconf automake libtool rustup@1.27.0 + brew install autoconf automake libtool rustup - name: "Install Mac ToolChain" run: |