Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(secp256k1): add library to be our dependency for secp256k1 iOS, macos, jvm, android, js #77

Merged
merged 1 commit into from
Jul 13, 2023

Conversation

goncalo-frade-iohk
Copy link
Contributor

add library for secp256k1 in iOS, macOS
add libraries for secp256k1 in JVM/Android and removed bouncy castle secp256k1 add new implementation of secp256k1 in common

@atala-dev
Copy link
Contributor

atala-dev commented Jul 10, 2023

🦙 MegaLinter status: ⚠️ WARNING

Descriptor Linter Files Fixed Errors Elapsed time
✅ ACTION actionlint 1 0 0.07s
⚠️ BASH bash-exec 4 1 0.01s
⚠️ BASH shfmt 4 3 0.02s
✅ EDITORCONFIG editorconfig-checker 51 0 0.17s
✅ KOTLIN ktlint 42 0 73.5s
⚠️ REPOSITORY devskim yes 6 0.85s
✅ REPOSITORY dustilock yes no 0.28s
✅ REPOSITORY git_diff yes no 0.02s
✅ REPOSITORY secretlint yes no 2.99s
✅ REPOSITORY syft yes no 0.39s
✅ REPOSITORY trivy yes no 3.99s
✅ YAML prettier 1 0 0.46s
✅ YAML v8r 1 0 2.41s
✅ YAML yamllint 1 0 0.36s

See detailed report in MegaLinter reports
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security

@goncalo-frade-iohk goncalo-frade-iohk force-pushed the feature/ATL-5164 branch 12 times, most recently from 7189fca to cdc2fd1 Compare July 10, 2023 16:54
Copy link
Contributor

@curtis-h curtis-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is awesome (mostly over my head), lots of commented code that I think could be removed, and got a couple of questions about naming

@@ -0,0 +1,8 @@
package io.iohk.atala.prism.apollo.secp256k1

expect class Secp256k1Lib constructor() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering why this is named as a "Lib" instead of "KeyPair"? should we adopt this for the others or is there a distinction being implied?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove completely KeyPair. It doesn't make much sense.

A PrivateKey should create a Public Key by getPublicKey(): ByteArray

This is more straightforward process.

Secp256k1Lib is because it uses dependency libs different in each platform to achieve the same. We could call it other way don't mind

Comment on lines 4 to 8
// @JsName("fromBigIntegersStrings")
// constructor(x: String, y: String) : this(KMMECCoordinate(BigInteger.parseString(x)), KMMECCoordinate(BigInteger.parseString(y)))

@OptIn(ExperimentalJsExport::class)
@JsExport
data class KMMECPoint(val x: KMMECCoordinate, val y: KMMECCoordinate) {
@JsName("fromBigIntegersStrings")
constructor(x: String, y: String) : this(KMMECCoordinate(BigInteger.parseString(x)), KMMECCoordinate(BigInteger.parseString(y)))

@JsName("fromBigIntegers")
constructor(x: BigInteger, y: BigInteger) : this(KMMECCoordinate(x), KMMECCoordinate(y))
// @JsName("fromBigIntegers")
// constructor(x: ByteArray, y: BigInteger) : this(KMMECCoordinate(x), KMMECCoordinate(y))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just remove this commented out code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


companion object : KMMECSecp256k1PublicKeyCommonStaticInterface

fun getEncodedCompressed(): ByteArray {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be getEncoded to be consistent with the others?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just for EC keys so Secp256k1, the Ed25519 and X25519 I don't think share the same feature.

Copy link
Contributor Author

@goncalo-frade-iohk goncalo-frade-iohk Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I actually deleted it since we raw should be enough. Probably we should just have raw for all.

// KMMECSecp256k1PublicKey.secp256k1FromBigIntegerCoordinates(tv.point.x.coordinate, tv.point.y.coordinate)
// }
// }
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason not to remove commented code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I will have a look on comments before I merge. I just wanted to see first it actually build on the CI 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed


@OptIn(ExperimentalJsExport::class)
@JsExport
class KMMECSecp256k1PrivateKeyJS {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guessing I'm missing something, but why have the JS suffix here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for any JS exported you will unfortunately have to create a wrapper. Since ByteArray is not available, you need to create a wrapper that exports BN or Buffer instead of ByteArray and this wrapper converts it.

We can actually name the class in KMM for JS, so although in Kotlin it shows KMMECSecp256k1PrivateKeyJS we can say to KMM to call this on JS as KMMECSecp256k1PrivateKey that's the plan.

But bare in mind we still need to test if the API is showing correctly and appealing in JS :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah after our talk I removed the wrappers they are not needed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to keep it all commented out? Can't we delete the file altogether?

Copy link
Contributor Author

@goncalo-frade-iohk goncalo-frade-iohk Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the file

Comment on lines 226 to 227
// protected fun MemScope.allocPrivateKey(privkey: ByteArray): secp256k1_pubkey {
// val natPriv = toNat(privkey)
// val pub = alloc<secp256k1_>()
// secp256k1_ec_pubkey_parse(
// ctx,
// pub.ptr,
// natPub,
// pubkey.size.convert()
// ).requireSuccess("secp256k1_ec_pubkey_parse() failed")
// return pub
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to keep this commented? Can be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can delete it, I just really wanted to have this all passing and ready to merge to be sure that im not missing something :)

@goncalo-frade-iohk goncalo-frade-iohk force-pushed the feature/ATL-5164 branch 5 times, most recently from 94cedff to 6154217 Compare July 13, 2023 10:34
…droid, jvm, ios, macos, js

add library for secp256k1 in iOS, macOS
add libraries for secp256k1 in JVM/Android and removed bouncy castle secp256k1
add new implementation of secp256k1 in common
Copy link
Contributor

@cristianIOHK cristianIOHK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@goncalo-frade-iohk goncalo-frade-iohk changed the title feat(secp256k1): add library to be our dependency for secp256k1 in js feat(secp256k1): add library to be our dependency for secp256k1 iOS, macos, jvm, android, js Jul 13, 2023
@goncalo-frade-iohk goncalo-frade-iohk merged commit 9121f60 into main Jul 13, 2023
@goncalo-frade-iohk goncalo-frade-iohk deleted the feature/ATL-5164 branch July 13, 2023 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants