forked from trezor/trezor-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
39 deletions.
There are no files selected for viewing
33 changes: 20 additions & 13 deletions
33
src/apps/monero/protocol/signing/step_03_inputs_permutation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,39 @@ | ||
""" | ||
Set permutation on the inputs - sorted by key image on host. | ||
Inputs in transaction need to be sorted by their key image, otherwise the | ||
transaction is rejected. The sorting is done on host and then sent here in | ||
the MoneroTransactionInputsPermutationRequest message. | ||
The message contains just a simple array where each item stands for the | ||
input's position in the transaction. | ||
We do not do the actual sorting here (we do not store the complete input | ||
data anyway, so we can't) we just save the array to the state and use | ||
it later when needed. | ||
""" | ||
|
||
from .state import State | ||
|
||
from apps.monero.layout.confirms import transaction_step | ||
from apps.monero.xmr import common | ||
|
||
|
||
async def tsx_inputs_permutation(state: State, permutation): | ||
""" | ||
Set permutation on the inputs - sorted by key image on host. | ||
""" | ||
async def tsx_inputs_permutation(state: State, permutation: list): | ||
from trezor.messages.MoneroTransactionInputsPermutationAck import ( | ||
MoneroTransactionInputsPermutationAck | ||
) | ||
|
||
await transaction_step(state.ctx, state.STEP_PERM) | ||
|
||
_tsx_inputs_permutation(state, permutation) | ||
|
||
return MoneroTransactionInputsPermutationAck() | ||
|
||
|
||
def _tsx_inputs_permutation(state: State, permutation): | ||
""" | ||
Set permutation on the inputs - sorted by key image on host. | ||
""" | ||
state.source_permutation = permutation | ||
common.check_permutation(permutation) | ||
_check_permutation(permutation) | ||
state.current_input_index = -1 | ||
|
||
return MoneroTransactionInputsPermutationAck() | ||
|
||
|
||
def _check_permutation(permutation): | ||
for n in range(len(permutation)): | ||
if n not in permutation: | ||
raise ValueError("Invalid permutation") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters