Skip to content

Commit

Permalink
feat: move of display to dedicated bagl section
Browse files Browse the repository at this point in the history
  • Loading branch information
n4l5u0r committed Dec 4, 2024
1 parent 2b1a4af commit 05697d8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 36 deletions.
36 changes: 4 additions & 32 deletions src/common/getPublicKey.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "responseCodes.h"
#include "util.h"
#include "ux.h"
#include "display.h"

static keyDerivationPath_t *keyPath = &path;
static exportPublicKeyContext_t *ctx = &global.exportPublicKeyContext;
Expand All @@ -12,30 +13,6 @@ static const uint32_t HARDENED_OFFSET = 0x80000000;

instructionContext global;

void sendPublicKey(bool compare);

UX_STEP_VALID(ux_decline_step, pb, sendUserRejection(), {&C_icon_crossmark, "Decline"});

// UI definitions for the approval of the generation of a public-key. This prompts the user to
// accept that a public-key will be generated and returned to the computer.
UX_STEP_VALID(ux_generate_public_flow_0_step,
pnn,
sendPublicKey(true),
{&C_icon_validate_14, "Public key", (char *) global.exportPublicKeyContext.display});
UX_FLOW(ux_generate_public_flow, &ux_generate_public_flow_0_step, &ux_decline_step, FLOW_LOOP);

// UI definitions for comparison of public-key on the device
// with the public-key that the caller received.
UX_STEP_NOCB(ux_sign_compare_public_key_0_step,
bnnn_paging,
{.title = "Compare", .text = (char *) global.exportPublicKeyContext.publicKey});
UX_STEP_CB(ux_compare_accept_step, pb, ui_menu_main(), {&C_icon_validate_14, "Accept"});
UX_STEP_CB(ux_compare_decline_step, pb, ui_menu_main(), {&C_icon_crossmark, "Decline"});
UX_FLOW(ux_sign_compare_public_key,
&ux_sign_compare_public_key_0_step,
&ux_compare_accept_step,
&ux_compare_decline_step);

/**
* Derive the public-key for the given path, and then write it to
* the APDU buffer to be returned to the caller.
Expand Down Expand Up @@ -68,7 +45,8 @@ void sendPublicKey(bool compare) {
toPaginatedHex(publicKey, sizeof(publicKey), ctx->publicKey, sizeof(ctx->publicKey));
// Allow for receiving a new instruction even while comparing public keys.
tx_state->currentInstruction = -1;
ux_flow_init(0, ux_sign_compare_public_key, NULL);
uiComparePubkey();

} else {
sendSuccess(tx);
}
Expand Down Expand Up @@ -129,12 +107,6 @@ void handleGetPublicKey(uint8_t *cdata, uint8_t p1, uint8_t p2, volatile unsigne
accountIndex);
}
}

// Display the UI for the public-key flow, where the user can validate that the
// public-key being generated is the expected one.
ux_flow_init(0, ux_generate_public_flow, NULL);

// Tell the main process to wait for a button press.
*flags |= IO_ASYNCH_REPLY;
uiGeneratePubkey(flags);
}
}
9 changes: 5 additions & 4 deletions src/common/getPublicKey.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#ifndef _CONCORDIUM_APP_GET_PUBLIC_KEY_H_
#define _CONCORDIUM_APP_GET_PUBLIC_KEY_H_
#pragma once

#include <stdbool.h>
#include <stdint.h>

/**
* Handles the derivation and export of account and governance public keys.
Expand All @@ -10,11 +12,10 @@
* export the signature on the public-key signed with the corresponding private-key.
*/
void handleGetPublicKey(uint8_t *cdata, uint8_t p1, uint8_t p2, volatile unsigned int *flags);
void sendPublicKey(bool compare);

typedef struct {
uint8_t display[21];
char publicKey[68];
bool signPublicKey;
} exportPublicKeyContext_t;

#endif
3 changes: 3 additions & 0 deletions src/common/ui/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ extern const ux_flow_step_t ux_display_memo_step_nocb;
extern const ux_flow_step_t ux_sign_flow_account_sender_view;

#endif

void uiComparePubkey(void);
void uiGeneratePubkey(volatile unsigned int *flags);
36 changes: 36 additions & 0 deletions src/common/ui/display_bagl.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "util.h"
#include "display.h"
#include "globals.h"
#include "menu.h"
#include "getPublicKey.h"

accountSender_t global_account_sender;
static cborContext_t *ctx = &global.withDataBlob.cborContext;
Expand Down Expand Up @@ -126,4 +128,38 @@ void readCborContent(uint8_t *cdata, uint8_t contentLength) {
}
}

// UI definitions for comparison of public-key on the device
// with the public-key that the caller received.
UX_STEP_NOCB(ux_sign_compare_public_key_0_step,
bnnn_paging,
{.title = "Compare", .text = (char *) global.exportPublicKeyContext.publicKey});
UX_STEP_CB(ux_compare_accept_step, pb, ui_menu_main(), {&C_icon_validate_14, "Accept"});
UX_STEP_CB(ux_compare_decline_step, pb, ui_menu_main(), {&C_icon_crossmark, "Decline"});
UX_FLOW(ux_sign_compare_public_key,
&ux_sign_compare_public_key_0_step,
&ux_compare_accept_step,
&ux_compare_decline_step);

void uiComparePubkey(void) {
ux_flow_init(0, ux_sign_compare_public_key, NULL);
}

UX_STEP_VALID(ux_decline_step, pb, sendUserRejection(), {&C_icon_crossmark, "Decline"});

// UI definitions for the approval of the generation of a public-key. This prompts the user to
// accept that a public-key will be generated and returned to the computer.
UX_STEP_VALID(ux_generate_public_flow_0_step,
pnn,
sendPublicKey(true),
{&C_icon_validate_14, "Public key", (char *) global.exportPublicKeyContext.display});
UX_FLOW(ux_generate_public_flow, &ux_generate_public_flow_0_step, &ux_decline_step, FLOW_LOOP);

void uiGeneratePubkey(volatile unsigned int *flags) {
// Display the UI for the public-key flow, where the user can validate that the
// public-key being generated is the expected one.
ux_flow_init(0, ux_generate_public_flow, NULL);

// Tell the main process to wait for a button press.
*flags |= IO_ASYNCH_REPLY;
}
#endif

0 comments on commit 05697d8

Please sign in to comment.