Skip to content

Commit

Permalink
Merge pull request #6 from LedgerHQ/v1.2.0
Browse files Browse the repository at this point in the history
V1.2.0
  • Loading branch information
lpascal-ledger authored Apr 5, 2022
2 parents 038e873 + 6998f8b commit 16a93dd
Show file tree
Hide file tree
Showing 58 changed files with 25,389 additions and 7,340 deletions.
145 changes: 137 additions & 8 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,174 @@
name: Compilation & tests

on:
workflow_dispatch:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop

jobs:
job_build_debug_nano_s:
name: Build debug Nano S
runs-on: ubuntu-latest

container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest

steps:
- name: Clone
uses: actions/checkout@v2
with:
submodules: recursive

- name: Build plugin for Nano S
run: |
make clean
make BOLOS_SDK=$NANOS_SDK
- name: Move binary to test directory
run: |
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/poap_nanos.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
with:
name: binaries
path: tests/elfs/poap_nanos.elf

job_build_debug_nano_x:
name: Build debug Nano X
runs-on: ubuntu-latest

container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest

steps:
- name: Clone
uses: actions/checkout@v2
with:
submodules: recursive

- name: Build plugin for Nano X
run: |
make clean
make BOLOS_SDK=$NANOX_SDK
- name: Move binary to test directory
run: |
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/poap_nanox.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
with:
name: binaries
path: tests/elfs/poap_nanox.elf

job_build_debug_nano_sp:
name: Build debug Nano S+
runs-on: ubuntu-latest
container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Clone
uses: actions/checkout@v2
with:
submodules: recursive
- name: Build plugin for Nano S+
run: |
make clean
make BOLOS_SDK=$NANOSP_SDK
- name: Move binary to test directory
run: |
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/poap_nanosp.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
with:
name: binaries
path: tests/elfs/poap_nanosp.elf

job_build_ethereum_nano_s:
name: Build Ethereum application for Nano S testing
runs-on: ubuntu-latest
container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Checkout app-ethereum
uses: actions/checkout@v2
with:
repository: LedgerHQ/app-ethereum
ref: 'master'
submodules: recursive
- name: Build ethereum
run: |
make clean
make -j DEBUG=1 BYPASS_SIGNATURES=1 BOLOS_SDK=$NANOS_SDK CHAIN=ethereum
- name: Move binary to test directory
run: |
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/ethereum_nanos.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
with:
name: binaries
path: tests/elfs/ethereum_nanos.elf

job_build_ethereum_nano_x:
name: Build Ethereum application for Nano X testing
runs-on: ubuntu-latest
container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Checkout app-ethereum
uses: actions/checkout@v2
with:
repository: LedgerHQ/app-ethereum
ref: 'master'
submodules: recursive
- name: Build ethereum
run: |
make clean
make -j DEBUG=1 BYPASS_SIGNATURES=1 BOLOS_SDK=$NANOX_SDK CHAIN=ethereum
- name: Move binary to test directory
run: |
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/ethereum_nanox.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
with:
name: binaries
path: tests/elfs/ethereum_nanox.elf

# # In anticipation for Nano SP testing
# job_build_ethereum_nano_sp:
# name: Build Ethereum application for Nano SP testing
# runs-on: ubuntu-latest
# container:
# image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
# steps:
# - name: Checkout app-ethereum
# uses: actions/checkout@v2
# with:
# repository: LedgerHQ/app-ethereum
# ref: 'master'
# submodules: recursive
# - name: Build ethereum
# run: |
# make clean
# make -j DEBUG=1 BYPASS_SIGNATURES=1 BOLOS_SDK=$NANOSP_SDK CHAIN=ethereum
# - name: Move binary to test directory
# run: |
# mkdir -p ./tests/elfs/
# mv bin/app.elf ./tests/elfs/ethereum_nanox.elf
# - name: Upload plugin binary
# uses: actions/upload-artifact@v2
# with:
# name: binaries
# path: tests/elfs/ethereum_nanosp.elf

jobs-e2e-tests:
needs: [job_build_debug_nano_s, job_build_debug_nano_x]
needs:
- job_build_debug_nano_s
- job_build_debug_nano_x
- job_build_ethereum_nano_s
- job_build_ethereum_nano_x
runs-on: ubuntu-latest
steps:
- name: Test
Expand All @@ -56,11 +178,18 @@ jobs:
echo $DISPLAY
- name: Checkout
uses: actions/checkout@v2
- name: Download built binaries
uses: actions/download-artifact@v2
with:
name: binaries
path: tests/elfs/
- name: Check downloaded binaries
run: ls -lh ./tests/elfs
- run: sudo apt-get update -y && sudo apt-get install -y libusb-1.0.0 libudev-dev
- name: Install node
uses: actions/setup-node@v2
with:
node-version: "14.4.0"
node-version: "16.4.0"
- name: Install yarn
run: |
npm install -g yarn
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ APP_LOAD_PARAMS += --appFlags 0x800 --path "44'/60'" --path "45'" --curve secp25
APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS)

APPVERSION_M = 1
APPVERSION_N = 0
APPVERSION_P = 1
APPVERSION_N = 2
APPVERSION_P = 0
APPVERSION = $(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)

APPNAME = "Poap"
APPNAME = "POAP"

#prepare hsm generation
ifeq ($(TARGET_NAME), TARGET_NANOS)
Expand Down
2 changes: 1 addition & 1 deletion ethereum-plugin-sdk
7 changes: 0 additions & 7 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@

void handle_finalize(void *parameters) {
ethPluginFinalize_t *msg = (ethPluginFinalize_t *) parameters;
context_t *context = (context_t *) msg->pluginContext;

msg->uiType = ETH_UI_TYPE_GENERIC;

// 2 additional screens are required to display the `token and `beneficiary` fields
msg->numScreens = 2;
msg->result = ETH_PLUGIN_RESULT_OK;

if (context->selectorIndex == SAFE_TRANSFER) {
// An additional screen is required to display the `token` field for safe_transfer method.
msg->numScreens += 1;
}
}
3 changes: 0 additions & 3 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ void handle_init_contract(void *parameters) {
case MINT_TOKEN:
context->next_param = EVENT_ID;
break;
case SAFE_TRANSFER:
context->next_param = FROM_ADDRESS;
break;
default:
PRINTF("Missing selectorIndex: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
40 changes: 1 addition & 39 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#include "poap_plugin.h"

// Copies the whole parameter (32 bytes long) from `src` to `dst`.
// Useful for numbers, data...
static void copy_parameter(uint8_t *dst, uint8_t *src) {
memcpy(dst, src, PARAMETER_LENGTH);
}

// Copy token sent parameter to token_id
static void handle_token(const ethPluginProvideParameter_t *msg, context_t *context) {
copy_parameter(context->token_id, msg->parameter);
copy_parameter(context->token_id, msg->parameter, PARAMETER_LENGTH);
}

static void handle_beneficiary(const ethPluginProvideParameter_t *msg, context_t *context) {
Expand All @@ -19,13 +13,6 @@ static void handle_beneficiary(const ethPluginProvideParameter_t *msg, context_t
PRINTF("BENEFICIARY: %.*H\n", ADDRESS_LENGTH, context->beneficiary);
}

static void handle_from_address(const ethPluginProvideParameter_t *msg, context_t *context) {
memset(context->from_address, 0, sizeof(context->from_address));
memcpy(context->from_address,
&msg->parameter[PARAMETER_LENGTH - ADDRESS_LENGTH],
sizeof(context->from_address));
PRINTF("FROM_ADDRESS: %.*H\n", ADDRESS_LENGTH, context->from_address);
}
static void handle_mint_token(ethPluginProvideParameter_t *msg, context_t *context) {
switch (context->next_param) {
case EVENT_ID:
Expand All @@ -47,28 +34,6 @@ static void handle_mint_token(ethPluginProvideParameter_t *msg, context_t *conte
break;
}
}
static void handle_safe_transfer(ethPluginProvideParameter_t *msg, context_t *context) {
switch (context->next_param) {
case FROM_ADDRESS: // from_address
handle_from_address(msg, context);
context->next_param = BENEFICIARY;
break;
case BENEFICIARY: // to
handle_beneficiary(msg, context);
context->next_param = TOKEN;
break;
case TOKEN: // id of the token received
handle_token(msg, context);
context->next_param = NONE;
break;
case NONE:
break;
default:
PRINTF("Param not supported\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
}

void handle_provide_parameter(void *parameters) {
ethPluginProvideParameter_t *msg = (ethPluginProvideParameter_t *) parameters;
Expand All @@ -92,9 +57,6 @@ void handle_provide_parameter(void *parameters) {
case MINT_TOKEN:
handle_mint_token(msg, context);
break;
case SAFE_TRANSFER:
handle_safe_transfer(msg, context);
break;
default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
3 changes: 0 additions & 3 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ void handle_query_contract_id(void *parameters) {
strlcpy(msg->name, PLUGIN_NAME, msg->nameLength);

switch (context->selectorIndex) {
case SAFE_TRANSFER:
strlcpy(msg->version, "Safe Transfer", msg->versionLength);
break;
case MINT_TOKEN:
strlcpy(msg->version, "Mint", msg->versionLength);
break;
Expand Down
16 changes: 0 additions & 16 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@ static void set_beneficiary_ui(ethQueryContractUI_t *msg, context_t *context) {
getEthAddressStringFromBinary(context->beneficiary, msg->msg + 2, msg->pluginSharedRW->sha3, 0);
}

// Set UI for "From Address" screen.
static void set_from_address_ui(ethQueryContractUI_t *msg, context_t *context) {
strlcpy(msg->title, "From Address", msg->titleLength);

msg->msg[0] = '0';
msg->msg[1] = 'x';

getEthAddressStringFromBinary(context->from_address,
msg->msg + 2,
msg->pluginSharedRW->sha3,
0);
}

// Set UI for "Warning" screen.
static void set_warning_ui(ethQueryContractUI_t *msg,
const context_t *context __attribute__((unused))) {
Expand Down Expand Up @@ -82,9 +69,6 @@ void handle_query_contract_ui(void *parameters) {
screens_t screen = get_screen(msg, context);

switch (screen) {
case FROM_ADDRESS_SCREEN:
set_from_address_ui(msg, context);
break;
case TOKEN_SCREEN:
set_token_ui(msg, context);
break;
Expand Down
10 changes: 5 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

#include "poap_plugin.h"

// Function: mintToken(uint256 eventId, uint256 tokenId, address receiver, bytes signedMessage)
// Selector: 0x3da5b8f0
static const uint8_t MINT_TOKEN_SELECTOR[SELECTOR_SIZE] = {0x3d, 0xa5, 0xb8, 0xf0};
static const uint8_t SAFE_TRANSFER_SELECTOR[SELECTOR_SIZE] = {0x42, 0x84, 0x2e, 0x0e};
// Function: mintToken(uint256 eventId, uint256 tokenId, address receiver, uint256 expirationTime,
// bytes signature)
// Selector: 0xaf68b302
static const uint8_t MINT_TOKEN_SELECTOR[SELECTOR_SIZE] = {0xaf, 0x68, 0xb3, 0x02};

// Array of all the different poap selectors.
const uint8_t *const POAP_SELECTORS[NUM_SELECTORS] = {MINT_TOKEN_SELECTOR, SAFE_TRANSFER_SELECTOR};
const uint8_t *const POAP_SELECTORS[NUM_SELECTORS] = {MINT_TOKEN_SELECTOR};

// Function to dispatch calls from the ethereum app.
void dispatch_plugin_calls(int message, void *parameters) {
Expand Down
4 changes: 1 addition & 3 deletions src/poap_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "eth_plugin_interface.h"
#include <string.h>

#define NUM_SELECTORS 2
#define NUM_SELECTORS 1
#define PLUGIN_NAME "POAP"
#define TOKEN_FOUND 1 << 1
#define SELECTOR_SIZE 4
Expand All @@ -13,7 +13,6 @@

typedef enum {
MINT_TOKEN,
SAFE_TRANSFER,
} selector_t;

// Enumeration used to parse the smart contract data.
Expand All @@ -39,7 +38,6 @@ extern const uint8_t *const POAP_SELECTORS[NUM_SELECTORS];
typedef struct context_t {
// For display.
uint8_t beneficiary[ADDRESS_LENGTH];
uint8_t from_address[ADDRESS_LENGTH];
uint8_t token_id[PARAMETER_LENGTH]; // not crypto token dedicated poap token value int number
char ticker[MAX_TICKER_LEN];

Expand Down
Loading

0 comments on commit 16a93dd

Please sign in to comment.