|
cryptnox-sdk-arduino 1.0.0
Arduino library for Cryptnox Hardware Wallet
|
Go to the source code of this file.
Functions | |
| int | fromHex (char c) |
| Convert a hexadecimal character to a byte value. | |
| bool | hexToBytes (const char *hex, uint8_t *out, size_t len) |
| Convert a hex string to a byte array. | |
| uint32_t | RlpEncodeWholeHeader (uint8_t *header_output, size_t header_cap, uint32_t total_len) |
| Encodes the RLP list header for a sequence of items. | |
| uint32_t | RlpEncodeItem (uint8_t *output, size_t output_cap, const uint8_t *input, uint32_t input_len) |
| Encodes a single RLP item. | |
| uint32_t | ConvertNumberToUintArray (uint8_t *str, uint64_t val) |
| Converts an unsigned integer into a big-endian byte array. | |
| size_t | trimLeadingZeros (uint8_t *out, size_t out_cap, const uint8_t *in, size_t in_len) |
| Trims leading zeros from a byte array. | |
| uint32_t ConvertNumberToUintArray | ( | uint8_t * | str, |
| uint64_t | val ) |
Converts an unsigned integer into a big-endian byte array.
Converts an unsigned integer to a big-endian byte array.
NEW-5: widened to uint64_t. Previously truncated Tx2 uint64 fields (nonce/fees/gasLimit/value) at 4 bytes, producing wrong-amount tx.
| [out] | str | Output buffer (at least 8 bytes). |
| [in] | val | Unsigned 64-bit integer to convert. |
Definition at line 190 of file util.cpp.
Referenced by rlpEncodeTxBody().
| int fromHex | ( | char | c | ) |
Convert a hexadecimal character to a byte value.
M-07: returns -1 on any non-hex character so callers can distinguish a true '0' from a parse error.
Definition at line 15 of file util.cpp.
Referenced by fetchNonce(), and hexToBytes().
| bool hexToBytes | ( | const char * | hex, |
| uint8_t * | out, | ||
| size_t | len ) |
Convert a hex string to a byte array.
H-03: validate input length before any read. Without this guard a truncated or malicious RPC response shorter than 2*len would cause out-of-bounds reads past the NUL terminator.
Definition at line 32 of file util.cpp.
References fromHex().
Referenced by encodeERC20Transfer(), and rlpEncodeTxBody().
| uint32_t RlpEncodeItem | ( | uint8_t * | output, |
| size_t | output_cap, | ||
| const uint8_t * | input, | ||
| uint32_t | input_len ) |
Encodes a single RLP item.
Encodes a single item in RLP format.
| [out] | output | Buffer where the encoded RLP item will be written. |
| [in] | input | Input data to encode. |
| [in] | input_len | Length of input data. |
Definition at line 123 of file util.cpp.
Referenced by rlpEncodeSignedTx().
| uint32_t RlpEncodeWholeHeader | ( | uint8_t * | header_output, |
| size_t | header_cap, | ||
| uint32_t | total_len ) |
Encodes the RLP list header for a sequence of items.
Encodes the total length into an RLP list header.
This function generates the RLP "whole header" for a list payload of length total_len, according to Ethereum RLP specification.
RLP encoding rules:
Example: total_len = 10 → header = C0 + 0x0A → C0 0A total_len = 100 → total_len = 0x64 (1 byte) → F8 64 total_len = 1024 → total_len = 0x0400 (2 bytes) → F9 04 00
This header is intended to be placed immediately before the concatenated items in an RLP list. For EIP-1559 typed transactions, it must appear after the type byte (0x02).
| [out] | header_output | Pointer where the encoded header will be written. |
| [in] | total_len | Length in bytes of all list items concatenated. |
Definition at line 76 of file util.cpp.
Referenced by rlpFinalize().
| size_t trimLeadingZeros | ( | uint8_t * | out, |
| size_t | out_cap, | ||
| const uint8_t * | in, | ||
| size_t | in_len ) |
Trims leading zeros from a byte array.
Removes leading zeros from a byte array.
| [out] | out | Output buffer. |
| [in] | in | Input buffer. |
| [in] | in_len | Length of input buffer. |
Definition at line 220 of file util.cpp.
Referenced by rlpEncodeSignedTx().