Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap near #145

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions .github/workflows/reusable_swap_functional_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ on:
default: 'LedgerHQ/app-tron'
type: string

branch_for_near:
required: false
default: 'y333_241015/add_swap_support'
type: string
repo_for_near:
required: false
default: 'LedgerHQ/app-near'
type: string

test_filter:
required: false
default: '""'
Expand Down Expand Up @@ -146,6 +155,9 @@ jobs:
- name: tron
repo: ${{ inputs.repo_for_tron }}
branch: ${{ inputs.branch_for_tron }}
- name: near
repo: ${{ inputs.repo_for_near }}
branch: ${{ inputs.branch_for_near }}

uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_build.yml@v1
with:
Expand All @@ -156,6 +168,7 @@ jobs:
flags: "COIN=${{ matrix.coin.name }} CHAIN=${{ matrix.coin.name }} CAL_TEST_KEY=1 DOMAIN_NAME_TEST_KEY=1 SET_PLUGIN_TEST_KEY=1 NFT_TEST_KEY=1"
upload_app_binaries_artifact: libraries_binaries-${{ matrix.coin.name }}-${{ strategy.job-index }}
upload_as_lib_artifact: ${{ matrix.coin.name }}
builder: ledger-app-builder

merge_libraries_build:
name: Merge built libraries
Expand Down
2 changes: 2 additions & 0 deletions src/parse_check_address_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ int parse_check_address_message(const command_t *cmd,
}

// Read address parameters
PRINTF("Read Address Parameters\n");
if (!parse_to_sized_buffer(cmd->data.bytes, cmd->data.size, 1, address_parameters, &read)) {
PRINTF("Cannot read the address_parameters\n");
return 0;
}
PRINTF("Address Parameters size: %d\n", address_parameters->size);
if (address_parameters->size < 1) {
PRINTF("Invalid address_parameters size %d\n", address_parameters->size);
return 0;
Expand Down
2 changes: 2 additions & 0 deletions test/python/apps/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .polkadot import DOT_PACKED_DERIVATION_PATH, DOT_CONF
from .tron import TRX_PACKED_DERIVATION_PATH, TRX_CONF
from .tron import TRX_USDT_CONF, TRX_USDC_CONF, TRX_TUSD_CONF, TRX_USDD_CONF
from .near import NEAR_PACKED_DERIVATION_PATH, NEAR_CONF

@dataclass
class CurrencyConfiguration:
Expand Down Expand Up @@ -51,6 +52,7 @@ def get_conf_for_ticker(self, overload_signer: Optional[SigningAuthority]=None)
USDC_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="USDC", conf=TRX_USDC_CONF, packed_derivation_path=TRX_PACKED_DERIVATION_PATH)
TUSD_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="TUSD", conf=TRX_TUSD_CONF, packed_derivation_path=TRX_PACKED_DERIVATION_PATH)
USDD_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="USDD", conf=TRX_USDD_CONF, packed_derivation_path=TRX_PACKED_DERIVATION_PATH)
NEAR_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="NEAR", conf=NEAR_CONF, packed_derivation_path=NEAR_PACKED_DERIVATION_PATH)


# Helper that can be called from outside if we want to generate errors easily
Expand Down
60 changes: 60 additions & 0 deletions test/python/apps/near.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from enum import IntEnum

from ragger.bip import pack_derivation_path
from ragger.utils import create_currency_config, RAPDU
from py_near.transactions import create_transfer_action, Transaction
import ed25519
import base58


ED25519_KEYPAIR = "188d2ce61071d477a2400558c3612ee68957a80aa2e56c29dc4da2dace58e7d8c4f5941e81e071c2fd1dae2e71fd3d859d462484391d9a90bf219211dcbb320f"
PRIVATE_KEY = ed25519.SigningKey(bytes.fromhex(ED25519_KEYPAIR))
PUBLIC_KEY = PRIVATE_KEY.get_verifying_key()

NEAR_CONF = create_currency_config("NEAR", "NEAR")

NEAR_PACKED_DERIVATION_PATH = pack_derivation_path("m/44'/397'/0'/0'/1'")
SIGNER_ID = "blablatest.testnet"
NONCE = 96520360000015
BLOCK_HASH = base58.b58decode("C32rfeBkSMT1xnsrArkV9Mu81ww9qK7n6Kw17NhEbVuK")


class Ins():
SIGN = 0x02


class P1():
START = 0x00
MORE = 0x80


class P2():
UNUSED = 0x57


class NearErrors(IntEnum):
SW_DENY = 0x6985
SW_SWAP_CHECKING_FAIL = 0x6A88


class NearClient:
CLA = 0x80

def __init__(self, backend):
self._backend = backend

def send_simple_sign_tx(self, path: str, destination: str, send_amount: int) -> RAPDU:
packed_path = pack_derivation_path(path)

tx = Transaction(
signer_id="blablatest.testnet",
public_key=PUBLIC_KEY.to_bytes(),
nonce=NONCE,
receiver_id=destination,
actions=[create_transfer_action(send_amount * 10**24)],
block_hash=BLOCK_HASH
)

serialized_tx = bytes(tx.to_vec(PRIVATE_KEY.to_bytes()))

return self._backend.exchange(self.CLA, Ins.SIGN, P1.MORE, P2.UNUSED, packed_path[1:] + serialized_tx)
1 change: 1 addition & 0 deletions test/python/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"solana": "Solana",
"DOT": "Polkadot",
"tron": "Tron",
"near": "NEAR",
}

configuration.OPTIONAL.SIDELOADED_APPS_DIR = "test/python/lib_binaries/"
Expand Down
1 change: 1 addition & 0 deletions test/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ xrpl-py
scalecodec
bip32
embit
py-near
ledger_app_clients.ethereum @ https://github.com/LedgerHQ/app-ethereum/archive/develop.zip#subdirectory=client
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading