Bad return code -1 when running client.get_public_key

Hello! I’m using a HSM6 and hoping to follow the digital wallet tutorial, but I’m running into issues

Setup:
Raspberry Pi 4 running Bullseye
HSM6

I followed the getting started guide, most things seem OK, the LED blinks every three seconds and so on.

When I run zk_crypto_test.py it passes, but when I run zk_app_utils_test.py it fails with

Testing get_ecdsa_public_key()...
Traceback (most recent call last):
  File "/home/pi/zk_app_utils_test.py", line 45, in <module>
    pk = zymkey.client.get_ecdsa_public_key()
  File "/usr/local/lib/python3.9/dist-packages/zymkey/__init__.py", line 978, in get_ecdsa_public_key
    raise AssertionError("bad return code %d" % ret)
AssertionError: bad return code -1

After some digging, I found I can reproduce this with a minimal example

import zymkey
zymkey_pub_key_slot = zymkey.client.gen_key_pair("secp256k1")
zymkey.client.get_ecdsa_public_key(zymkey_pub_key_slot)

Any ideas? I tried both install scripts from “Getting Started” but no joy.

I get the same issue with get_public_key() as get_ecdsa_public_key()

I’m assuming your LED is still blinking once every three seconds. Can you print the slot number and slot allocation? Try this:

pi@raspberrypi $ python3
Python 3.9.2 (default, Mar 12 2021, 04:06:34)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import zymkey
>>> slot = zymkey.client.gen_key_pair("secp256k1")
>>> zymkey.client.get_public_key(slot)
bytearray(b"\xf0\x06h\xd8\xea\xc6.\x91\x7f\xa6\x93^<\xdeyx\xe6\xa3\xaf|\xf9\xcb\xfc:\xcbj-K\x8b\xb2\x1f\xb6MC\xc8:\xee\x82gk\xf7l\xc1\x07\xde)$\xdeq\xc8c\x16qa@\xecj\xc8\x00\x02\xe9+\'$")
>>> print(slot)
19
>>> zymkey.client.get_slot_alloc_list()
([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, 17, 18, 19], 528)
>>>

@shanet - Can you also verify your firmware revision for me?

python3 -c "import zymkey; print(zymkey.client.get_firmware_version())"

I’m assuming your LED is still blinking once every three seconds.

It is indeed!

Can you print the slot number and slot allocation? Try this:

I hope this is useful:

>>> slot = zymkey.client.gen_key_pair("secp256k1")
>>> zymkey.client.get_public_key(slot)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/zymkey/__init__.py", line 1012, in get_public_key
    raise AssertionError("bad return code %d" % ret)
AssertionError: bad return code -1
>>> print(slot)
23
>>> zymkey.client.get_slot_alloc_list()
([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, 17, 18, 19, 20, 21, 22, 23], 528)
>>> 

@shanet - Can you also verify your firmware revision for me?

06.00.16Rel

This is interesting - I wonder if it needs to be / can be updated?

@shanet That is indeed a very early unit. It is not field upgradeable. We’ll send you an up-to-date replacement unit.

Thanks very much @Bob_of_Zymbit !