Add ETH 2 deposit handling
This commit is contained in:
committed by
TamtamHero
parent
832294334f
commit
7e53de8897
82
src_features/getEth2PublicKey/cmd_getEth2PublicKey.c
Normal file
82
src_features/getEth2PublicKey/cmd_getEth2PublicKey.c
Normal file
@@ -0,0 +1,82 @@
|
||||
#ifdef HAVE_ETH2
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
|
||||
#include "ui_flow.h"
|
||||
#include "feature_getEth2PublicKey.h"
|
||||
|
||||
static const uint8_t BLS12_381_FIELD_MODULUS[] = { 0x1a, 0x01, 0x11, 0xea, 0x39, 0x7f, 0xe6, 0x9a, 0x4b, 0x1b, 0xa7, 0xb6, 0x43, 0x4b, 0xac, 0xd7, 0x64, 0x77, 0x4b, 0x84, 0xf3, 0x85, 0x12, 0xbf, 0x67, 0x30, 0xd2, 0xa0, 0xf6, 0xb0, 0xf6, 0x24, 0x1e, 0xab, 0xff, 0xfe, 0xb1, 0x53, 0xff, 0xff, 0xb9, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xaa, 0xab };
|
||||
|
||||
void getEth2PublicKey(uint32_t *bip32Path, uint8_t bip32PathLength, uint8_t *out) {
|
||||
#if 0
|
||||
uint8_t privateKeyData[32];
|
||||
cx_ecfp_256_extended_private_key_t privateKey;
|
||||
cx_ecfp_384_public_key_t publicKey;
|
||||
uint8_t yFlag = 0;
|
||||
uint8_t tmp[96];
|
||||
|
||||
io_seproxyhal_io_heartbeat();
|
||||
os_perso_derive_eip2333(bip32Path, bip32PathLength, privateKeyData);
|
||||
io_seproxyhal_io_heartbeat();
|
||||
memset(tmp, 0, 48);
|
||||
memmove(tmp + 16, privateKeyData, 32);
|
||||
cx_ecfp_init_private_key(CX_CURVE_BLS12_381_G1, tmp, 48, &privateKey);
|
||||
cx_ecfp_generate_pair(CX_CURVE_BLS12_381_G1, &publicKey, &privateKey, 1);
|
||||
memset(tmp, 0, 96);
|
||||
memset((void*)&privateKey, 0, sizeof(cx_ecfp_256_extended_private_key_t));
|
||||
tmp[47] = 2;
|
||||
cx_math_mult(tmp, publicKey.W + 1 + 48, tmp, 48);
|
||||
if (cx_math_cmp(tmp + 48, BLS12_381_FIELD_MODULUS, 48) > 0) {
|
||||
yFlag = 0x20;
|
||||
}
|
||||
publicKey.W[1] &= 0x1f;
|
||||
publicKey.W[1] |= 0x80 | yFlag;
|
||||
memmove(out, publicKey.W + 1, 48);
|
||||
#endif
|
||||
}
|
||||
|
||||
void handleGetEth2PublicKey(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx) {
|
||||
UNUSED(dataLength);
|
||||
uint32_t bip32Path[MAX_BIP32_PATH];
|
||||
uint32_t i;
|
||||
uint8_t bip32PathLength = *(dataBuffer++);
|
||||
|
||||
if(!called_from_swap){
|
||||
reset_app_context();
|
||||
}
|
||||
if ((bip32PathLength < 0x01) ||
|
||||
(bip32PathLength > MAX_BIP32_PATH)) {
|
||||
PRINTF("Invalid path\n");
|
||||
THROW(0x6a80);
|
||||
}
|
||||
if ((p1 != P1_CONFIRM) && (p1 != P1_NON_CONFIRM)) {
|
||||
THROW(0x6B00);
|
||||
}
|
||||
if (p2 != 0) {
|
||||
THROW(0x6B00);
|
||||
}
|
||||
for (i = 0; i < bip32PathLength; i++) {
|
||||
bip32Path[i] = U4BE(dataBuffer, 0);
|
||||
dataBuffer += 4;
|
||||
}
|
||||
getEth2PublicKey(bip32Path, bip32PathLength, tmpCtx.publicKeyContext.publicKey.W);
|
||||
|
||||
#ifndef NO_CONSENT
|
||||
if (p1 == P1_NON_CONFIRM)
|
||||
#endif // NO_CONSENT
|
||||
{
|
||||
*tx = set_result_get_eth2_publicKey();
|
||||
THROW(0x9000);
|
||||
}
|
||||
#ifndef NO_CONSENT
|
||||
else
|
||||
{
|
||||
ux_flow_init(0, ux_display_public_eth2_flow, NULL);
|
||||
|
||||
*flags |= IO_ASYNCH_REPLY;
|
||||
}
|
||||
#endif // NO_CONSENT
|
||||
}
|
||||
|
||||
#endif
|
||||
4
src_features/getEth2PublicKey/feature_getEth2PublicKey.h
Normal file
4
src_features/getEth2PublicKey/feature_getEth2PublicKey.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#include "shared_context.h"
|
||||
|
||||
uint32_t set_result_get_eth2_publicKey(void);
|
||||
|
||||
13
src_features/getEth2PublicKey/logic_getEth2PublicKey.c
Normal file
13
src_features/getEth2PublicKey/logic_getEth2PublicKey.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifdef HAVE_ETH2
|
||||
|
||||
#include "shared_context.h"
|
||||
|
||||
uint32_t set_result_get_eth2_publicKey() {
|
||||
uint32_t tx = 0;
|
||||
os_memmove(G_io_apdu_buffer + tx, tmpCtx.publicKeyContext.publicKey.W, 48);
|
||||
tx += 48;
|
||||
return tx;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
32
src_features/getEth2PublicKey/ui_common_getEth2PublicKey.c
Normal file
32
src_features/getEth2PublicKey/ui_common_getEth2PublicKey.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifdef HAVE_ETH2
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "feature_getEth2PublicKey.h"
|
||||
#include "ui_callbacks.h"
|
||||
|
||||
unsigned int io_seproxyhal_touch_eth2_address_ok(const bagl_element_t *e) {
|
||||
uint32_t tx = set_result_get_eth2_publicKey();
|
||||
G_io_apdu_buffer[tx++] = 0x90;
|
||||
G_io_apdu_buffer[tx++] = 0x00;
|
||||
reset_app_context();
|
||||
// Send back the response, do not restart the event loop
|
||||
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, tx);
|
||||
// Display back the original UX
|
||||
ui_idle();
|
||||
return 0; // do not redraw the widget
|
||||
}
|
||||
|
||||
#if 0
|
||||
unsigned int io_seproxyhal_touch_eth2_address_cancel(const bagl_element_t *e) {
|
||||
G_io_apdu_buffer[0] = 0x69;
|
||||
G_io_apdu_buffer[1] = 0x85;
|
||||
reset_app_context();
|
||||
// Send back the response, do not restart the event loop
|
||||
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2);
|
||||
// Display back the original UX
|
||||
ui_idle();
|
||||
return 0; // do not redraw the widget
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
50
src_features/getEth2PublicKey/ui_flow_getEth2PublicKey.c
Normal file
50
src_features/getEth2PublicKey/ui_flow_getEth2PublicKey.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifdef HAVE_ETH2
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "ui_callbacks.h"
|
||||
|
||||
void prepare_eth2_public_key() {
|
||||
snprintf(strings.tmp.tmp, 100, "0x%.*H", 48, tmpCtx.publicKeyContext.publicKey.W);
|
||||
}
|
||||
|
||||
UX_STEP_NOCB(
|
||||
ux_display_public_eth2_flow_1_step,
|
||||
pnn,
|
||||
{
|
||||
&C_icon_eye,
|
||||
"Verify ETH2",
|
||||
"public key",
|
||||
});
|
||||
UX_STEP_NOCB_INIT(
|
||||
ux_display_public_eth2_flow_2_step,
|
||||
bnnn_paging,
|
||||
prepare_eth2_public_key(),
|
||||
{
|
||||
.title = "Public Key",
|
||||
.text = strings.tmp.tmp,
|
||||
});
|
||||
UX_STEP_CB(
|
||||
ux_display_public_eth2_flow_3_step,
|
||||
pb,
|
||||
io_seproxyhal_touch_eth2_address_ok(NULL),
|
||||
{
|
||||
&C_icon_validate_14,
|
||||
"Approve",
|
||||
});
|
||||
UX_STEP_CB(
|
||||
ux_display_public_eth2_flow_4_step,
|
||||
pb,
|
||||
io_seproxyhal_touch_address_cancel(NULL),
|
||||
{
|
||||
&C_icon_crossmark,
|
||||
"Reject",
|
||||
});
|
||||
|
||||
UX_FLOW(ux_display_public_eth2_flow,
|
||||
&ux_display_public_eth2_flow_1_step,
|
||||
&ux_display_public_eth2_flow_2_step,
|
||||
&ux_display_public_eth2_flow_3_step,
|
||||
&ux_display_public_eth2_flow_4_step
|
||||
);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifdef HAVE_ETH2
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
|
||||
|
||||
void handleSetEth2WithdrawalIndex(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx) {
|
||||
UNUSED(dataLength);
|
||||
|
||||
if (dataLength != 4) {
|
||||
THROW(0x6700);
|
||||
}
|
||||
|
||||
if ((p1 != 0) || (p2 != 0)) {
|
||||
THROW(0x6B00);
|
||||
}
|
||||
|
||||
eth2WithdrawalIndex = U4BE(dataBuffer, 0);
|
||||
|
||||
THROW(0x9000);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user