Skip to content

Commit

Permalink
Update App Specification and get public key
Browse files Browse the repository at this point in the history
- Get public key response
  • Loading branch information
TeknoPT committed Dec 6, 2023
1 parent 44cc4f5 commit 585e351
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
18 changes: 9 additions & 9 deletions APP_SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ This documentation describes the APDU messages interface to communicate with the

The application covers the following functionalities :

- Get a public Boilerplate address given a BIP 32 path
- Sign a basic Boilerplate transaction given a BIP 32 path and raw transaction
- Retrieve the Boilerplate app version
- Retrieve the Boilerplate app name
- Get a public Phantasma address given a BIP 32 path
- Sign a basic Phantasma transaction given a BIP 32 path and raw transaction
- Retrieve the Phantasma app version
- Retrieve the Phantasma app name

The application interface can be accessed over HID or BLE

## APDUs

### GET BOILERPLATE PUBLIC ADDRESS
### GET PHANTASMA PUBLIC ADDRESS

#### Description

Expand Down Expand Up @@ -54,11 +54,11 @@ The address can be optionally checked on the device before being returned.
| Chain code | var |


### SIGN BOILERPLATE TRANSACTION
### SIGN PHANTASMA TRANSACTION

#### Description

This command signs a Boilerplate transaction after having the user validate the transactions parameters.
This command signs a Phantasma transaction after having the user validate the transactions parameters.

The input data is the RLP encoded transaction streamed to the device in 255 bytes maximum data chunks.

Expand Down Expand Up @@ -100,7 +100,7 @@ The input data is the RLP encoded transaction streamed to the device in 255 byte

#### Description

This command returns boilerplate application version
This command returns Phantasma application version

#### Coding

Expand All @@ -127,7 +127,7 @@ None

#### Description

This command returns boilerplate application name
This command returns Phantasma application name

#### Coding

Expand Down
28 changes: 18 additions & 10 deletions src/handler/get_public_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,44 @@
#include "cx.h"
#include "io.h"
#include "buffer.h"
#include "crypto_helpers.h"

#include "get_public_key.h"
#include "../globals.h"
#include "../types.h"
#include "../sw.h"
#include "../ui/display.h"
#include "../helper/send_response.h"
#include "../crypto.h"

int handler_get_public_key(buffer_t *cdata, bool display) {
explicit_bzero(&G_context, sizeof(G_context));
G_context.req_type = CONFIRM_ADDRESS;
G_context.state = STATE_NONE;
// Read BIP32 path from incoming data and handle errors

cx_ecfp_private_key_t private_key = {0};
cx_ecfp_public_key_t public_key = {0};

// Read BIP32 path from incoming data and handle errors
if (!buffer_read_u8(cdata, &G_context.bip32_path_len) ||
!buffer_read_bip32_path(cdata, G_context.bip32_path, (size_t) G_context.bip32_path_len)) {
return io_send_sw(SW_WRONG_DATA_LENGTH);
}

cx_err_t error = bip32_derive_get_pubkey_256(CX_CURVE_256K1,
G_context.bip32_path,
G_context.bip32_path_len,
G_context.pk_info.raw_public_key,
G_context.pk_info.chain_code,
CX_SHA512);
// Derive private key according to BIP32 path
if (crypto_derive_private_key(&private_key, G_context.bip32_path, G_context.bip32_path_len) != 0) {
explicit_bzero(&private_key, sizeof(private_key));
return io_send_sw(SW_DENY); // or appropriate error code
}

if (error != CX_OK) {
return io_send_sw(error);
// Generate corresponding public key
if (crypto_init_public_key(&private_key, &public_key, G_context.pk_info.raw_public_key) != 0) {
explicit_bzero(&private_key, sizeof(private_key));
return io_send_sw(SW_DISPLAY_ADDRESS_FAIL); // or appropriate error code
}

// Reset private key after use for security
explicit_bzero(&private_key, sizeof(private_key));

if (display) {
return ui_display_address();
}
Expand Down

0 comments on commit 585e351

Please sign in to comment.