Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ftheirs committed Jan 6, 2023
1 parent 6bb6d60 commit 9541f04
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 66 deletions.
53 changes: 0 additions & 53 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,36 +114,6 @@ __Z_INLINE bool process_chunk(__Z_UNUSED volatile uint32_t *tx, uint32_t rx) {
THROW(APDU_CODE_INVALIDP1P2);
}

// Avoid warnings: unused method
#if 0
// For transparent transfers in MASP transactions
__Z_INLINE void handleGetAddrSecp256k1(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
extractHDPath(rx, OFFSET_DATA);

const uint8_t requireConfirmation = G_io_apdu_buffer[OFFSET_P1];
uint16_t replyLen = 0;

zxerr_t zxerr = masp_transparent_get_address_secp256k1(G_io_apdu_buffer, IO_APDU_BUFFER_SIZE - 2, &replyLen);
if(zxerr != zxerr_ok){
*tx = 0;
THROW(APDU_CODE_DATA_INVALID);
}

action_addrResponse.kind = addr_masp_transparent_secp256k1;
action_addrResponse.len = replyLen;

if (requireConfirmation) {
view_review_init(addr_getItem, addr_getNumItems, app_reply_address);
view_review_show(REVIEW_ADDRESS);
*flags |= IO_ASYNCH_REPLY;
return;
}

*tx = replyLen;
THROW(APDU_CODE_OK);
}
#endif

__Z_INLINE void handleSignWrapper(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
ZEMU_LOGF(50, "handleSignWrapper\n")
if (!process_chunk(tx, rx)) {
Expand Down Expand Up @@ -213,29 +183,6 @@ __Z_INLINE void handleSignEd25519(volatile uint32_t *flags, volatile uint32_t *t
*flags |= IO_ASYNCH_REPLY;
}

// Avoid warning: unused method
#if 0
__Z_INLINE void handleSignSecp256k1(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
zemu_log("handleSignSecp256k1\n");
if (!process_chunk(tx, rx)) {
THROW(APDU_CODE_OK);
}

const char *error_msg = tx_parse();
CHECK_APP_CANARY()
if (error_msg != NULL) {
int error_msg_length = strlen(error_msg);
memcpy(G_io_apdu_buffer, error_msg, error_msg_length);
*tx += (error_msg_length);
THROW(APDU_CODE_DATA_INVALID);
}

view_review_init(tx_getItem, tx_getNumItems, app_sign_secp256k1);
view_review_show(REVIEW_TXN);
*flags |= IO_ASYNCH_REPLY;
}
#endif

__Z_INLINE void handle_getversion(volatile uint32_t *flags, volatile uint32_t *tx)
{
G_io_apdu_buffer[0] = 0;
Expand Down
4 changes: 0 additions & 4 deletions app/src/crypto_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ zxerr_t crypto_serializeData(const uint64_t dataSize, uint8_t *buffer, uint16_t
CHECK_ZXERR(encodeLEB128(dataSize, buffer + 1, MAX_LEB128_OUTPUT, dataInfoSize))

(*dataInfoSize)++;
ZEMU_LOGF(50, "PreData 0: %d\n", buffer[0])
ZEMU_LOGF(50, "PreData 1: %d\n", buffer[1])
ZEMU_LOGF(50, "DataInfoSize: %d\n", *dataInfoSize)

return zxerr_ok;
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/leb128.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ extern "C" {
#define MAX_LEB128_OUTPUT 10

zxerr_t encodeLEB128(uint64_t number, uint8_t *encoded, uint8_t encodedLen, uint8_t *encodedBytes);
// zxerr_t encodeSLEB128(const int64_t number, uint8_t *encoded, uint8_t encodedSize);

// TO DO
// zxerr_t encodeSLEB128();
// zxerr_t decodeLEB128();
// zxerr_t decodeSLEB128();

Expand Down
1 change: 0 additions & 1 deletion app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

parser_error_t _read(parser_context_t *c, parser_tx_t *v)
{
ZEMU_LOGF(50, "Parser::_read\n")
if (c->bufferLen < v->outerTxnPtr->codeSize + v->outerTxnPtr->dataSize + sizeof(uint64_t) + sizeof(uint32_t)) {
return parser_missing_field;
}
Expand Down
1 change: 0 additions & 1 deletion app/src/parser_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
extern "C" {
#endif

// #{TODO} --> functions to parse, get, process transaction fields
parser_error_t _read(parser_context_t *c, parser_tx_t *v);

#ifdef __cplusplus
Expand Down
12 changes: 6 additions & 6 deletions docs/APDUSPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

## General structure

# #{TODO} --> Update CLA, HDPATH and APDU messages

The general structure of commands and responses is as follows:

### Commands
Expand Down Expand Up @@ -76,7 +74,7 @@ Gets the ED25519 public key and corresponding address
| CLA | byte (1) | Application Identifier | 0x57 |
| INS | byte (1) | Instruction ID | 0x01 |
| P1 | byte (1) | Request User confirmation | No = 0 |
| P2 | byte (1) | Parameter 2 | ignored |
| P2 | byte (1) | Signature scheme | Ed25519 = 0 / Secp256k1 = 1 |
| L | byte (1) | Bytes in payload | (depends) |
| Path[0] | byte (4) | Derivation Path Data | 0x80000000 | 44 |
| Path[1] | byte (4) | Derivation Path Data | 0x80000000 | 434 |
Expand All @@ -89,7 +87,7 @@ Gets the ED25519 public key and corresponding address
| Field | Type | Content | Note |
| ------- | --------- | ----------- | ------------------------ |
| PK | byte (32) | Public Key | |
| ADDR | byte (??) | address | |
| ADDR | byte (??) | address | Testnet: 84 / Mainnet: 80 |
| SW1-SW2 | byte (2) | Return code | see list of return codes |

---
Expand All @@ -109,7 +107,7 @@ Sign wrapper transaction with Ed25519
| P2 | byte (1) | ---- | not used |
| L | byte (1) | Bytes in payload | (depends) |

The first packet/chunk includes only the derivation path
The first packet/chunk includes the derivation path and size for Code and Data fields

All other packets/chunks contain data chunks that are described below

Expand All @@ -122,6 +120,8 @@ All other packets/chunks contain data chunks that are described below
| Path[2] | byte (4) | Derivation Path Data | ? |
| Path[3] | byte (4) | Derivation Path Data | ? |
| Path[4] | byte (4) | Derivation Path Data | ? |
| CodeSize | byte (4) | Bytes of Code | ? |
| DataSize | byte (4) | Bytes of Data | ? |

##### Other Chunks/Packets

Expand All @@ -133,6 +133,6 @@ All other packets/chunks contain data chunks that are described below

| Field | Type | Content | Note |
| ------- | --------- | ----------- | ------------------------ |
| SIG | byte (65) | Signature | |
| SIG | byte (64) | Signature | |
| SW1-SW2 | byte (2) | Return code | see list of return codes |

0 comments on commit 9541f04

Please sign in to comment.