Skip to content

Commit

Permalink
Fix linters output
Browse files Browse the repository at this point in the history
  • Loading branch information
cedelavergne-ledger committed Sep 29, 2023
1 parent d47d728 commit e64ce9c
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 42 deletions.
27 changes: 13 additions & 14 deletions src/apdu/messages/sign_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ void sign_transaction() {

cx_err_t error = CX_INTERNAL_ERROR;
CX_CHECK(bip32_derive_init_privkey_256(tmp_ctx.transaction_context.curve,
tmp_ctx.transaction_context.bip32_path,
tmp_ctx.transaction_context.path_length,
&private_key,
NULL));
tmp_ctx.transaction_context.bip32_path,
tmp_ctx.transaction_context.path_length,
&private_key,
NULL));

io_seproxyhal_io_heartbeat();

Expand All @@ -77,26 +77,25 @@ void sign_transaction() {
uint8_t *suffix_data = key_buffer + XRP_PUBKEY_SIZE;

CX_CHECK(cx_ecfp_generate_pair_no_throw(tmp_ctx.transaction_context.curve,
&public_key,
&private_key,
1));
&public_key,
&private_key,
1));
xrp_compress_public_key(&public_key, public_key_data);
xrp_public_key_hash160(public_key_data, suffix_data);

memmove(
tmp_ctx.transaction_context.raw_tx + tmp_ctx.transaction_context.raw_tx_length,
suffix_data,
suffix_length);
memmove(tmp_ctx.transaction_context.raw_tx + tmp_ctx.transaction_context.raw_tx_length,
suffix_data,
suffix_length);
tmp_ctx.transaction_context.raw_tx_length += suffix_length;

explicit_bzero(key_buffer, sizeof(key_buffer));
}

if (tmp_ctx.transaction_context.curve == CX_CURVE_256K1) {
cx_hash_sha512(tmp_ctx.transaction_context.raw_tx,
tmp_ctx.transaction_context.raw_tx_length,
key_buffer,
64);
tmp_ctx.transaction_context.raw_tx_length,
key_buffer,
64);
PRINTF("Hash to sign:\n%.*H\n", 32, key_buffer);
io_seproxyhal_io_heartbeat();

Expand Down
2 changes: 1 addition & 1 deletion src/swap/handle_swap_sign_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool copy_transaction_parameters(create_transaction_parameters_t* params) {

// Full reset the global variables
os_explicit_zero_BSS_segment();
// Keep the address at wich we'll reply the signing status
// Keep the address at which we'll reply the signing status
G_swap_sign_return_value_address = &params->result;
// Commit the values read from exchange to the clean global space
memcpy(&approval_strings.swap, &stack_data, sizeof(stack_data));
Expand Down
4 changes: 2 additions & 2 deletions src/transaction/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ static bool check_field(const field_t *field,
}

/*
Check that a previously parsed TX has the rigth shape/content for the app to sign it without user
Check that a previously parsed TX has the right shape/content for the app to sign it without user
approval.
Exemple of such a swappable TX (as it would be displayed with the approval flow):
Example of such a swappable TX (as it would be displayed with the approval flow):
{
"TransactionType" : "Payment",
"Account" : "ra7Zr8ddy9tB88RaXL8B87YkqhEJG2vkAJ",
Expand Down
2 changes: 1 addition & 1 deletion src/xrp/fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void format_field(field_t* field, field_value_t* dst) {
}

if (ret != 0) {
strncpy(dst->buf, "[ERROR DURING FORMATING]", sizeof(dst->buf));
strncpy(dst->buf, "[ERROR DURING FORMATTING]", sizeof(dst->buf));
return;
}

Expand Down
8 changes: 7 additions & 1 deletion src/xrp/xrp_pub_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "xrp_pub_key.h"
#include "xrp_helpers.h"
#include "lcx_hash.h"
#include "crypto_helpers.h"

/* return 0 on success */
Expand All @@ -19,5 +20,10 @@ int get_public_key(cx_curve_t curve,

pub_key->curve = curve;
pub_key->W_len = 65;
return bip32_derive_get_pubkey_256(curve, bip32_path_parsed, bip32_path_length, pub_key->W, chain_code, CX_SHA256);
return bip32_derive_get_pubkey_256(curve,
bip32_path_parsed,
bip32_path_length,
pub_key->W,
chain_code,
CX_SHA256);
}
Empty file added tests/__init__.py
Empty file.
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
import os
from pathlib import Path
from ragger.conftest import configuration
Expand Down
12 changes: 5 additions & 7 deletions tests/functional_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
#!/usr/bin/env python3

"""
./speculos.py --log-level automation:DEBUG --automation file:$HOME/app-xrp/tests/automation.json ~/app-xrp/bin/app.elf &
./speculos.py --log-level automation:DEBUG ~/app-xrp/bin/app.elf &
export LEDGER_PROXY_ADDRESS=127.0.0.1 LEDGER_PROXY_PORT=9999
pytest-3 -v -s
"""
import os
import pytest
import pathlib
from xrp import XRPClient, DEFAULT_PATH
from ledgerwallet.params import Bip32Path
import pytest
from ledgerwallet.params import Bip32Path # type: ignore [import]
from ragger.backend import RaisePolicy
from ragger.error import ExceptionRAPDU
from .xrp import XRPClient, DEFAULT_PATH


def test_sign_too_large(backend, firmware, navigator):
Expand Down Expand Up @@ -74,7 +72,7 @@ def test_sign_valid_tx_and_compare_screens(backend, raw_tx_path, firmware, navig

backend.wait_for_home_screen()
xrp.sign(payload, True, no_prefix_snappath)
assert xrp._client.last_async_response.status == 0x9000
assert backend.last_async_response.status == 0x9000

# Verify tx signature (Does not work...)
# key = xrp.get_pubkey()
Expand Down
23 changes: 23 additions & 0 deletions tests/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[tool:pytest]
addopts = --strict-markers

[pylint]
# disable = missing-function-docstring,missing-class-docstring
disable = C0114, # missing-module-docstring
C0115, # missing-class-docstring
C0116, # missing-function-docstring
C0103, # invalid-name
R0801, # duplicate-code
R0913, # too-many-arguments
R0914 # too-many-variables
max-line-length=100
extension-pkg-whitelist=hid

[pycodestyle]
max-line-length = 100

[mypy-hid.*]
ignore_missing_imports = True

[mypy-pytest.*]
ignore_missing_imports = True
23 changes: 8 additions & 15 deletions tests/xrp.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#!/usr/bin/env python3

from typing import Generator
from contextlib import contextmanager
from enum import IntEnum
from time import sleep
from ragger.backend.interface import BackendInterface, RAPDU
from ragger.navigator import NavInsID, NavIns
from ledgerwallet.params import Bip32Path
import pathlib

from ecdsa.util import sigdecode_der
from ecdsa import VerifyingKey, SECP256k1
from hashlib import sha256
from ragger.backend.interface import BackendInterface, RAPDU
from ragger.navigator import NavInsID
from ledgerwallet.params import Bip32Path # type: ignore [import]

from ecdsa.util import sigdecode_der # type: ignore [import]
from ecdsa import VerifyingKey, SECP256k1 # type: ignore [import]

DEFAULT_PATH = "44'/144'/0'/0'/0"

Expand Down Expand Up @@ -44,9 +40,6 @@ class Action(IntEnum):
NONE = 2


DEFAULT_PATH = "44'/144'/0'/0'/0"


class XRPClient:
CLA = 0xE0

Expand Down Expand Up @@ -96,7 +89,7 @@ def sign(self, payload, navigate: bool = False, snappath: str = ""):

size = min(len(payload), chunk_size)
if size != len(payload):
p1 |= P1.MORE
p1 |= P1.MORE # type: ignore[assignment]

p2 = P2.CURVE_SECP256K1

Expand All @@ -105,7 +98,7 @@ def sign(self, payload, navigate: bool = False, snappath: str = ""):
elif p1 in [P1.FIRST, P1.NEXT]:
with self._client.exchange_async(
self.CLA, ins=Ins.SIGN, p1=p1, p2=p2, data=payload[:size]
) as r:
):
if navigate:
if self._firmware.device == "stax":
self._navigator.navigate_until_text_and_compare(
Expand Down

0 comments on commit e64ce9c

Please sign in to comment.