-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Allow Apollo to verify der signatures from bc and bitcoin seamle…
…ssly. Will try validating bouncyCastle or convert to bouncy castle from bitcoin format.
- Loading branch information
1 parent
4b9b207
commit a73f59f
Showing
4 changed files
with
154 additions
and
2 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
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
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
92 changes: 92 additions & 0 deletions
92
apollo/src/jvmTest/kotlin/io.iohk.atala.prism.apollo/utils/Secp256k1LibJVMTests.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,92 @@ | ||
package io.iohk.atala.prism.apollo.utils | ||
|
||
import io.iohk.atala.prism.apollo.base64.base64UrlDecodedBytes | ||
import io.iohk.atala.prism.apollo.secp256k1.Secp256k1Lib | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
|
||
class Secp256k1LibJVMTests { | ||
|
||
|
||
@Test | ||
fun testVerification() { | ||
val pubKeyBase64 = "BD-l4lrQ6Go-oN5XtdpY6o5dyf2V2v5EbMAvRjVGJpE1gYVURJfxKMpNPnKlLr4MOLNVaYvBNOoy9L50E8jVx8Q" | ||
val signatureBase64 = | ||
"MEUCIQCFeGlhJrH-9R70X4JzrurWs52SwuxCnJ8ky6riFwMOrwIgT7zlLo7URMHW5tiMgG73IOw2Dm3XyLl1iqW1-t5NFWQ" | ||
val message = "Test" | ||
|
||
assertTrue { | ||
Secp256k1Lib().verify( | ||
pubKeyBase64.base64UrlDecodedBytes, | ||
signatureBase64.base64UrlDecodedBytes, | ||
message.encodeToByteArray() | ||
) | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalStdlibApi::class) | ||
@Test | ||
fun testSignatureNormalisationFromJS() { | ||
val signatureHex = "3045022100bca0478b0f400277626355d9f411bf0534afb1236758099c0c8ffdd761664a7202207e629a601f1bbe3e0df10899e62919c2a5c902f773120a2bddeb1cde14bae1fd" | ||
val publicKeyHex = "042e6d481b0b8761414166ea01431ed339d9150a58c2e521cb6cc8638988299b835acfc2cc1c7a7fd9ea54acc8060c37367be8ed7fb70c13203e702ef7a20d8b06" | ||
val dataHex = "4174616c61507269736d2057616c6c65742053444b"; | ||
val publicKey = publicKeyHex.hexToByteArray() | ||
val signature = signatureHex.hexToByteArray(); | ||
val data = dataHex.hexToByteArray(); | ||
val valid = Secp256k1Lib().verify(publicKey,signature, data) | ||
assertEquals( valid, true) | ||
} | ||
|
||
@Test | ||
fun testJVMVerification() { | ||
val pubKeyBase64 = "BD-l4lrQ6Go-oN5XtdpY6o5dyf2V2v5EbMAvRjVGJpE1gYVURJfxKMpNPnKlLr4MOLNVaYvBNOoy9L50E8jVx8Q" | ||
val signatureBase64 = "MEUCIQCFeGlhJrH-9R70X4JzrurWs52SwuxCnJ8ky6riFwMOrwIgT7zlLo7URMHW5tiMgG73IOw2Dm3XyLl1iqW1-t5NFWQ" | ||
val message = "Test" | ||
assertTrue { | ||
Secp256k1Lib().verify( | ||
pubKeyBase64.base64UrlDecodedBytes, | ||
signatureBase64.base64UrlDecodedBytes, | ||
message.encodeToByteArray() | ||
) | ||
} | ||
} | ||
|
||
|
||
@Test | ||
fun testJVMVerificationBitcoin() { | ||
val ecPublicKeyBase64 = "BC7OYUnD57Qxel3-gyGuUIeicvRYhkFMOw9vsz70WMHzt8X8jiX358Jv9KYrMOHpkHE6jpb8CTvGabgIJUPkX_4" | ||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yIPQsVOchQDQz1RMA==" | ||
|
||
val publicKey = ecPublicKeyBase64.base64UrlDecodedBytes | ||
val message = messageBase64.encodeToByteArray() | ||
|
||
assertTrue { | ||
Secp256k1Lib().verify( | ||
publicKey, | ||
rawSignatureBase64.base64UrlDecodedBytes, | ||
message | ||
) | ||
} | ||
|
||
assertTrue { | ||
Secp256k1Lib().verify( | ||
publicKey, | ||
swiftSignatureBase64.base64UrlDecodedBytes, | ||
message | ||
) | ||
} | ||
|
||
assertTrue { | ||
Secp256k1Lib().verify( | ||
publicKey, | ||
nimbusDerSignatureBase64.base64UrlDecodedBytes, | ||
message | ||
) | ||
} | ||
} | ||
|
||
} |