Skip to content

Commit

Permalink
SFT-1708: trying to use existing bip340 micropython module
Browse files Browse the repository at this point in the history
  • Loading branch information
mjg-foundation committed Sep 27, 2023
1 parent 935f394 commit 4eda91a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ STATIC const mp_rom_map_elem_t mp_module_trezorcrypto_globals_table[] = {
MP_ROM_PTR(&mod_trezorcrypto_Ripemd160_type)},
{MP_ROM_QSTR(MP_QSTR_secp256k1),
MP_ROM_PTR(&mod_trezorcrypto_secp256k1_module)},
#ifndef FOUNDATION_ADDITIONS
{MP_ROM_QSTR(MP_QSTR_bip340), MP_ROM_PTR(&mod_trezorcrypto_bip340_module)},
#ifndef FOUNDATION_ADDITIONS
{MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&mod_trezorcrypto_Sha1_type)},
#endif // FOUNDATION_ADDITIONS
{MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&mod_trezorcrypto_Sha256_type)},
Expand Down
26 changes: 15 additions & 11 deletions ports/stm32/boards/Passport/modules/chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,24 @@ def address(cls, node, addr_fmt):
# bech32 encoded segwit p2pkh
return tcc.codecs.bech32_encode(cls.bech32_hrp, 0, raw)
elif addr_fmt & AFC_BECH32M:
from utils import precomputed_tagged_hash
from ubinascii import unhexlify as a2b_hex
# from utils import precomputed_tagged_hash
# from ubinascii import unhexlify as a2b_hex
from ubinascii import hexlify as b2a_hex
from trezorcrypto import ecdsa
# from trezorcrypto import ecdsa
from trezorcrypto import bip340

print("here 1")
tap_tweak_sha256 = a2b_hex("e80fe1639c9ca050e3af1b39c143c63e429cbceb15d940fbb5c5a1f4af57c5e9")
print("here 2")
tweaked = bip340.tweak_public_key(node.public_key())
print(b2a_hex(tweaked))

x = ecdsa.get_x(node.public_key())
print("here 3")
print(b2a_hex(x))
print("here 4")
hash_tap_tweaked_pubkey = precomputed_tagged_hash(tap_tweak_sha256, x)
# print("here 1")
# tap_tweak_sha256 = a2b_hex("e80fe1639c9ca050e3af1b39c143c63e429cbceb15d940fbb5c5a1f4af57c5e9")
# print("here 2")

# x = ecdsa.get_x(node.public_key())
# print("here 3")
# print(b2a_hex(x))
# print("here 4")
# hash_tap_tweaked_pubkey = precomputed_tagged_hash(tap_tweak_sha256, x)
# point = lift_x(pubkey) + hash_tap_tweaked_pubkey * secp256k1_generator()
# tweaked_pubkey = point.x()
return tcc.codecs.bech32_encode(cls.bech32_hrp, 1, raw)
Expand Down

0 comments on commit 4eda91a

Please sign in to comment.