Skip to content

Commit a743d58

Browse files
Add Favorite Accounts feature
1 parent 706e44d commit a743d58

File tree

12 files changed

+1285
-7
lines changed

12 files changed

+1285
-7
lines changed

doc/ethapp.adoc

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,158 @@ _Output data_
960960

961961
None
962962

963+
### Favorite Accounts
964+
965+
#### Description
966+
967+
This command allows to synchronize an Address Book between Ledger Live and the device.
968+
This allows user-friendly and easier address verifications.
969+
Also, the entries from the Address Book can be displayed as a QR code for easier control or sharing.
970+
971+
#### Coding
972+
973+
'Command'
974+
975+
[width="80%"]
976+
|==============================================================================================================================
977+
| *CLA* | *INS* | *P1* | *P2* | *Lc* | *Le*
978+
| E0 | 30 | 01 : delete all accounts | 00 | 00 | empty
979+
| E0 | 30 | 02 : get account | account Nb | 00 | empty
980+
| E0 | 30 | 03 : rename an account | old name size | variable | see below
981+
| E0 | 30 | 04 : update an account with address | 00 | 00 | see below
982+
| E0 | 30 | 05 : update multiple accounts with address | 00 : next data
983+
984+
01 : last data | variable | see below
985+
986+
| E0 | 30 | 06 : update an account with derivation path | 00 | 00 | see below
987+
| E0 | 30 | 07 : update multiple accounts with derivation path | 00 : next data
988+
989+
01 : last data | variable | see below
990+
|==============================================================================================================================
991+
992+
Commands summary:
993+
994+
- `delete all accounts`: _Purge_ the Address Book, and remove all entries.
995+
- `get account`: Retrieve a specific Address Book entry; the Account Number is given in parameter.
996+
- `rename an account`: _Change_ the Name assigned to an Account.
997+
- `update an account`: _Add_ a new account, or _Rename_ an existing one.
998+
- `update multiple accounts`: _Add_ new accounts and/or _Rename_ existing ones.
999+
This is a _chaining_ command, meaning several APDU must be sent successively,
1000+
and the last one should have P2 = 0x01 to trig the confirmation screens.
1001+
1002+
NOTE: For _update account_ commands, we have each time 2 variants:
1003+
- Providing the full address
1004+
- Providing the full derivation path, allowing the device to securely derivate and compute the address.
1005+
1006+
_Input data_
1007+
1008+
##### If P1 == `rename an account`
1009+
1010+
[width="80%"]
1011+
|==============================================================================================================================
1012+
| *Description* | *Length*
1013+
| Old Account Name (up to 16 ascii characters, 32 hex values - without '0x') | variable (max 32)
1014+
| New Account Name (up to 16 ascii characters, 32 hex values - without '0x') | variable (max 32)
1015+
|==============================================================================================================================
1016+
1017+
The _Old Account name_ length must be written in P2.
1018+
1019+
##### If P1 == `update an account`
1020+
1021+
This command is used to _Add_ a new Address Book entry. If the pair (*_Address_*, *_Chain Id_*) already exists,
1022+
the command will be considered as a _Rename_.
1023+
1024+
###### Case with Address
1025+
1026+
[width="80%"]
1027+
|==============================================================================================================================
1028+
| *Description* | *Length*
1029+
| Chain Id (8 Bytes) | 16
1030+
| Address (20 hex values without '0x') | 40
1031+
| Name (up to 16 ascii characters, 32 hex values - without '0x') | variable (max 32)
1032+
|==============================================================================================================================
1033+
1034+
###### Case with Derivation Path
1035+
1036+
[width="80%"]
1037+
|==============================================================================================================================
1038+
| *Description* | *Length*
1039+
| Chain Id (8 Bytes) | 16
1040+
| Derivation Path (1 Byte length + n x 4 Bytes) | Max 42 (5 x 4 + 1) x 2
1041+
| Name (up to 16 ascii characters, 32 hex values - without '0x') | variable (max 32)
1042+
|==============================================================================================================================
1043+
1044+
1045+
##### If P1 == `update multiple account`
1046+
1047+
Compared to the previous `update an account`, the principle here is to chain multiple APDU
1048+
to update (_Add_/_Rename_) several Address Book entries at once.
1049+
The review/confirmation will be displayed only once when all APDU have been sent.
1050+
Thus, the last APDU must be distinguished using the P2 value.
1051+
1052+
###### Case with Address
1053+
1054+
[width="80%"]
1055+
|==============================================================================================================================
1056+
| *Description* | *Length*
1057+
| Chain Id (8 Bytes) | 16
1058+
| Address (20 hex values without '0x') | 40
1059+
| Name (up to 16 ascii characters, 32 hex values - without '0x') | variable (max 32)
1060+
|==============================================================================================================================
1061+
1062+
###### Case with Derivation Path
1063+
1064+
[width="80%"]
1065+
|==============================================================================================================================
1066+
| *Description* | *Length*
1067+
| Chain Id (8 Bytes) | 16
1068+
| Derivation Path (1 Byte length + n x 4 Bytes) | Max 42 (5 x 4 + 1) x 2
1069+
| Name (up to 16 ascii characters, 32 hex values - without '0x') | variable (max 32)
1070+
|==============================================================================================================================
1071+
1072+
_Output data_
1073+
1074+
##### If P1 == `get account`
1075+
1076+
[width="80%"]
1077+
|==============================================================================================================================
1078+
| *Description* | *Length*
1079+
| Chain Id (8 Bytes) | 16
1080+
| Address (20 hex values without '0x') | 40
1081+
| Account Name (up to 16 ascii characters, 32 hex values - without '0x') | variable (max 32)
1082+
|==============================================================================================================================
1083+
1084+
1085+
_Status Word_
1086+
1087+
The returned Status Word depends on the command:
1088+
1089+
##### If P1 == `update multiple account`
1090+
1091+
For each intermediate APDU, the Status Word will contain the remaining available entries in the lower bits.
1092+
For example, it will return `0x9002` when the command is correctly completed, and there are still `2` remaining (free) entries.
1093+
Of course, after the *Last* one (with P2 = 0x01), it will be `0x9000`, indicating everything has been done and completed.
1094+
1095+
##### Other commands
1096+
1097+
The other commands will return `0x9000` when correctly completed.
1098+
1099+
##### Errors
1100+
1101+
In case of error, the _Status Word_ will be:
1102+
1103+
[width="80%"]
1104+
|==============================================================================================================================
1105+
| *Description* | *Status Word*
1106+
| Error in P1 / P2 parameters | 0x6B00
1107+
| Memory error: No more Address Book entries available | 0x6A80
1108+
| Requested Data not found | 0x6A88
1109+
| Add an account, but using an already assigned name | 0x6A80
1110+
| Update an account, but APDU length is inconsistent | 0x6983
1111+
| Add an account, but it is already present in the Address Book | 0x6985
1112+
|==============================================================================================================================
1113+
1114+
9631115

9641116
## Transport protocol
9651117

glyphs/filter32px.bmp

632 Bytes
Binary file not shown.

glyphs/list32px.bmp

192 Bytes
Binary file not shown.

glyphs/plus32px.bmp

632 Bytes
Binary file not shown.

glyphs/trash32px.bmp

192 Bytes
Binary file not shown.

src/apdu_constants.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define INS_EIP712_FILTERING 0x1E
2525
#define INS_ENS_GET_CHALLENGE 0x20
2626
#define INS_ENS_PROVIDE_INFO 0x22
27+
#define INS_FAVORITE_ACCOUNTS 0x30
2728
#define P1_CONFIRM 0x01
2829
#define P1_NON_CONFIRM 0x00
2930
#define P2_NO_CHAINCODE 0x00
@@ -32,6 +33,13 @@
3233
#define P1_MORE 0x80
3334
#define P2_EIP712_LEGACY_IMPLEM 0x00
3435
#define P2_EIP712_FULL_IMPLEM 0x01
36+
#define P1_FAVORITE_DELETE 0x01
37+
#define P1_FAVORITE_GET 0x02
38+
#define P1_FAVORITE_RENAME 0x03
39+
#define P1_FAVORITE_UPDATE 0x04
40+
#define P1_FAVORITE_UPDATE_MULTI 0x05
41+
#define P1_FAVORITE_UPDATE_PATH 0x06
42+
#define P1_FAVORITE_UPDATE_PATH_MULTI 0x07
3543

3644
#define COMMON_CLA 0xB0
3745
#define COMMON_INS_GET_WALLET_ID 0x04

src/main.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#include "commands_712.h"
3232
#include "challenge.h"
3333
#include "domain_name.h"
34+
#ifdef TARGET_STAX
35+
#include "feature_favoriteAccounts.h"
36+
#endif
3437

3538
unsigned char G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B];
3639

@@ -393,6 +396,15 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
393396
goto return_to_dashboard;
394397
#endif
395398

399+
#ifdef TARGET_STAX
400+
case INS_FAVORITE_ACCOUNTS:
401+
handleFavoriteAccounts(G_io_apdu_buffer[OFFSET_P1],
402+
G_io_apdu_buffer[OFFSET_P2],
403+
G_io_apdu_buffer + OFFSET_CDATA,
404+
G_io_apdu_buffer[OFFSET_LC]);
405+
break;
406+
#endif
407+
396408
default:
397409
THROW(0x6D00);
398410
break;

0 commit comments

Comments
 (0)