Skip to content

Commit bbbafcc

Browse files
Add a docs/ directory containing a mkdocs website
1 parent 3ac55f3 commit bbbafcc

35 files changed

+1044
-131
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore mkdocs build
2+
site/

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# ethereum-plugin-sdk
22

3-
This repository is meant to be linked as submodule and used in external plugins working with [app-ethereum](https://github.com/LedgerHQ/app-ethereum).
4-
It is composed of a few headers containing definitions about app-ethereum's internal transaction parsing state and some structures to communicate via shared memory.
3+
This repository is meant to be used as a submodule for ethereum plugins working with [app-ethereum](https://github.com/LedgerHQ/app-ethereum).
4+
5+
Please find the full documentation here [ethereum-plugin-sdk](https://ethereum-plugin-sdk.ledger.com).

docs/img/Ledger-logo-696.webp

786 Bytes
Loading

docs/index.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Ethereum plugin documentation
2+
3+
This documentation will help you design your own ethereum plugin.
4+
5+
## What is a plugin?
6+
7+
A plugin is a lightweight application that only performs smart contract parsing and leverages the Ethereum application for the rest.
8+
9+
Your plugin will allow your users to clear-sign your smart contracts when using a Ledger device.
10+
11+
Plugins are designed to work hand-in-hand with the Ethereum application:
12+
13+
- The plugin handle the smart contract parsing
14+
- The Ethereum application handles everything else (APDU reception, signature, screen management, bluetooth, etc)
15+
16+
Upon your smart contract reception, the Ethereum application will call your plugin to query the elements to display and your plugin will be responsible for:
17+
18+
- Extracting the relevant information from the smart contract.
19+
- Replying the string to be displayed back to the Ethereum App.
20+
21+
## Coding my own plugin
22+
23+
### Use the Ethereum Plugin SDK
24+
25+
Use the Ledger developed [Ethereum Plugin SDK](https://github.com/LedgerHQ/ethereum-plugin-sdk).<br/>
26+
The SDK will do all the busy work of your plugin and leave you with only a few handlers to code.<br/>
27+
The SDK is designed to be used as a git submodule.
28+
29+
!!! note
30+
Always keep your SDK up to date with its **develop** branch.<br/>
31+
We are providing a CI workflow to help you check that the latest version is being used.
32+
33+
### Fork the Plugin Boilerplate
34+
35+
While starting a new plugin application from a blank repository + the SDK is technically possible, it is not *at all* recommended and support would not be provided.<br/>
36+
Instead, fork our official template application [Plugin Boilerplate](https://github.com/LedgerHQ/app-plugin-boilerplate) and start from there.
37+
38+
You will start with a correct build structure, examples of handlers, our test framework working, and the CI workflows already setup.
39+
40+
## Plugin file structure
41+
42+
- `.github/workflows`: the [CI workflows](test_framework/ci.md) required to showcase your plugin's quality.
43+
- `Makefile`: The entry point of the compilation of your plugin.
44+
- `PLUGIN_SPECIFICATION.md`: The specification of the supported smart-contract and selectors of your plugin.
45+
- `ethereum-plugin-sdk/`: This repository contains the interface between the Ethereum app and your plugin, as well as a lot of utility functions.
46+
- `fuzzing/`: the [Fuzzer](test_framework/fuzzing.md) folder.
47+
- `glyphs/`: The icon displayed by the Ethereum application when using the plugin on a Touchscreen device.
48+
- `icons/`: The icons displayed on the device dashboard on any device.
49+
- `ledger_app.toml`: the [Manifest](https://github.com/LedgerHQ/ledgered/blob/master/doc/manifest.md) of your plugin, used to bridge with the Ledger developed tools.
50+
- `src/`: the source code of the plugin (in C).
51+
- `tests/`: the [tests](test_framework/ragger.md) folder.

docs/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mkdocs
2+
pymdown-extensions
3+
mkdocs-material
4+
mkdocs-mermaid2-plugin
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
This diagram showcases a complete sequence of the parsing, display, and signature of a smart contract.
2+
3+
```mermaid
4+
sequenceDiagram
5+
participant L as Ledger Live
6+
participant E as Ethereum application
7+
participant SDK as Plugin SDK
8+
participant P as Plugin
9+
L->>E: SET_EXTERNAL_PLUGIN
10+
E->>+SDK: ETH_PLUGIN_CHECK_PRESENCE
11+
SDK->>-E: ack;
12+
L->>+E: Transaction to sign
13+
Note over E: The plugin for this smart<br/>contract exists, rely on it
14+
E->>+SDK: ETH_PLUGIN_INITIALIZE
15+
SDK->>+P: handle_init_contract()
16+
Note over P: Your code here
17+
P->>-SDK: return;
18+
SDK->>-E: ;
19+
Note over E: Split contract data in chunks
20+
loop Send smart contract chunks
21+
E->>+SDK: ETH_PLUGIN_PROVIDE_PARAMETER
22+
SDK->>+P: handle_provide_parameter()
23+
Note over P: Your code here
24+
P->>-SDK: return;
25+
SDK->>-E: ;
26+
end
27+
Note over E: Inform plugin that everything was sent
28+
E->>+SDK: ETH_PLUGIN_FINALIZE
29+
SDK->>+P: handle_finalize()
30+
Note over P: Your code here
31+
P->>-SDK: Number of screens needed<br/>Ask ERC20 tokens info if needed
32+
SDK->>-E: ;
33+
opt
34+
Note over L: Knows that Ethereum<br/>will need ERC20 token info
35+
L->>E: Provide ERC20 token
36+
E->>+SDK: ETH_PLUGIN_PROVIDE_TOKEN
37+
SDK->>+P: handle_provide_token()
38+
Note over P: Your code here
39+
P->>-SDK: Update screens number
40+
SDK->>-E: ;
41+
end
42+
Note over E: Ready to start display
43+
E->>+SDK: ETH_PLUGIN_QUERY_CONTRACT_ID
44+
SDK->>+P: handle_query_contract_id()
45+
Note over P: Your code here
46+
P->>-SDK: Provide title screen
47+
SDK->>-E: ;
48+
loop For every screen requested
49+
E->>+SDK: ETH_PLUGIN_QUERY_CONTRACT_UI
50+
SDK->>+P: handle_query_contract_ui()
51+
Note over P: Your code here
52+
P->>-SDK: Provide screen
53+
SDK->>-E: ;
54+
end
55+
Note over E: User validates or rejects
56+
E->>-L: Transaction signed / rejected
57+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
!!! warning
2+
Global variables should **never** be used in your plugin. Only the semi-persistent context provided by the Ethereum application should be used.
3+
4+
Each call by the Ethereum application starts the plugin anew with a fresh main call: everything not saved in the context is lost.
5+
6+
In order to retain knowledge from a handler call to another, the plugin can use a memory section allocated by the Ethereum application.
7+
8+
The context can be accessed through the `uint8_t *pluginContext` field of the parameter. All handlers will pass it to your plugin and it's common to your plugin's lifetime from the init call to the display.
9+
10+
The ethereum application will never modify the content of the structure.
11+
12+
This is the size available for the context of your plugin:
13+
```c
14+
--8<-- "src/eth_plugin_interface.h:plugin_context"
15+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# handle_finalize()
2+
3+
## Handle explanation
4+
5+
--8<-- "src/eth_plugin_interface.h:handle_finalize_explanation"
6+
7+
## Fields descriptions
8+
9+
```c
10+
--8<-- "src/eth_plugin_interface.h:handle_finalize_parameters"
11+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# handle_init_contract()
2+
3+
## Handle explanation
4+
5+
--8<-- "src/eth_plugin_interface.h:handle_init_contract_explanation"
6+
7+
## Fields descriptions
8+
9+
```c
10+
--8<-- "src/eth_plugin_interface.h:handle_init_contract_parameters"
11+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# handle_provide_parameter()
2+
3+
## Handle explanation
4+
5+
--8<-- "src/eth_plugin_interface.h:handle_provide_parameter_explanation"
6+
7+
## Fields descriptions
8+
9+
```c
10+
--8<-- "src/eth_plugin_interface.h:handle_provide_parameter_parameters"
11+
```

0 commit comments

Comments
 (0)