mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 09:28:13 +00:00
nem: multisig
This commit is contained in:
parent
d54d33df3a
commit
b80a8022d0
@ -6,8 +6,12 @@ from trezor.crypto import nem
|
|||||||
|
|
||||||
|
|
||||||
async def ask_multisig(ctx, msg: NEMSignTx):
|
async def ask_multisig(ctx, msg: NEMSignTx):
|
||||||
# todo
|
address = nem.compute_address(msg.multisig.signer, msg.transaction.network)
|
||||||
await require_confirm_action(ctx, 'Multisig?')
|
if msg.cosigning:
|
||||||
|
await require_confirm_address(ctx, 'Cosign transaction for', address)
|
||||||
|
else:
|
||||||
|
await require_confirm_address(ctx, 'Initiate transaction for', address)
|
||||||
|
await require_confirm_fee(ctx, 'Confirm multisig fee', msg.multisig.fee)
|
||||||
|
|
||||||
|
|
||||||
async def ask_aggregate_modification(ctx, msg: NEMSignTx):
|
async def ask_aggregate_modification(ctx, msg: NEMSignTx):
|
||||||
@ -38,8 +42,10 @@ def serialize_multisig(msg: NEMTransactionCommon, public_key: bytes, inner: byte
|
|||||||
return w
|
return w
|
||||||
|
|
||||||
|
|
||||||
def serialize_multisig_signature(msg: NEMTransactionCommon, public_key: bytes, inner: bytes, address: str):
|
def serialize_multisig_signature(common: NEMTransactionCommon, public_key: bytes,
|
||||||
w = write_common(msg, bytearray(public_key), NEM_TRANSACTION_TYPE_MULTISIG_SIGNATURE)
|
inner: bytes, address_public_key: bytes):
|
||||||
|
address = nem.compute_address(address_public_key, common.network)
|
||||||
|
w = write_common(common, bytearray(public_key), NEM_TRANSACTION_TYPE_MULTISIG_SIGNATURE)
|
||||||
digest = hashlib.sha3_256(inner).digest(True)
|
digest = hashlib.sha3_256(inner).digest(True)
|
||||||
|
|
||||||
write_uint32(w, 4 + len(digest))
|
write_uint32(w, 4 + len(digest))
|
||||||
|
@ -16,6 +16,7 @@ async def sign_tx(ctx, msg: NEMSignTx):
|
|||||||
|
|
||||||
if msg.multisig:
|
if msg.multisig:
|
||||||
public_key = msg.multisig.signer
|
public_key = msg.multisig.signer
|
||||||
|
await ask_multisig(ctx, msg)
|
||||||
else:
|
else:
|
||||||
public_key = _get_public_key(node)
|
public_key = _get_public_key(node)
|
||||||
|
|
||||||
@ -35,6 +36,10 @@ async def sign_tx(ctx, msg: NEMSignTx):
|
|||||||
else:
|
else:
|
||||||
raise ValueError('No transaction provided')
|
raise ValueError('No transaction provided')
|
||||||
|
|
||||||
|
if msg.multisig:
|
||||||
|
# wrap transaction in multisig wrapper
|
||||||
|
tx = _multisig(node, msg, tx)
|
||||||
|
|
||||||
signature = ed25519.sign(node.private_key(), tx, helpers.NEM_HASH_ALG)
|
signature = ed25519.sign(node.private_key(), tx, helpers.NEM_HASH_ALG)
|
||||||
|
|
||||||
resp = NEMSignedTx()
|
resp = NEMSignedTx()
|
||||||
@ -43,6 +48,16 @@ async def sign_tx(ctx, msg: NEMSignTx):
|
|||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
def _multisig(node, msg: NEMSignTx, inner_tx: bytes) -> bytes:
|
||||||
|
if msg.cosigning:
|
||||||
|
return serialize_multisig_signature(msg.multisig,
|
||||||
|
_get_public_key(node),
|
||||||
|
inner_tx,
|
||||||
|
msg.multisig.signer)
|
||||||
|
else:
|
||||||
|
return serialize_multisig(msg.multisig, _get_public_key(node), inner_tx)
|
||||||
|
|
||||||
|
|
||||||
def _get_public_key(node) -> bytes:
|
def _get_public_key(node) -> bytes:
|
||||||
# 0x01 prefix is not part of the actual public key, hence removed
|
# 0x01 prefix is not part of the actual public key, hence removed
|
||||||
return node.public_key()[1:]
|
return node.public_key()[1:]
|
||||||
@ -75,10 +90,7 @@ async def _supply_change(ctx, public_key: bytes, msg: NEMSignTx):
|
|||||||
|
|
||||||
async def _aggregate_modification(ctx, public_key: bytes, msg: NEMSignTx):
|
async def _aggregate_modification(ctx, public_key: bytes, msg: NEMSignTx):
|
||||||
await ask_aggregate_modification(ctx, msg)
|
await ask_aggregate_modification(ctx, msg)
|
||||||
if not msg.multisig:
|
|
||||||
w = serialize_aggregate_modification(msg, public_key)
|
w = serialize_aggregate_modification(msg, public_key)
|
||||||
else:
|
|
||||||
w = bytearray() # todo
|
|
||||||
|
|
||||||
for m in msg.aggregate_modification.modifications:
|
for m in msg.aggregate_modification.modifications:
|
||||||
serialize_cosignatory_modification(w, m.type, m.public_key)
|
serialize_cosignatory_modification(w, m.type, m.public_key)
|
||||||
|
@ -29,12 +29,12 @@ class TestNemMultisig(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(multisig, unhexlify("0410000001000098df1a3c002000000059d89076964742ef2a2089d26a5aa1d2c7a7bb052a46c1de159891e91ad3d76e808d5b00000000003f6f3c006c0000000110000001000098df1a3c0020000000abac2ee3d4aaa7a3bfb65261a00cc04c761521527dd3f2cf741e2815cbba83ac0024f400000000003f6f3c0001000000280000000200000020000000e6cff9b3725a91f31089c3acca0fac3e341c00b1c8c6e9578f66c4514509c3b3"))
|
self.assertEqual(multisig, unhexlify("0410000001000098df1a3c002000000059d89076964742ef2a2089d26a5aa1d2c7a7bb052a46c1de159891e91ad3d76e808d5b00000000003f6f3c006c0000000110000001000098df1a3c0020000000abac2ee3d4aaa7a3bfb65261a00cc04c761521527dd3f2cf741e2815cbba83ac0024f400000000003f6f3c0001000000280000000200000020000000e6cff9b3725a91f31089c3acca0fac3e341c00b1c8c6e9578f66c4514509c3b3"))
|
||||||
|
|
||||||
address = "TCRXYUQIMFA7AOGL5LF3YWLC7VABLYUMJ5ACBUNL"
|
address_pubkey = unhexlify("abac2ee3d4aaa7a3bfb65261a00cc04c761521527dd3f2cf741e2815cbba83ac")
|
||||||
m = _create_common_msg(NEM_NETWORK_TESTNET,
|
m = _create_common_msg(NEM_NETWORK_TESTNET,
|
||||||
3939891,
|
3939891,
|
||||||
6000000,
|
6000000,
|
||||||
3961491)
|
3961491)
|
||||||
multisig = serialize_multisig_signature(m, unhexlify("71cba4f2a28fd19f902ba40e9937994154d9eeaad0631d25d525ec37922567d4"), base_tx, address)
|
multisig = serialize_multisig_signature(m, unhexlify("71cba4f2a28fd19f902ba40e9937994154d9eeaad0631d25d525ec37922567d4"), base_tx, address_pubkey)
|
||||||
|
|
||||||
self.assertEqual(multisig, unhexlify("0210000001000098331e3c002000000071cba4f2a28fd19f902ba40e9937994154d9eeaad0631d25d525ec37922567d4808d5b000000000093723c0024000000200000008ec165580bdabfd31ce6007a1748ce5bdf30eab7a214743097de3bc822ac7e002800000054435258595551494d464137414f474c354c463359574c43375641424c59554d4a35414342554e4c"))
|
self.assertEqual(multisig, unhexlify("0210000001000098331e3c002000000071cba4f2a28fd19f902ba40e9937994154d9eeaad0631d25d525ec37922567d4808d5b000000000093723c0024000000200000008ec165580bdabfd31ce6007a1748ce5bdf30eab7a214743097de3bc822ac7e002800000054435258595551494d464137414f474c354c463359574c43375641424c59554d4a35414342554e4c"))
|
||||||
|
|
||||||
@ -62,16 +62,15 @@ class TestNemMultisig(unittest.TestCase):
|
|||||||
59414342,
|
59414342,
|
||||||
6000000,
|
6000000,
|
||||||
59500742)
|
59500742)
|
||||||
address = "NDDRG3UEB5LZZZMDWBE4RTKZK73JBHPAIWBHCFMV"
|
address_pubkey = unhexlify("a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a")
|
||||||
multisig = serialize_multisig_signature(m, unhexlify("1b49b80203007117d034e45234ffcdf402c044aeef6dbb06351f346ca892bce2"), base_tx, address)
|
multisig = serialize_multisig_signature(m, unhexlify("1b49b80203007117d034e45234ffcdf402c044aeef6dbb06351f346ca892bce2"), base_tx, address_pubkey)
|
||||||
self.assertEqual(multisig, unhexlify("021000000100006846978a03200000001b49b80203007117d034e45234ffcdf402c044aeef6dbb06351f346ca892bce2808d5b0000000000c6e88b032400000020000000bfa2088f7720f89dd4664d650e321dabd02fab61b7355bc88a391a848a49786a280000004e4444524733554542354c5a5a5a4d445742453452544b5a4b37334a424850414957424843464d56"))
|
self.assertEqual(multisig, unhexlify("021000000100006846978a03200000001b49b80203007117d034e45234ffcdf402c044aeef6dbb06351f346ca892bce2808d5b0000000000c6e88b032400000020000000bfa2088f7720f89dd4664d650e321dabd02fab61b7355bc88a391a848a49786a280000004e4444524733554542354c5a5a5a4d445742453452544b5a4b37334a424850414957424843464d56"))
|
||||||
|
|
||||||
m = _create_common_msg(NEM_NETWORK_MAINNET,
|
m = _create_common_msg(NEM_NETWORK_MAINNET,
|
||||||
59414381,
|
59414381,
|
||||||
6000000,
|
6000000,
|
||||||
59500781)
|
59500781)
|
||||||
address = "NDDRG3UEB5LZZZMDWBE4RTKZK73JBHPAIWBHCFMV"
|
multisig = serialize_multisig_signature(m, unhexlify("7ba4b39209f1b9846b098fe43f74381e43cb2882ccde780f558a63355840aa87"), base_tx, address_pubkey)
|
||||||
multisig = serialize_multisig_signature(m, unhexlify("7ba4b39209f1b9846b098fe43f74381e43cb2882ccde780f558a63355840aa87"), base_tx, address)
|
|
||||||
self.assertEqual(multisig, unhexlify("02100000010000686d978a03200000007ba4b39209f1b9846b098fe43f74381e43cb2882ccde780f558a63355840aa87808d5b0000000000ede88b032400000020000000bfa2088f7720f89dd4664d650e321dabd02fab61b7355bc88a391a848a49786a280000004e4444524733554542354c5a5a5a4d445742453452544b5a4b37334a424850414957424843464d56"))
|
self.assertEqual(multisig, unhexlify("02100000010000686d978a03200000007ba4b39209f1b9846b098fe43f74381e43cb2882ccde780f558a63355840aa87808d5b0000000000ede88b032400000020000000bfa2088f7720f89dd4664d650e321dabd02fab61b7355bc88a391a848a49786a280000004e4444524733554542354c5a5a5a4d445742453452544b5a4b37334a424850414957424843464d56"))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user