Skip to content

Commit d129d1c

Browse files
committed
Updated documentation
1 parent d04d9e8 commit d129d1c

File tree

26 files changed

+112
-21
lines changed

26 files changed

+112
-21
lines changed

.circleci/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build:
2+
docker build . -f images/ubuntu_1804/Dockerfile -t anyledger/base
3+
docker build . -f images/develop/Dockerfile -t anyledger/develop

.circleci/download_solc.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
set -e
44
set -x
5-
SOLC_URL_LINUX='https://github.com/ethereum/solidity/releases/download/v0.4.23/solc-static-linux'
6-
SOLC_VERSION='v0.4.23'
5+
SOLC_VERSION='v0.5.10'
6+
SOLC_URL_LINUX="https://github.com/ethereum/solidity/releases/download/${SOLC_VERSION}/solc-static-linux"
77

88
fail() {
99
if [[ $- == *i* ]]; then
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#
2+
# dockerfile for "developer" image
3+
#
4+
FROM anyledger/base:latest
5+
6+
WORKDIR /home/circleci
7+
ENV HOME /home/circleci
8+
9+
COPY build_zephyr_nrf52840_pca10056.sh /home/circleci
10+
RUN chmod +x build_zephyr_nrf52840_pca10056.sh
11+
RUN ./build_zephyr_nrf52840_pca10056.sh

BUILD-qemu.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This document describes how to start `anyledger-wallet` project using a QEMU vir
2727

2828
2) build the wallet
2929

30-
`$ mkdir build && cd build && cmake -GNinja -DBOARD=qemu_x86 -DBUILD_XCOMPILE=1 ../ && ninja`
30+
`$ mkdir build && cd build && cmake -GNinja -DBOARD=qemu_x86 -DBUILD_XCOMPILE=1 ../examples/wallet && ninja`
3131

3232
## part three: play with the wallet
3333
1) run the emulator (the wallet prompt should appear immediately)

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ A working `solc` should be available in your `$PATH`. See the [Installation inst
5353

5454
### x86 build
5555

56-
This build is used to develop and test the wallet library on your desktop.
56+
This build is used to develop and test the wallet library on your desktop. It does not include any working application - its purpose is to provide a compileable framework
57+
for unit testing of the individual components on POSIX system. You should always start with this build if you plan to do any changes to the core components.
5758

5859
1) clone wallet repo
5960
`git clone [email protected]:AnyLedger/anyledger-wallet.git && cd anyledger-wallet`
6061

6162
2) create build directory and generate build targets
62-
`mkdir build && cd build && cmake -GNinja ../`
63+
`mkdir build && cd build && cmake -GNinja ../examples/tests`
6364

6465
3) compile the library & run the tests
6566
`ninja && ctest`
@@ -69,15 +70,29 @@ This build is used to develop and test the wallet library on your desktop.
6970
Prerequisites: a working zephyr SDK (at least v0.9.5), see [here](https://docs.zephyrproject.org/latest/getting_started/getting_started.html) for instructions.
7071
Please make sure you can compile and flash at least blinky example before building the wallet.
7172

73+
Before using the actual hardware, you will probably want to test the functionality using the zephyr's QEMU image. (Use `-DBOARD=x86_qemu` when running `cmake`)
74+
7275
1) clone wallet repo to the zephyr's `samples` directory
7376
`mkdir samples/anyledger/ && git clone [email protected]:AnyLedger/anyledger-wallet.git`
7477

7578
2) create build directory and generate build targets
76-
`cd samples/anyledger/anyledger-wallet/build && cmake -GNinja -DBOARD=nrf52840_pca10056 -DBUILD_XCOMPILE=1 ../`
79+
`mkdir -p samples/anyledger/anyledger-wallet/build && cd samples/anyledger/anyledger-wallet/build && cmake -GNinja -DBOARD=nrf52840_pca10056 -DBUILD_XCOMPILE=1 ../examples/wallet`
7780

78-
3) compile & flash the firmware
81+
3) for hardware builds, compile & flash the firmware
7982
`ninja && ninja flash`
8083

8184
## Using AnyLedger wallet
8285

8386
To start AnyLedger wallet using a QEMU virtual machine, [see here](https://github.com/AnyLedger/anyledger-wallet/blob/master/BUILD-qemu.md).
87+
88+
## Project structure
89+
90+
- `abi_compiler` - python tool for compiling Ethereum ABI definition into a C code
91+
- `eth` - ethereum transaction utilities
92+
- `utils` - string manipulation, JSON en+de-coding, run-length encoding, uint256 manipulators
93+
- `examples` - examples of the actual apps
94+
- `sawtooth` - Hyperledger sawtooth utilities
95+
- `thirdparty` - CMakeFiles for 3rd party modules
96+
- `tools` - random helper scripts
97+
- `wallet` - MacOs compatibility hack
98+
- `zephyr-wallet` - Zephyr-specific code for the AnyLedger wallet

eth/address.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ extern "C" {
1212
typedef struct {
1313
uint8_t a[20];
1414
} address_t;
15+
16+
// ETH privkey to address conversion
1517
int privkey_to_ethereum_address(const uint8_t *privkey, address_t *addr_out);
18+
19+
// derive address from a signature (ecrecover)
1620
int address_from_signature(const uint8_t *data, size_t data_len, const signature_t *signature, address_t *addr_out);
1721

1822
#ifdef __cplusplus

eth/sign.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,21 @@ typedef struct {
1717
uint8_t v;
1818
} signature_t;
1919

20-
// signature is 32 bytes
20+
// sign a data using provided @privkey
21+
// @param privkey: privkey to use
22+
// @param data: data to sign
23+
// @param data_len: length of the data
24+
// @param signature: signature is stored here. The parameter must have size of at least 65 bytes
2125
int eth_sign(const uint8_t *privkey, const uint8_t *data, size_t data_len, uint8_t *signature);
26+
// create a keccak256 digest of a data
27+
// @param data: data to digest
28+
// @param data_len: length of the data
29+
// @param digest: digest is stored here. The parameter must have size of at least 32 bytes.
2230
int eth_digest_message(const uint8_t *data, size_t data_len, uint8_t *digest);
31+
32+
// sign keccak256(data). the signature parameter must have size of at least 65 bytes.
2333
int eth_sign_data_rawsig(const uint8_t *privkey, const uint8_t *data, size_t data_len, uint8_t *signature);
34+
// sign keccak256(data) and store the signature as r, v, s values
2435
int eth_sign_data(const uint8_t *privkey, const uint8_t *data, size_t data_len, signature_t *out);
2536

2637
int privkey_to_pubkey(const uint8_t *privkey, uint8_t *pubkey);

eth/transaction.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extern "C" {
1616
#endif
1717
#define SIGNATURE_LENGTH 64
1818

19+
// a generic ethereum transaction
1920
typedef struct {
2021
uint32_t nonce;
2122
uint32_t gas_price;
@@ -26,20 +27,27 @@ typedef struct {
2627
size_t data_len;
2728
} transaction_t;
2829

30+
// ethereum transaction hash
2931
typedef struct {
3032
uint8_t h[32];
3133
} tx_hash_t;
3234

35+
// basic transaction receipt
3336
typedef struct {
3437
uint64_t blockNumber;
3538
uint8_t status;
3639
} tx_receipt_t;
3740

41+
// set 'to' parameter of the transaction
42+
// @param to_hex: ASCII-encoded address
3843
int tx_set_to(transaction_t *tx, const char *to_hex);
44+
// set 'value' parameter of the transaction (64bit)
45+
// @param val: value
3946
void tx_set_value_u64(transaction_t *tx, uint64_t val);
4047

48+
// encode an ethereum transaction and store result in the buffer
4149
int tx_encode(const transaction_t *tx, const signature_t *sig, uint8_t *buf, size_t buf_size);
42-
// create pre-EIP155 tx
50+
// create pre-EIP155 signed tx
4351
int tx_encode_sign(const transaction_t *tx, const uint8_t *privkey, uint8_t *buf, size_t buf_size);
4452

4553

eth/web3.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,22 @@
1111
extern "C" {
1212
#endif
1313

14+
// Module that generates JSON-RPC strings for querying the state of an ethereum network
15+
1416
typedef struct {
1517
uint8_t *buf;
1618
size_t buf_size;
1719
size_t buf_used;
1820
uint32_t req_id;
1921
} web3_ctx_t;
2022

23+
// initialize the web3 module
24+
// @param web3: web3 context to use
25+
// @param buf: buffer to use for the outgoing requests
26+
// @param buf_size: buffer size
2127
void web3_init(web3_ctx_t *web3, uint8_t *buf, size_t buf_size);
2228

23-
// what to filter out when assembling tx JSON
29+
// tx flags: what to filter out when assembling tx JSON
2430
#define TX_NO_FROM 1 << 0
2531
#define TX_NO_GAS 1 << 1
2632
#define TX_NO_GASPRICE 1 << 2

eth/web3_jsonp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
extern "C" {
1313
#endif
1414

15+
// JSON-RPC reply decoder
16+
1517
typedef struct {
1618
long code;
1719
const char *message;
@@ -22,7 +24,9 @@ typedef struct {
2224
jsonrpc_error_t error;
2325
} jsonrpc_result_t;
2426

27+
// decode 'hexencoded' result (i.e. result of a eth_blockNumber call)
2528
int jsonrpc_decode_hexencoded(uint8_t *buf, size_t buf_size, jsonrpc_result_t *result, uint256_t *out);
29+
// decode transaction receipt
2630
int jsonrpc_decode_txreceipt(uint8_t *buf, size_t buf_size, jsonrpc_result_t *result, tx_receipt_t *out);
2731

2832
#ifdef __cplusplus

0 commit comments

Comments
 (0)