ACINQ / secp256k1-kmp

Kotlin Multi Platform bindings for Bitcoin secp256k1 library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About the Hex functions

KotlinGeekDev opened this issue · comments

Hello maintainers.
Today, I was converting a string to a byte array using one of the Hex functions, and it threw an error, because of a dot(.) in the string. Which brings me to my question: are the Hex functions only for use with private and public key encoding/decoding?

Thanks.

You can use the hex functions with any hex string, it's not at all only for keys. But obviously if you pass in a string that isn't hex, this will throw. A dot isn't a valid hex character, so it's expected that the function throws.

I think what I meant was whether it could be used for converting any string, but the answer is clear now.

That wouldn't make any sense...?

If you mean that you want to convert a string to bytes, this really depends on the encoding you choose, and for arbitrary strings you can use things like ascii, utf-8, etc depending on what characters are allowed to be present in your encoding. But that's a completely different thing from hex encoding, which is used to represent bytes, not arbitrary strings.

Yeah, @t-bast that is what I meant. Sorry for not being clear enough 😅 . I understand better now, thanks.