Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: fenidik on July 03, 2018, 09:46:41 AM



Title: Calculationg public key from coordinates
Post by: fenidik on July 03, 2018, 09:46:41 AM
Could anyone help me to realize how to get valid pub key from elliptic curve coordinates?

I get public key coordinates (secp256k1) from hsm device, but I dont understand how to convert these coordinates to pair of  32 hex characters.

"x": "2MDjyVEULe+IJaALKcF1Hon+wbJn7bgklVQq+7Y5WY8=",
"y": "VPdchhpNDZ3efVNVfVpzwn1/FRju4+tjBTWTdOMiXZ0="


Title: Re: Calculationg public key from coordinates
Post by: fenidik on July 03, 2018, 01:12:25 PM
to start the discussion I want to add some thoughts

this HSM coordinates otput is a part of JSON Web Key (https://tools.ietf.org/html/rfc7517 (https://tools.ietf.org/html/rfc7517))

Link below describes that "integers are represented using the base64url encoding of their big-endian representations"

But it's confusing. Cause "2MDjyVEULe+IJaALKcF1Hon+wbJn7bgklVQq+7Y5WY8=" looks like base64, not base64url.


Title: Re: Calculationg public key from coordinates
Post by: fenidik on July 03, 2018, 01:54:52 PM
twimc

I just made base64 decode and encode to hex.  Seems correct

Code:
import base64

x='taf/47/9zBBq1OV+VjtCM3koD0Mav3hrrP0K8ux9Gjk='
y='dg4pB3+BrqyiFQ5HKVBUDw/lcQPrsZ3/ecLvO2dpckc='
print('04'+str(base64.b64decode(x).encode("hex"))+str(base64.b64decode(y).encode("hex")))

output: 04b5a7ffe3bffdcc106ad4e57e563b423379280f431abf786bacfd0af2ec7d1a39760e29077f81a eaca2150e472950540f0fe57103ebb19dff79c2ef3b67697247