Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/LDG-516--nano-ap…
Browse files Browse the repository at this point in the history
…p-implement-exportprivatekey-method
  • Loading branch information
keiff3r committed Dec 10, 2024
2 parents b36a6b0 + 2d8a950 commit c234921
Show file tree
Hide file tree
Showing 93 changed files with 294 additions and 1 deletion.
60 changes: 59 additions & 1 deletion src/common/ui/display_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "glyphs.h"
#include "menu.h"
#include "getPublicKey.h"
#include "util.h"
#include "sign.h"

#include "nbgl_use_case.h"
accountSender_t global_account_sender;
Expand Down Expand Up @@ -60,8 +62,64 @@ void startConfigureBakerUrlDisplay(bool lastUrlPage) {
// TODO: Implement this
}

// TODO: To fix
void startConfigureDelegationDisplay(void) {
// TODO: Implement this
// Get context from global state
signConfigureDelegationContext_t *ctx = &global.signConfigureDelegation;

// Create tag-value pairs for the content
nbgl_layoutTagValue_t pairs[4]; // Maximum possible pairs
uint8_t pairIndex = 0;

// Add sender address
pairs[pairIndex].item = "Sender";
pairs[pairIndex].value = (char *) global_account_sender.sender;
pairIndex++;

// Add capital amount if present
if (ctx->hasCapital) {
if (ctx->stopDelegation) {
pairs[pairIndex].item = "Action";
pairs[pairIndex].value = "Stop delegation";
} else {
pairs[pairIndex].item = "Amount to delegate";
pairs[pairIndex].value = (char *) ctx->displayCapital;
}
pairIndex++;
}

// Add restake earnings if present
if (ctx->hasRestakeEarnings) {
pairs[pairIndex].item = "Restake earnings";
pairs[pairIndex].value = (char *) ctx->displayRestake;
pairIndex++;
}

// Add delegation target if present
if (ctx->hasDelegationTarget) {
pairs[pairIndex].item = "Delegation target";
pairs[pairIndex].value = (char *) ctx->displayDelegationTarget;
pairIndex++;
}

// Create the page content
nbgl_pageContent_t content;
content.type = TAG_VALUE_LIST;
content.title = "Review Transaction";
content.isTouchableTitle = true;
content.topRightIcon = NULL;
content.tagValueList.nbPairs = pairIndex;
content.tagValueList.pairs = pairs;
content.tagValueList.smallCaseForValue = false;
content.tagValueList.nbMaxLinesForValue = 0;

// Setup the review screen
nbgl_useCaseReviewStart(&C_app_concordium_64px,
"Review Transaction",
NULL, // No subtitle
"Reject transaction",
buildAndSignTransactionHash,
sendUserRejection);
}

void uiSignUpdateCredentialThresholdDisplay(volatile unsigned int *flags) {
Expand Down
16 changes: 16 additions & 0 deletions tests/application_client/boilerplate_command_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,22 @@ def sign_tx_with_schedule_and_memo_part_3(
) as response:
yield response

@contextmanager
def sign_configure_delegation(
self, path: str, transaction: bytes
) -> Generator[None, None, None]:
data = pack_derivation_path(path)
data += transaction

with self.backend.exchange_async(
cla=CLA,
ins=InsType.CONFIGURE_DELEGATION,
p1=P1.P1_NONE,
p2=P2.P2_NONE,
data=data,
) as response:
yield response

# @contextmanager
# def sign_tx(
# self, path: str, tx_type_ins: InsType, transaction: bytes
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
219 changes: 219 additions & 0 deletions tests/test_configure_delegation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
import pytest

from application_client.boilerplate_command_sender import BoilerplateCommandSender
from utils import navigate_until_text_and_compare


# In these tests we send to the device a transaction to sign and validate it on screen
# The transactions are short and will be sent in one chunk
# We will ensure that the displayed information is correct by using screenshots comparison

@pytest.mark.active_test_scope
def test_sign_configure_delegation_capital(
backend, firmware, navigator, default_screenshot_path, test_name
):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
path: str = "m/44/919/0/0/0/0"

# Create the transaction that will be sent to the device for signing
transaction = "20a845815bd43a1999e90fbf971537a70392eb38f89e6bd32b3dd70e1a9551d7000000000000000a0000000000000064000000290000000063de5da71a00010000ffffffffffff"
transaction = bytes.fromhex(transaction)

# Send the sign device instruction.
# As it requires on-screen validation, the function is asynchronous.
# It will yield the result when the navigation is done
with client.sign_configure_delegation(path=path, transaction=transaction):
# Validate the on-screen request by performing the navigation appropriate for this device
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name
)

# The device as yielded the result, parse it and ensure that the signature is correct
response = client.get_async_response().data
response_hex = response.hex()
print("response", response_hex)
assert (
response_hex
== "91f6646bed5597d32c9ecbb31795b9ecb93963063bd804549e66c66eafa44b8eb17984b11c5770a302d0dfb0acb9f821e85a1e60bd1485f09fa6391a40118d00"
)

@pytest.mark.active_test_scope
def test_sign_configure_delegation_stop_delegation(
backend, firmware, navigator, default_screenshot_path, test_name
):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
path: str = "m/44/919/0/0/0/0"

# Create the transaction that will be sent to the device for signing
transaction = "20a845815bd43a1999e90fbf971537a70392eb38f89e6bd32b3dd70e1a9551d7000000000000000a0000000000000064000000290000000063de5da71a00010000000000000000"
transaction = bytes.fromhex(transaction)

# Send the sign device instruction.
# As it requires on-screen validation, the function is asynchronous.
# It will yield the result when the navigation is done
with client.sign_configure_delegation(path=path, transaction=transaction):
# Validate the on-screen request by performing the navigation appropriate for this device
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name
)

# The device as yielded the result, parse it and ensure that the signature is correct
response = client.get_async_response().data
response_hex = response.hex()
print("response", response_hex)
assert (
response_hex
== "b68d17594f23337afa2778ffb7a784a1c3986e216f6ad5a9d8a3a7b914dd0bf148c096167f441cbce3a7e3870d2985a8144a3eba457f2abe51a340e90363a901"
)

@pytest.mark.active_test_scope
def test_sign_configure_delegation_restake(
backend, firmware, navigator, default_screenshot_path, test_name
):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
path: str = "m/44/919/0/0/0/0"

# Create the transaction that will be sent to the device for signing
transaction = "20a845815bd43a1999e90fbf971537a70392eb38f89e6bd32b3dd70e1a9551d7000000000000000a0000000000000064000000290000000063de5da71a000201"
transaction = bytes.fromhex(transaction)

# Send the sign device instruction.
# As it requires on-screen validation, the function is asynchronous.
# It will yield the result when the navigation is done
with client.sign_configure_delegation(path=path, transaction=transaction):
# Validate the on-screen request by performing the navigation appropriate for this device
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name
)

# The device as yielded the result, parse it and ensure that the signature is correct
response = client.get_async_response().data
response_hex = response.hex()
print("response", response_hex)
assert (
response_hex
== "b981185bdd6a26e9371ae7045eecf7206069d9b3fe350a4a32e23c94f30127785bb33743d959bd5a0548aba9b5dee1bfe83c9061d803d2e0344831a0996c7007"
)

@pytest.mark.active_test_scope
def test_sign_configure_delegation_target(
backend, firmware, navigator, default_screenshot_path, test_name
):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
path: str = "m/44/919/0/0/0/0"

# Create the transaction that will be sent to the device for signing
transaction = "20a845815bd43a1999e90fbf971537a70392eb38f89e6bd32b3dd70e1a9551d7000000000000000a0000000000000064000000290000000063de5da71a00040100000000abcdefff"
transaction = bytes.fromhex(transaction)

# Send the sign device instruction.
# As it requires on-screen validation, the function is asynchronous.
# It will yield the result when the navigation is done
with client.sign_configure_delegation(path=path, transaction=transaction):
# Validate the on-screen request by performing the navigation appropriate for this device
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name
)

# The device as yielded the result, parse it and ensure that the signature is correct
response = client.get_async_response().data
response_hex = response.hex()
print("response", response_hex)
assert (
response_hex
== "b639ca39861fc3cd9b569b16a778dc69389c9e70bc536cc0e0c4bc70751e3d8239f59c7298fd6b5a3648081a01ce232bc32edabf2b9fffdaf8a677bc2930aa0e"
)

@pytest.mark.active_test_scope
def test_sign_configure_delegation_capital_target(
backend, firmware, navigator, default_screenshot_path, test_name
):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
path: str = "m/44/919/0/0/0/0"

# Create the transaction that will be sent to the device for signing
transaction = "20a845815bd43a1999e90fbf971537a70392eb38f89e6bd32b3dd70e1a9551d7000000000000000a0000000000000064000000290000000063de5da71a00050000ffffffffffff0100000000abcdefff"
transaction = bytes.fromhex(transaction)

# Send the sign device instruction.
# As it requires on-screen validation, the function is asynchronous.
# It will yield the result when the navigation is done
with client.sign_configure_delegation(path=path, transaction=transaction):
# Validate the on-screen request by performing the navigation appropriate for this device
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name
)

# The device as yielded the result, parse it and ensure that the signature is correct
response = client.get_async_response().data
response_hex = response.hex()
print("response", response_hex)
assert (
response_hex
== "7577ec2c11776977e15197954ff48a9df675b7e1ecd778d4ec2de8bb31c1b04fd3b5a65bc9711ce8d1ffc9ee1dd8333f235f7d43c8ca27e1e3f02d9e4d9b3508"
)

@pytest.mark.active_test_scope
def test_sign_configure_delegation_capital_restake_target(
backend, firmware, navigator, default_screenshot_path, test_name
):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
path: str = "m/44/919/0/0/0/0"

# Create the transaction that will be sent to the device for signing
transaction = "20a845815bd43a1999e90fbf971537a70392eb38f89e6bd32b3dd70e1a9551d7000000000000000a0000000000000064000000290000000063de5da71a00070000ffffffffffff010100000000abcdefff"
transaction = bytes.fromhex(transaction)

# Send the sign device instruction.
# As it requires on-screen validation, the function is asynchronous.
# It will yield the result when the navigation is done
with client.sign_configure_delegation(path=path, transaction=transaction):
# Validate the on-screen request by performing the navigation appropriate for this device
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name
)

# The device as yielded the result, parse it and ensure that the signature is correct
response = client.get_async_response().data
response_hex = response.hex()
print("response", response_hex)
assert (
response_hex
== "6b5f0920d7d5abee49148514e67d2054e844c109e8e8cf3f4ce7fce69a71d0d61be185d3d90fed8c13e0cc3c87db972a8635ae9455550ff4ffa57dfef12cdb08"
)

@pytest.mark.active_test_scope
def test_sign_configure_delegation_passive_delegation(
backend, firmware, navigator, default_screenshot_path, test_name
):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
path: str = "m/44/919/0/0/0/0"

# Create the transaction that will be sent to the device for signing
transaction = "20a845815bd43a1999e90fbf971537a70392eb38f89e6bd32b3dd70e1a9551d7000000000000000a0000000000000064000000290000000063de5da71a000400"
transaction = bytes.fromhex(transaction)

# Send the sign device instruction.
# As it requires on-screen validation, the function is asynchronous.
# It will yield the result when the navigation is done
with client.sign_configure_delegation(path=path, transaction=transaction):
# Validate the on-screen request by performing the navigation appropriate for this device
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name
)

# The device as yielded the result, parse it and ensure that the signature is correct
response = client.get_async_response().data
response_hex = response.hex()
print("response", response_hex)
assert (
response_hex
== "374719c3038f1fe8f7edd8254b6e79e0c91dc3ed5cc7c344bb3cd906068b5b9da3ef19c70b52e39fcf1e3697670769a6c8a751525d28a2ea4a75d9201191d906"
)

0 comments on commit c234921

Please sign in to comment.