Skip to content

Commit b42b2cc

Browse files
Merge pull request #748 from LedgerHQ/feat/apa/gcs_trusted_name_sender_addr
GCS PARAM_TRUSTED_NAME sender address support
2 parents 8d78f53 + 6e42506 commit b42b2cc

File tree

10 files changed

+67
-19
lines changed

10 files changed

+67
-19
lines changed

client/src/ledger_app_clients/ethereum/gcs.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,19 @@ class ParamTrustedName():
409409
value: Value
410410
types: list[TrustedNameType]
411411
sources: list[TrustedNameSource]
412+
sender_addrs: Optional[list[bytes]]
412413

413-
def __init__(self, version: int, value: Value, types: list[TrustedNameType], sources: list[TrustedNameSource]):
414+
def __init__(self,
415+
version: int,
416+
value: Value,
417+
types: list[TrustedNameType],
418+
sources: list[TrustedNameSource],
419+
sender_addrs: Optional[list[bytes]] = None):
414420
self.version = version
415421
self.value = value
416422
self.types = types
417423
self.sources = sources
424+
self.sender_addrs = sender_addrs
418425

419426
def serialize(self) -> bytes:
420427
payload = bytearray()
@@ -428,6 +435,9 @@ def serialize(self) -> bytes:
428435
for source in self.sources:
429436
sources.append(source)
430437
payload += format_tlv(0x03, sources)
438+
if self.sender_addrs is not None:
439+
for addr in self.sender_addrs:
440+
payload += format_tlv(0x04, addr)
431441
return payload
432442

433443

src_features/generic_tx_parser/gtp_param_trusted_name.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
#include "gtp_field_table.h"
88
#include "utils.h"
99
#include "shared_context.h"
10+
#include "feature_signTx.h" // get_public_key
11+
#include "apdu_constants.h"
1012

1113
enum {
1214
TAG_VERSION = 0x00,
1315
TAG_VALUE = 0x01,
1416
TAG_TYPES = 0x02,
1517
TAG_SOURCES = 0x03,
18+
TAG_SENDER_ADDR = 0x04,
1619
};
1720

1821
static bool handle_version(const s_tlv_data *data, s_param_trusted_name_context *context) {
@@ -49,6 +52,19 @@ static bool handle_sources(const s_tlv_data *data, s_param_trusted_name_context
4952
return true;
5053
}
5154

55+
static bool handle_sender_addr(const s_tlv_data *data, s_param_trusted_name_context *context) {
56+
if ((data->length > sizeof(context->param->sender_addr)) ||
57+
(context->param->sender_addr_count == ARRAYLEN(context->param->sender_addr))) {
58+
return false;
59+
}
60+
buf_shrink_expand(data->value,
61+
data->length,
62+
context->param->sender_addr[context->param->sender_addr_count],
63+
sizeof(context->param->sender_addr[context->param->sender_addr_count]));
64+
context->param->sender_addr_count += 1;
65+
return true;
66+
}
67+
5268
bool handle_param_trusted_name_struct(const s_tlv_data *data,
5369
s_param_trusted_name_context *context) {
5470
bool ret;
@@ -66,6 +82,9 @@ bool handle_param_trusted_name_struct(const s_tlv_data *data,
6682
case TAG_SOURCES:
6783
ret = handle_sources(data, context);
6884
break;
85+
case TAG_SENDER_ADDR:
86+
ret = handle_sender_addr(data, context);
87+
break;
6988
default:
7089
PRINTF(TLV_TAG_ERROR_MSG, data->tag);
7190
ret = false;
@@ -87,6 +106,14 @@ bool format_param_trusted_name(const s_param_trusted_name *param, const char *na
87106
chain_id = get_tx_chain_id();
88107
for (int i = 0; i < values.size; ++i) {
89108
buf_shrink_expand(values.value[i].ptr, values.value[i].length, addr, sizeof(addr));
109+
// replace by wallet addr if a match is found
110+
for (uint8_t idx = 0; idx < param->sender_addr_count; ++idx) {
111+
if (memcmp(addr, param->sender_addr[idx], ADDRESS_LENGTH) == 0) {
112+
ret = get_public_key(addr, sizeof(addr)) == APDU_RESPONSE_OK;
113+
break;
114+
}
115+
}
116+
if (!ret) break;
90117
if ((tname = get_trusted_name(param->type_count,
91118
param->types,
92119
param->source_count,

src_features/generic_tx_parser/gtp_param_trusted_name.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99
#include "gtp_value.h"
1010
#include "trusted_name.h"
1111

12+
#define MAX_SENDER_ADDRS 3
13+
1214
typedef struct {
1315
uint8_t version;
1416
s_value value;
1517
uint8_t type_count;
1618
e_name_type types[TN_TYPE_COUNT];
1719
uint8_t source_count;
1820
e_name_source sources[TN_SOURCE_COUNT];
21+
uint8_t sender_addr_count;
22+
uint8_t sender_addr[MAX_SENDER_ADDRS][ADDRESS_LENGTH];
1923
} s_param_trusted_name;
2024

2125
typedef struct {
856 Bytes
Loading
-342 Bytes
Loading
371 Bytes
Loading
-342 Bytes
Loading
371 Bytes
Loading
682 Bytes
Loading

tests/ragger/test_gcs.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ def test_gcs_nft(firmware: Firmware,
4040
abi=json.load(file),
4141
address=None
4242
)
43-
recipient_addr = bytes.fromhex("1111111111111111111111111111111111111111")
43+
with app_client.get_public_addr(bip32_path="m/44'/60'/0'/0/0", display=False):
44+
pass
45+
_, device_addr, _ = ResponseParser.pk_addr(app_client.response().data)
4446
data = contract.encode_abi("safeBatchTransferFrom", [
45-
bytes.fromhex("Dad77910DbDFdE764fC21FCD4E74D71bBACA6D8D"),
46-
recipient_addr,
47+
bytes.fromhex("1111111111111111111111111111111111111111"),
48+
bytes.fromhex("d8da6bf26964af9d7eed9e03e53415d37aa96045"),
4749
[
4850
0xff,
4951
0xffff,
@@ -75,8 +77,8 @@ def test_gcs_nft(firmware: Firmware,
7577
Field(
7678
1,
7779
"From",
78-
ParamType.RAW,
79-
ParamRaw(
80+
ParamType.TRUSTED_NAME,
81+
ParamTrustedName(
8082
1,
8183
Value(
8284
1,
@@ -88,14 +90,27 @@ def test_gcs_nft(firmware: Firmware,
8890
PathLeaf(PathLeafType.STATIC),
8991
]
9092
),
91-
)
93+
),
94+
[
95+
TrustedNameType.ACCOUNT,
96+
],
97+
[
98+
TrustedNameSource.UD,
99+
TrustedNameSource.ENS,
100+
TrustedNameSource.FN,
101+
],
102+
[
103+
bytes.fromhex("0000000000000000000000000000000000000000"),
104+
bytes.fromhex("1111111111111111111111111111111111111111"),
105+
bytes.fromhex("2222222222222222222222222222222222222222"),
106+
],
92107
)
93108
),
94109
Field(
95110
1,
96111
"To",
97-
ParamType.TRUSTED_NAME,
98-
ParamTrustedName(
112+
ParamType.RAW,
113+
ParamRaw(
99114
1,
100115
Value(
101116
1,
@@ -107,15 +122,7 @@ def test_gcs_nft(firmware: Firmware,
107122
PathLeaf(PathLeafType.STATIC),
108123
]
109124
),
110-
),
111-
[
112-
TrustedNameType.ACCOUNT,
113-
],
114-
[
115-
TrustedNameSource.UD,
116-
TrustedNameSource.ENS,
117-
TrustedNameSource.FN,
118-
],
125+
)
119126
)
120127
),
121128
Field(
@@ -205,7 +212,7 @@ def test_gcs_nft(firmware: Firmware,
205212

206213
app_client.provide_transaction_info(tx_info.serialize())
207214
challenge = ResponseParser.challenge(app_client.get_challenge().data)
208-
app_client.provide_trusted_name_v2(recipient_addr,
215+
app_client.provide_trusted_name_v2(device_addr,
209216
"gerard.eth",
210217
TrustedNameType.ACCOUNT,
211218
TrustedNameSource.ENS,

0 commit comments

Comments
 (0)