Nano cryptocurrency C library with P2PoW/DPoW support
1.0.0
|
#include <errors.h>
#include <stdint.h>
#include <f_util.h>
#include <f_bitcoin.h>
#include <version.h>
Go to the source code of this file.
Data Structures | |
struct | f_block_transfer_t |
struct | f_nano_encrypted_wallet_t |
struct | f_nano_crypto_wallet_t |
struct | f_nano_wallet_info_bdy_t |
struct | f_nano_wallet_info_t |
Macros | |
#define | F_NANO_POW_MAX_THREAD (size_t)10 |
#define | MAX_STR_NANO_CHAR (size_t)70 |
#define | PUB_KEY_EXTENDED_MAX_LEN (size_t)40 |
#define | NANO_PREFIX "nano_" |
#define | XRB_PREFIX "xrb_" |
#define | NANO_ENCRYPTED_SEED_FILE "/spiffs/secure/nano.nse" |
#define | NANO_PASSWD_MAX_LEN (size_t)80 |
#define | STR_NANO_SZ (size_t)66 |
#define | NANO_FILE_WALLETS_INFO "/spiffs/secure/walletsinfo.i" |
#define | F_BLOCK_TRANSFER_SIZE (size_t)sizeof(F_BLOCK_TRANSFER) |
#define | F_P2POW_BLOCK_TRANSFER_SIZE 2*F_BLOCK_TRANSFER_SIZE |
#define | REP_XRB (uint8_t)0x4 |
#define | SENDER_XRB (uint8_t)0x02 |
#define | DEST_XRB (uint8_t)0x01 |
#define | F_BRAIN_WALLET_VERY_POOR (uint32_t)0 |
#define | F_BRAIN_WALLET_POOR (uint32_t)1 |
#define | F_BRAIN_WALLET_VERY_BAD (uint32_t)2 |
#define | F_BRAIN_WALLET_BAD (uint32_t)3 |
#define | F_BRAIN_WALLET_VERY_WEAK (uint32_t)4 |
#define | F_BRAIN_WALLET_WEAK (uint32_t)5 |
#define | F_BRAIN_WALLET_STILL_WEAK (uint32_t)6 |
#define | F_BRAIN_WALLET_MAYBE_GOOD (uint32_t)7 |
#define | F_BRAIN_WALLET_GOOD (uint32_t)8 |
#define | F_BRAIN_WALLET_VERY_GOOD (uint32_t)9 |
#define | F_BRAIN_WALLET_NICE (uint32_t)10 |
#define | F_BRAIN_WALLET_PERFECT (uint32_t)11 |
#define | F_SIGNATURE_RAW (uint32_t)1 |
#define | F_SIGNATURE_STRING (uint32_t)2 |
#define | F_SIGNATURE_OUTPUT_RAW_PK (uint32_t)4 |
#define | F_SIGNATURE_OUTPUT_STRING_PK (uint32_t)8 |
#define | F_SIGNATURE_OUTPUT_XRB_PK (uint32_t)16 |
#define | F_SIGNATURE_OUTPUT_NANO_PK (uint32_t)32 |
#define | F_IS_SIGNATURE_RAW_HEX_STRING (uint32_t)64 |
#define | F_MESSAGE_IS_HASH_STRING (uint32_t)128 |
#define | F_DEFAULT_THRESHOLD (uint64_t) 0xffffffc000000000 |
#define | F_VERIFY_SIG_NANO_WALLET (uint32_t)1 |
#define | F_PUBLIC_KEY_RAW_HEX (uint32_t)2 |
#define | F_PUBLIC_KEY_ASCII_HEX (uint32_t)4 |
#define | F_BALANCE_RAW_128 F_NANO_A_RAW_128 |
#define | F_BALANCE_REAL_STRING F_NANO_A_REAL_STRING |
#define | F_BALANCE_RAW_STRING F_NANO_A_RAW_STRING |
#define | F_VALUE_SEND_RECEIVE_RAW_128 F_NANO_B_RAW_128 |
#define | F_VALUE_SEND_RECEIVE_REAL_STRING F_NANO_B_REAL_STRING |
#define | F_VALUE_SEND_RECEIVE_RAW_STRING F_NANO_B_RAW_STRING |
#define | F_VALUE_TO_SEND (int)(1<<0) |
#define | F_VALUE_TO_RECEIVE (int)(1<<1) |
#define | F_FEE_VALUE_RAW_128 F_NANO_B_RAW_128 |
#define | F_FEE_VALUE_REAL_STRING F_NANO_B_REAL_STRING |
#define | F_FEE_VALUE_RAW_STRING F_NANO_B_RAW_STRING |
Typedefs | |
typedef uint8_t | F_TOKEN[16] |
typedef uint8_t | NANO_SEED[crypto_sign_SEEDBYTES] |
typedef uint8_t | f_uint128_t[16] |
typedef uint8_t | NANO_PRIVATE_KEY[sizeof(NANO_SEED)] |
typedef uint8_t | NANO_PRIVATE_KEY_EXTENDED[crypto_sign_ed25519_SECRETKEYBYTES] |
typedef uint8_t | NANO_PUBLIC_KEY[crypto_sign_ed25519_PUBLICKEYBYTES] |
typedef uint8_t | NANO_PUBLIC_KEY_EXTENDED[PUB_KEY_EXTENDED_MAX_LEN] |
typedef enum f_nano_err_t | f_nano_err |
typedef enum f_write_seed_err_t | f_write_seed_err |
typedef enum f_file_info_err_t | F_FILE_INFO_ERR |
typedef enum f_nano_create_block_dyn_err_t | F_NANO_CREATE_BLOCK_DYN_ERR |
typedef enum f_nano_p2pow_block_dyn_err_t | F_NANO_P2POW_BLOCK_DYN_ERR |
Functions | |
struct f_block_transfer_t | __attribute__ ((packed)) F_BLOCK_TRANSFER |
double | to_multiplier (uint64_t, uint64_t) |
uint64_t | from_multiplier (double, uint64_t) |
void | f_set_dictionary_path (const char *) |
char * | f_get_dictionary_path (void) |
int | f_generate_token (F_TOKEN, void *, size_t, const char *) |
int | f_verify_token (F_TOKEN, void *, size_t, const char *) |
int | f_cloud_crypto_wallet_nano_create_seed (size_t, char *, char *) |
int | f_generate_nano_seed (NANO_SEED, uint32_t) |
int | pk_to_wallet (char *, char *, NANO_PUBLIC_KEY_EXTENDED) |
int | f_seed_to_nano_wallet (NANO_PRIVATE_KEY, NANO_PUBLIC_KEY, NANO_SEED, uint32_t) |
int | f_nano_is_valid_block (F_BLOCK_TRANSFER *) |
int | f_nano_block_to_json (char *, size_t *, size_t, F_BLOCK_TRANSFER *) |
int | f_nano_get_block_hash (uint8_t *, F_BLOCK_TRANSFER *) |
int | f_nano_get_p2pow_block_hash (uint8_t *, uint8_t *, F_BLOCK_TRANSFER *) |
int | f_nano_p2pow_to_JSON (char *, size_t *, size_t, F_BLOCK_TRANSFER *) |
char * | f_nano_key_to_str (char *, unsigned char *) |
int | f_nano_seed_to_bip39 (char *, size_t, size_t *, NANO_SEED, char *) |
int | f_bip39_to_nano_seed (uint8_t *, char *, char *) |
int | f_parse_nano_seed_and_bip39_to_JSON (char *, size_t, size_t *, void *, int, const char *) |
int | f_read_seed (uint8_t *, const char *, void *, int, int) |
int | f_nano_raw_to_string (char *, size_t *, size_t, void *, int) |
int | f_nano_valid_nano_str_value (const char *) |
int | valid_nano_wallet (const char *) |
int | nano_base_32_2_hex (uint8_t *, char *) |
int | f_nano_transaction_to_JSON (char *, size_t, size_t *, NANO_PRIVATE_KEY_EXTENDED, F_BLOCK_TRANSFER *) |
int | valid_raw_balance (const char *) |
int | is_null_hash (uint8_t *) |
int | is_nano_prefix (const char *, const char *) |
F_FILE_INFO_ERR | f_get_nano_file_info (F_NANO_WALLET_INFO *) |
F_FILE_INFO_ERR | f_set_nano_file_info (F_NANO_WALLET_INFO *, int) |
f_nano_err | f_nano_value_compare_value (void *, void *, uint32_t *) |
f_nano_err | f_nano_verify_nano_funds (void *, void *, void *, uint32_t) |
f_nano_err | f_nano_parse_raw_str_to_raw128_t (uint8_t *, const char *) |
f_nano_err | f_nano_parse_real_str_to_raw128_t (uint8_t *, const char *) |
f_nano_err | f_nano_add_sub (void *, void *, void *, uint32_t) |
int | f_nano_sign_block (F_BLOCK_TRANSFER *, F_BLOCK_TRANSFER *, NANO_PRIVATE_KEY_EXTENDED) |
f_write_seed_err | f_write_seed (void *, int, uint8_t *, char *) |
f_nano_err | f_nano_balance_to_str (char *, size_t, size_t *, f_uint128_t) |
int | f_extract_seed_from_brainwallet (uint8_t *, char **, uint32_t, const char *, const char *) |
int | f_verify_work (uint64_t *, const unsigned char *, uint64_t *, uint64_t) |
int | f_sign_data (unsigned char *signature, void *out_public_key, uint32_t ouput_type, const unsigned char *message, size_t msg_len, const unsigned char *private_key) |
int | f_verify_signed_data (const unsigned char *, const unsigned char *, size_t, const void *, uint32_t) |
int | f_is_valid_nano_seed_encrypted (void *, size_t, int) |
int | nano_create_block_dynamic (F_BLOCK_TRANSFER **, const void *, size_t, const void *, size_t, const void *, size_t, const void *, const void *, uint32_t, const void *, size_t, int) |
int | nano_create_p2pow_block_dynamic (F_BLOCK_TRANSFER **, F_BLOCK_TRANSFER *, const void *, size_t, const void *, uint32_t, const void *, size_t) |
int | f_verify_signed_block (F_BLOCK_TRANSFER *) |
int | f_nano_pow (uint64_t *, unsigned char *, const uint64_t, int) |
Variables | |
uint8_t | preamble [32] |
uint8_t | account [32] |
uint8_t | previous [32] |
uint8_t | representative [32] |
f_uint128_t | balance |
uint8_t | link [32] |
uint8_t | signature [64] |
uint8_t | prefixes |
uint64_t | work |
uint8_t | sub_salt [32] |
uint8_t | iv [16] |
uint8_t | reserved [16] |
uint8_t | hash_sk_unencrypted [32] |
uint8_t | sk_encrypted [32] |
uint8_t | nano_hdr [sizeof(NANO_WALLET_MAGIC)] |
uint32_t | ver |
uint8_t | description [F_DESC_SZ] |
uint8_t | salt [32] |
F_ENCRYPTED_BLOCK | seed_block |
uint8_t | wallet_prefix |
uint32_t | last_used_wallet_number |
char | wallet_representative [MAX_STR_NANO_CHAR] |
char | max_fee [F_RAW_STR_MAX_SZ] |
uint8_t | header [sizeof(F_NANO_WALLET_INFO_MAGIC)] |
uint16_t | version |
char | desc [F_NANO_DESC_SZ] |
uint8_t | nanoseed_hash [32] |
uint8_t | file_info_integrity [32] |
F_NANO_WALLET_INFO_BODY | body |
This API Integrates Nano Cryptocurrency to low computational devices.
Definition in file f_nano_crypto_util.h.
#define DEST_XRB (uint8_t)0x01 |
Definition at line 440 of file f_nano_crypto_util.h.
#define F_BALANCE_RAW_128 F_NANO_A_RAW_128 |
Balance is RAW 128 bit.
Definition at line 1452 of file f_nano_crypto_util.h.
#define F_BALANCE_RAW_STRING F_NANO_A_RAW_STRING |
Balance is raw string.
Definition at line 1464 of file f_nano_crypto_util.h.
#define F_BALANCE_REAL_STRING F_NANO_A_REAL_STRING |
Balance is real string.
Definition at line 1458 of file f_nano_crypto_util.h.
#define F_BLOCK_TRANSFER_SIZE (size_t)sizeof(F_BLOCK_TRANSFER) |
Definition at line 291 of file f_nano_crypto_util.h.
#define F_BRAIN_WALLET_BAD (uint32_t)3 |
#define F_BRAIN_WALLET_GOOD (uint32_t)8 |
#define F_BRAIN_WALLET_MAYBE_GOOD (uint32_t)7 |
[maybe good for you].
Crack within one century
Definition at line 1233 of file f_nano_crypto_util.h.
#define F_BRAIN_WALLET_NICE (uint32_t)10 |
[very nice].
Crack withing one hundred thousand year
Definition at line 1252 of file f_nano_crypto_util.h.
#define F_BRAIN_WALLET_PERFECT (uint32_t)11 |
[Perfect!] 3.34x10^53 Years to crack
Definition at line 1258 of file f_nano_crypto_util.h.
#define F_BRAIN_WALLET_POOR (uint32_t)1 |
#define F_BRAIN_WALLET_STILL_WEAK (uint32_t)6 |
#define F_BRAIN_WALLET_VERY_BAD (uint32_t)2 |
#define F_BRAIN_WALLET_VERY_GOOD (uint32_t)9 |
#define F_BRAIN_WALLET_VERY_POOR (uint32_t)0 |
#define F_BRAIN_WALLET_VERY_WEAK (uint32_t)4 |
#define F_BRAIN_WALLET_WEAK (uint32_t)5 |
#define F_DEFAULT_THRESHOLD (uint64_t) 0xffffffc000000000 |
Default Nano Proof of Work Threshold.
Definition at line 1361 of file f_nano_crypto_util.h.
#define F_FEE_VALUE_RAW_128 F_NANO_B_RAW_128 |
P2PoW fee value is raw 128 bit.
Definition at line 1500 of file f_nano_crypto_util.h.
#define F_FEE_VALUE_RAW_STRING F_NANO_B_RAW_STRING |
P2PoW fee value is raw string.
Definition at line 1512 of file f_nano_crypto_util.h.
#define F_FEE_VALUE_REAL_STRING F_NANO_B_REAL_STRING |
P2PoW fee value is real string.
Definition at line 1506 of file f_nano_crypto_util.h.
#define F_IS_SIGNATURE_RAW_HEX_STRING (uint32_t)64 |
Signature is raw hex string flag.
Definition at line 1348 of file f_nano_crypto_util.h.
#define F_MESSAGE_IS_HASH_STRING (uint32_t)128 |
Message is raw hex hash string.
Definition at line 1355 of file f_nano_crypto_util.h.
#define F_NANO_POW_MAX_THREAD (size_t)10 |
(desktop only) Number of threads for Proof of Work routines.
Default 10
Definition at line 140 of file f_nano_crypto_util.h.
#define F_P2POW_BLOCK_TRANSFER_SIZE 2*F_BLOCK_TRANSFER_SIZE |
Definition at line 292 of file f_nano_crypto_util.h.
#define F_PUBLIC_KEY_ASCII_HEX (uint32_t)4 |
Public key is a hex ASCII encoded string.
Definition at line 1413 of file f_nano_crypto_util.h.
#define F_PUBLIC_KEY_RAW_HEX (uint32_t)2 |
Public key raw 32 bytes data.
Definition at line 1406 of file f_nano_crypto_util.h.
#define F_SIGNATURE_OUTPUT_NANO_PK (uint32_t)32 |
Public key is a NANO wallet encoded base32 string.
Definition at line 1341 of file f_nano_crypto_util.h.
#define F_SIGNATURE_OUTPUT_RAW_PK (uint32_t)4 |
#define F_SIGNATURE_OUTPUT_STRING_PK (uint32_t)8 |
Public key is hex ASCII encoded string.
Definition at line 1327 of file f_nano_crypto_util.h.
#define F_SIGNATURE_OUTPUT_XRB_PK (uint32_t)16 |
Public key is a XRB wallet encoded base32 string.
Definition at line 1334 of file f_nano_crypto_util.h.
#define F_SIGNATURE_RAW (uint32_t)1 |
#define F_SIGNATURE_STRING (uint32_t)2 |
Signature is hex ASCII encoded string.
Definition at line 1313 of file f_nano_crypto_util.h.
#define F_VALUE_SEND_RECEIVE_RAW_128 F_NANO_B_RAW_128 |
Value to send or receive is RAW 128 bit.
Definition at line 1470 of file f_nano_crypto_util.h.
#define F_VALUE_SEND_RECEIVE_RAW_STRING F_NANO_B_RAW_STRING |
Value to send or receive is raw string.
Definition at line 1482 of file f_nano_crypto_util.h.
#define F_VALUE_SEND_RECEIVE_REAL_STRING F_NANO_B_REAL_STRING |
Value to send or receive is real string.
Definition at line 1476 of file f_nano_crypto_util.h.
#define F_VALUE_TO_RECEIVE (int)(1<<1) |
Value to receive.
Definition at line 1494 of file f_nano_crypto_util.h.
#define F_VALUE_TO_SEND (int)(1<<0) |
Value to send.
Definition at line 1488 of file f_nano_crypto_util.h.
#define F_VERIFY_SIG_NANO_WALLET (uint32_t)1 |
Public key is a NANO wallet with XRB or NANO prefixes encoded base32 string.
Definition at line 1399 of file f_nano_crypto_util.h.
#define MAX_STR_NANO_CHAR (size_t)70 |
Defines a max size of Nano char (70 bytes)
Definition at line 152 of file f_nano_crypto_util.h.
#define NANO_ENCRYPTED_SEED_FILE "/spiffs/secure/nano.nse" |
Path to non deterministic encrypted file with password.
File containing the SEED of the Nano wallets generated by TRNG (if available in your Hardware) or PRNG.
Default name: "nano.nse"
Definition at line 194 of file f_nano_crypto_util.h.
#define NANO_FILE_WALLETS_INFO "/spiffs/secure/walletsinfo.i" |
Custom information file path about Nano SEED wallet stored in "walletsinfo.i".
Definition at line 212 of file f_nano_crypto_util.h.
#define NANO_PASSWD_MAX_LEN (size_t)80 |
Password max length.
Definition at line 200 of file f_nano_crypto_util.h.
#define NANO_PREFIX "nano_" |
Nano prefix.
Definition at line 164 of file f_nano_crypto_util.h.
#define PUB_KEY_EXTENDED_MAX_LEN (size_t)40 |
Max size of public key (extended)
Definition at line 158 of file f_nano_crypto_util.h.
#define REP_XRB (uint8_t)0x4 |
Representative XRB flag.
Destination XRB flag.
Sender XRB flag.
#define SENDER_XRB (uint8_t)0x02 |
Definition at line 434 of file f_nano_crypto_util.h.
#define STR_NANO_SZ (size_t)66 |
String size of Nano encoded Base32 including NULL char.
Definition at line 206 of file f_nano_crypto_util.h.
#define XRB_PREFIX "xrb_" |
XRB (old Raiblocks) prefix.
Definition at line 170 of file f_nano_crypto_util.h.
Typedef Error enumerator for info file functions.
typedef enum f_nano_create_block_dyn_err_t F_NANO_CREATE_BLOCK_DYN_ERR |
Error function enumerator.
typedef enum f_nano_p2pow_block_dyn_err_t F_NANO_P2POW_BLOCK_DYN_ERR |
typedef uint8_t F_TOKEN[16] |
Definition at line 218 of file f_nano_crypto_util.h.
f_uint128_t |
128 bit big number of Nano balance
Definition at line 230 of file f_nano_crypto_util.h.
typedef enum f_write_seed_err_t f_write_seed_err |
NANO_PRIVATE_KEY |
Size of Nano Private Key.
Definition at line 240 of file f_nano_crypto_util.h.
NANO_PRIVATE_KEY_EXTENDED |
Size of Nano Private Key extended.
Definition at line 246 of file f_nano_crypto_util.h.
NANO_PUBLIC_KEY |
Size of Nano Public Key.
Definition at line 252 of file f_nano_crypto_util.h.
NANO_PUBLIC_KEY_EXTENDED |
Size of Public Key Extended.
Definition at line 258 of file f_nano_crypto_util.h.
NANO_SEED |
Size of Nano SEED.
Definition at line 224 of file f_nano_crypto_util.h.
enum f_file_info_err_t |
Definition at line 546 of file f_nano_crypto_util.h.
Definition at line 606 of file f_nano_crypto_util.h.
enum f_nano_err_t |
Definition at line 305 of file f_nano_crypto_util.h.
Enumerator | |
---|---|
NANO_P2POW_CREATE_BLOCK_OK | |
NANO_P2POW_CREATE_BLOCK_INVALID_USER_BLOCK | |
NANO_P2POW_CREATE_BLOCK_MALLOC | |
NANO_P2POW_CREATE_BLOCK_NULL | |
NANO_P2POW_CREATE_OUTPUT | |
NANO_P2POW_CREATE_OUTPUT_MALLOC |
Definition at line 629 of file f_nano_crypto_util.h.
enum f_write_seed_err_t |
Definition at line 442 of file f_nano_crypto_util.h.
struct f_block_transfer_t __attribute__ | ( | (packed) | ) |
int f_bip39_to_nano_seed | ( | uint8_t * | seed, |
char * | str, | ||
char * | dictionary | ||
) |
Parse Nano Bip39 encoded string to raw Nano SEED given a dictionary file.
[out] | seed | Nano SEED |
[in] | str | A encoded Bip39 string pointer |
[in] | dictionary | A string pointer path to file |
WARNING Sensive data. Do not share any SEED or Bip39 encoded string !
0 | On Success, otherwise Error |
int f_cloud_crypto_wallet_nano_create_seed | ( | size_t | entropy, |
char * | file_name, | ||
char * | password | ||
) |
Generates a new SEED and saves it to an non deterministic encrypted file.
password is mandatory
[in] | entropy | Entropy type. Entropy type are: F_ENTROPY_TYPE_PARANOIC F_ENTROPY_TYPE_EXCELENT F_ENTROPY_TYPE_GOOD F_ENTROPY_TYPE_NOT_ENOUGH F_ENTROPY_TYPE_NOT_RECOMENDED |
[in] | file_name | The file and path to be stored in your file system directory. It can be NULL. If you parse a NULL value then file will be stored in NANO_ENCRYPTED_SEED_FILE variable file system pointer. |
[in] | password | Password of the encrypted file. It can NOT be NULL or EMPTY |
WARNING
f_cloud_crypto_wallet_nano_create_seed() does not verify your password. It is recommended to use a strong password like symbols, capital letters and numbers to keep your SEED safe and avoid brute force attacks.
You can use f_pass_must_have_at_least() function to check passwords strength
0 | On Success, otherwise Error |
int f_extract_seed_from_brainwallet | ( | uint8_t * | seed, |
char ** | warning_msg, | ||
uint32_t | allow_mode, | ||
const char * | brainwallet, | ||
const char * | salt | ||
) |
Analyzes a text given a mode and if pass then the text in braiwallet is translated to a Nano SEED.
[out] | seed | Output Nano SEED extracted from brainwallet |
[out] | warning_msg | Warning message parsed to application. It can be NULL |
[in] | allow_mode | Allow mode. Funtion will return SUCCESS only if permitted mode set by user Allow mode are:
|
[in] | brainwallet | Brainwallet text to be parsed. It can be NOT NULL or null string |
[in] | salt | Salt of the Braiwallet. It can be NOT NULL or null string |
0 | If success, otherwise error. |
int f_generate_nano_seed | ( | NANO_SEED | seed, |
uint32_t | entropy | ||
) |
Generates a new SEED and stores it to seed pointer.
[out] | seed | SEED generated in system PRNG or TRNG |
[in] | entropy | Entropy type. Entropy type are: F_ENTROPY_TYPE_PARANOIC F_ENTROPY_TYPE_EXCELENT F_ENTROPY_TYPE_GOOD F_ENTROPY_TYPE_NOT_ENOUGH F_ENTROPY_TYPE_NOT_RECOMENDED |
0 | On Success, otherwise Error |
int f_generate_token | ( | F_TOKEN | signature, |
void * | data, | ||
size_t | data_sz, | ||
const char * | password | ||
) |
Generates a non deterministic token given a message data and a password.
[out] | signature | 128 bit non deterministic token |
[in] | data | Data to be signed in token |
[in] | data_sz | Size of data |
[in] | password | Password |
0 | On Success, otherwise Error |
char * f_get_dictionary_path | ( | void | ) |
Get default dictionary path in myNanoEmbedded library.
Path | and name of the dictionary file |
F_FILE_INFO_ERR f_get_nano_file_info | ( | F_NANO_WALLET_INFO * | info | ) |
Opens default file walletsinfo.i (if exists) containing information F_NANO_WALLET_INFO structure and parsing to pointer info if success.
[out] | info | Pointer to buffer to be parsed struct from $PATH/walletsinfo.i file. |
F_FILE_INFO_ERR_OK | If Success, otherwise F_FILE_INFO_ERR enum type error |
int f_is_valid_nano_seed_encrypted | ( | void * | stream, |
size_t | stream_len, | ||
int | read_from | ||
) |
Verifies if ecrypted Nano SEED is valid.
[in] | stream | Encrypted binary data block coming from memory or file |
[in] | stream_len | size of stream data |
[in] | read_from | Source READ_SEED_FROM_STREAM if encrypted binary data is in memory or READ_SEED_FROM_FILE is in a file. |
0 | If invalid, greater than zero if is valid or error if less than zero. |
f_nano_err f_nano_add_sub | ( | void * | res, |
void * | valA, | ||
void * | valB, | ||
uint32_t | mode | ||
) |
Add/Subtract two Nano balance values and stores value in res
[out] | res | Result value res = valA + valB or res = valA - valB |
[in] | valA | Input balance A value |
[in] | valB | Input balance B value |
[in] | mode | Mode type:
|
NANO_ERR_OK | If Success, otherwise f_nano_err_t enum type error |
f_nano_err f_nano_balance_to_str | ( | char * | str, |
size_t | str_len, | ||
size_t * | out_len, | ||
f_uint128_t | value | ||
) |
Converts a raw Nano balance to string raw balance.
[out] | str | Output string pointer |
[in] | str_len | Size of string pointer memory |
[out] | out_len | Output length of converted value to string. If out_len is NULL then str returns converted value with NULL terminated string |
[in] | value | Raw Nano balance value |
0 | If success, otherwise error. |
int f_nano_block_to_json | ( | char * | dest, |
size_t * | olen, | ||
size_t | dest_size, | ||
F_BLOCK_TRANSFER * | user_block | ||
) |
Parse a Nano Block to JSON.
[out] | dest | Destination of the converted JSON block |
[out] | olen | Output length of the converted JSON block. olen can be NULL. If NULL, destination size contains a NULL char |
[in] | dest_size | Size of dest memory buffer |
[in] | user_block | User Nano block |
int f_nano_get_block_hash | ( | uint8_t * | hash, |
F_BLOCK_TRANSFER * | block | ||
) |
Gets a hash from Nano block.
[out] | hash | Output hash |
[in] | block | Nano Block |
int f_nano_get_p2pow_block_hash | ( | uint8_t * | user_hash, |
uint8_t * | fee_hash, | ||
F_BLOCK_TRANSFER * | block | ||
) |
Get Nano user block hash and Nano fee block hashes from P2PoW block.
[out] | user_hash | Hash of the user block |
[out] | fee_hash | Hash of the P2PoW block |
[in] | block | Input Nano Block |
int f_nano_is_valid_block | ( | F_BLOCK_TRANSFER * | block | ) |
Checks if Binary Nano Block is valid.
[in] | block | Nano Block |
char * f_nano_key_to_str | ( | char * | out, |
unsigned char * | key | ||
) |
Parse a raw binary public key to string.
[out] | out | Pointer to outuput string |
[in] | in | Pointer to raw public key |
int f_nano_p2pow_to_JSON | ( | char * | buffer, |
size_t * | olen, | ||
size_t | buffer_sz, | ||
F_BLOCK_TRANSFER * | block | ||
) |
Parse binary P2PoW block to JSON.
[out] | buffer | Output JSON string |
[out] | olen | Output JSON string size. olen can be NULL. If NULL, buffer will be terminated with a NULL char |
[in] | buffer_sz | Size of memory buffer |
[in] | block | P2PoW block |
f_nano_err f_nano_parse_raw_str_to_raw128_t | ( | uint8_t * | res, |
const char * | raw_str_value | ||
) |
Parse a raw string balance to raw big number 128 bit.
[out] | res | Binary raw balance |
[in] | raw_str_value | Raw balance string |
NANO_ERR_OK | If Success, otherwise f_nano_err_t enum type error |
f_nano_err f_nano_parse_real_str_to_raw128_t | ( | uint8_t * | res, |
const char * | real_str_value | ||
) |
Parse a real string balance to raw big number 128 bit.
[out] | res | Binary raw balance |
[in] | real_str_value | Real balance string |
NANO_ERR_OK | If Success, otherwise f_nano_err_t enum type error |
int f_nano_pow | ( | uint64_t * | PoW_res, |
unsigned char * | hash, | ||
const uint64_t | threshold, | ||
int | n_thr | ||
) |
Calculates a Proof of Work given a hash, threshold and number of threads n_thr
[out] | PoW_res | Output Proof of Work |
[in] | hash | Input hash |
[in] | threshold | Input threshold |
[in] | n_thr | Number of threads. Default maximum value: 10. You can modify F_NANO_POW_MAX_THREAD in f_nano_crypto_util.h |
Mandatory: You need to enable attach a random function to your project using f_random_attach()
0 | If success, otherwise error. |
int f_nano_raw_to_string | ( | char * | str, |
size_t * | olen, | ||
size_t | str_sz, | ||
void * | raw, | ||
int | raw_type | ||
) |
Converts Nano raw balance [string | f_uint128_t] to real string value.
[out] | str | Output real string value |
[out] | olen | Size of output real string value. It can be NULL. If NULL output str will have a NULL char at the end. |
[in] | str_sz | Size of str buffer |
[in] | raw | Raw balance. |
[in] | raw_type | Raw balance type:
|
0 | On Success, otherwise Error |
int f_nano_seed_to_bip39 | ( | char * | buf, |
size_t | buf_sz, | ||
size_t * | out_buf_len, | ||
NANO_SEED | seed, | ||
char * | dictionary_file | ||
) |
Parse Nano SEED to Bip39 encoding given a dictionary file.
[out] | buf | Output string containing encoded Bip39 SEED |
[in] | buf_sz | Size of memory of buf pointer |
[out] | out_buf_len | If out_buf_len is NOT NULL then out_buf_len returns the size of string encoded Bip39 and out with non NULL char. If out_buf_len is NULL then out has a string encoded Bip39 with a NULL char. |
[in] | seed | Nano SEED |
[in] | dictionary_file | Path to dictionary file |
WARNING Sensive data. Do not share any SEED or Bip39 encoded string !
0 | On Success, otherwise Error |
int f_nano_sign_block | ( | F_BLOCK_TRANSFER * | user_block, |
F_BLOCK_TRANSFER * | fee_block, | ||
NANO_PRIVATE_KEY_EXTENDED | private_key | ||
) |
Signs user_block and worker fee_block given a private key private_key
[in,out] | user_block | User block to be signed with a private key private_key |
[in,out] | fee_block | Fee block to be signed with a private key private_key. Can be NULL if worker does not require fee |
[in] | private_key | Private key to sign block(s) |
0 | If Success, otherwise error |
int f_nano_transaction_to_JSON | ( | char * | str, |
size_t | str_len, | ||
size_t * | str_out, | ||
NANO_PRIVATE_KEY_EXTENDED | private_key, | ||
F_BLOCK_TRANSFER * | block_transfer | ||
) |
Sign a block pointed in block_transfer with a given private_key and stores signed block to block_transfer and parse to JSON Nano RPC.
[out] | str | A string pointer to store JSON Nano RPC |
[in] | str_len | Size of buffer in str pointer |
[out] | str_out | Size of JSON string. str_out can be NULL |
[in] | private_key | Private key to sign the block block_transfer |
[in,out] | block_transfer | Nano block containing raw data to be stored in Nano Blockchain |
WARNING Sensive data. Do not share any PRIVATE KEY
0 | On Success, otherwise Error |
int f_nano_valid_nano_str_value | ( | const char * | str | ) |
Check if a real string or raw string are valid Nano balance.
[in] | str | Value to be checked |
0 | If valid, otherwise is invalid |
f_nano_err f_nano_value_compare_value | ( | void * | valA, |
void * | valB, | ||
uint32_t * | mode_compare | ||
) |
Comparare two Nano balance.
[in] | valA | Nano balance value A |
[in] | valB | Nano balance value B |
[in,out] | mode_compare | Input mode and output result Input mode:
|
NANO_ERR_OK | If Success, otherwise f_nano_err_t enum type error |
f_nano_err f_nano_verify_nano_funds | ( | void * | balance, |
void * | value_to_send, | ||
void * | fee, | ||
uint32_t | mode | ||
) |
Check if Nano balance has sufficient funds.
[in] | balance | Nano balance |
[in] | value_to_send | Value to send |
[in] | fee | Fee value (it can be NULL) |
[in] | mode | Value type mode
|
NANO_ERR_OK | If Success, otherwise f_nano_err_t enum type error |
int f_parse_nano_seed_and_bip39_to_JSON | ( | char * | dest, |
size_t | dest_sz, | ||
size_t * | olen, | ||
void * | source_data, | ||
int | source, | ||
const char * | password | ||
) |
Parse Nano SEED and Bip39 to JSON given a encrypted data in memory or encrypted data in file or unencrypted seed in memory.
[out] | dest | Destination JSON string pointer |
[in] | dest_sz | Buffer size of dest pointer |
[out] | olen | Size of the output JSON string. If NULL string JSON returns a NULL char at the end of string otherwise it will return the size of the string is stored into olen variable without NULL string in dest |
[in] | source_data | Input data source (encrypted file | encrypted data in memory | unencrypted seed in memory) |
[in] | source | Source data type:
|
[in] | password | Required for READ_SEED_FROM_STREAM and READ_SEED_FROM_FILE sources |
WARNING Sensive data. Do not share any SEED or Bip39 encoded string !
0 | On Success, otherwise Error |
int f_read_seed | ( | uint8_t * | seed, |
const char * | passwd, | ||
void * | source_data, | ||
int | force_read, | ||
int | source | ||
) |
Extracts a Nano SEED from encrypted stream in memory or in a file.
[out] | seed | Output Nano SEED |
[in] | passwd | Password (always required) |
[in] | source_data | Encrypted source data from memory or path pointed in source_data |
[in] | force_read | If non zero value then forces reading from a corrupted file. This param is ignored when reading source_data from memory |
[in] | source | Source data type:
|
WARNING Sensive data. Do not share any SEED !
0 | On Success, otherwise Error |
int f_seed_to_nano_wallet | ( | NANO_PRIVATE_KEY | private_key, |
NANO_PUBLIC_KEY | public_key, | ||
NANO_SEED | seed, | ||
uint32_t | wallet_number | ||
) |
Extracts one key pair from Nano SEED given a wallet number.
[out] | private_key | Private key of the wallet_number from given seed |
[out] | public_key | Public key of the wallet_number from given seed |
[in,out] | seed | Nano SEED |
[in] | wallet_number | Wallet number of key pair to be extracted from Nano SEED |
WARNING 1:
WARNING 2:
0 | On Success, otherwise Error |
void f_set_dictionary_path | ( | const char * | path | ) |
Set default dictionary file and path to myNanoEmbedded library.
[in] | path | Path to dictionary file |
If f_set_dictionary_path() is not used in myNanoEmbedded library then default path stored in BIP39_DICTIONARY is used
F_FILE_INFO_ERR f_set_nano_file_info | ( | F_NANO_WALLET_INFO * | info, |
int | overwrite_existing_file | ||
) |
Saves wallet information stored at buffer struct info to file walletsinfo.i
[in] | info | Pointer to data to be saved at $PATH/walletsinfo.i file. |
[in] | overwrite_existing_file | If non zero then overwrites file $PATH/walletsinfo.i |
F_FILE_INFO_ERR_OK | If Success, otherwise F_FILE_INFO_ERR enum type error |
int f_sign_data | ( | unsigned char * | signature, |
void * | out_public_key, | ||
uint32_t | ouput_type, | ||
const unsigned char * | message, | ||
size_t | msg_len, | ||
const unsigned char * | private_key | ||
) |
Signs a message with a deterministic signature given a private key
[out] | signature | Output signature |
[out] | out_public_key | Output public key. It can be NULL |
[in] | output_type | Output type of public key. Public key types are:
|
[in] | message | Message to be signed with Elliptic Curve Ed25519 with blake2b hash |
[in] | msg_len | Size of message to be signed |
[in] | private_key | Private key to sign message |
0 | If success, otherwise error. |
int f_verify_signed_block | ( | F_BLOCK_TRANSFER * | ) |
int f_verify_signed_data | ( | const unsigned char * | signature, |
const unsigned char * | message, | ||
size_t | message_len, | ||
const void * | public_key, | ||
uint32_t | pk_type | ||
) |
Verifies if a signed message is valid.
[in] | signature | Signature of the message |
[in] | message | Message to be verified |
[in] | message_len | Length of the message |
[in] | public_key | Public key to verify signed message |
[in] | pk_type | Type of the public key. Types are:
|
Return value are
int f_verify_token | ( | F_TOKEN | signature, |
void * | data, | ||
size_t | data_sz, | ||
const char * | password | ||
) |
Verifies if a token is valid given data and password.
[in] | signature | 128 bit non deterministic token |
[in] | data | Data to be signed in token |
[in] | data_sz | Size of data |
[in] | password | Password |
0 | On if invalid; 1 if valid ; less than zero if an error occurs |
int f_verify_work | ( | uint64_t * | result, |
const unsigned char * | hash, | ||
uint64_t * | work, | ||
uint64_t | threshold | ||
) |
Verifies if Proof of Work of a given hash is valid.
[out] | result | Result of work. It can be NULL |
[in] | hash | Input hash for verification |
[in] | work | Work previously calculated to be checked |
[in] | threshold | Input threshold |
0 | If is not valid or less than zero if error or greater than zero if is valid |
f_write_seed_err f_write_seed | ( | void * | source_data, |
int | source, | ||
uint8_t * | seed, | ||
char * | passwd | ||
) |
Writes a SEED into a ecrypted with password with non deterministic stream in memory or file.
[out] | source_data | Memory pointer or file name |
[in] | source | Source of output data:
|
[in] | seed | Nano SEED to be stored in encrypted stream or file |
[in] | passwd | (Mandatory) It can not be null string or NULL. See f_pass_must_have_at_least() function to check passwords strength |
0 | If Success, otherwise error |
uint64_t from_multiplier | ( | double | multiplier, |
uint64_t | base_difficulty | ||
) |
Calculates a PoW given a multiplier and base difficulty.
[in] | multiplier | Multiplier of the work |
[in] | base_difficulty | Base difficulty Details here |
Calculated | value |
int is_nano_prefix | ( | const char * | nano_wallet, |
const char * | prefix | ||
) |
Checks prefix in nano_wallet
[in] | nano_wallet | Base32 Nano wallet encoded string |
[in] | prefix | Prefix type
|
1 | If prefix in nano_wallet, otherwise 0 |
int is_null_hash | ( | uint8_t * | hash | ) |
Check if 32 bytes hash is filled with zeroes.
[in] | hash | 32 bytes binary hash |
1 | If zero filled buffer, otherwise 0 |
int nano_base_32_2_hex | ( | uint8_t * | res, |
char * | str_wallet | ||
) |
Parse Nano Base32 wallet string to public key binary.
[out] | res | Output raw binary public key |
[in] | str_wallet | Valid Base32 encoded Nano string to be parsed |
0 | On Success, otherwise Error |
int nano_create_block_dynamic | ( | F_BLOCK_TRANSFER ** | block, |
const void * | account, | ||
size_t | account_len, | ||
const void * | previous, | ||
size_t | previous_len, | ||
const void * | representative, | ||
size_t | representative_len, | ||
const void * | balance, | ||
const void * | value_to_send_or_receive, | ||
uint32_t | balance_and_val_to_send_or_rec_types, | ||
const void * | link, | ||
size_t | link_len, | ||
int | direction | ||
) |
Creates a Nano block dynamically in memory.
[out] | block | Pointer to new allocated Nano block |
[in] | account | nano or xrb or raw hex string or raw hex binary account (public key) |
[in] | account_len | Account length. If zero it is assumed as nano, xrb or raw hex string public key |
[in] | previous | Hex string or raw hex binary previous block |
[in] | previous_len | Previous length size. If zero it is assumed previous is a NULL terminated string |
[in] | representative | nano or xrb or raw hex string or raw hex binary representative account |
[in] | representative_len | Representative length. If zero it is assumed as nano, xrb or raw hex string representative |
[in] | balance | Real balance or raw string balance or raw binary balance |
[in] | value_to_send_or_receive | Real value to send or receive or raw string value to send or receive or raw value to send or receive |
[in] | balance_and_val_to_send_or_rec_types | Balance and value to send/receive types:
|
[in] | link | nano or xrb or raw hex string or raw hex binary link |
[in] | link_len | Link length. If zero it is assumed as nano, xrb or raw hex string link |
[in] | direction | Direction of the Nano block:
|
WARNING: block must be free after used.
ERROR_SUCCESS | when success or non zero otherwise |
int nano_create_p2pow_block_dynamic | ( | F_BLOCK_TRANSFER ** | , |
F_BLOCK_TRANSFER * | , | ||
const void * | , | ||
size_t | , | ||
const void * | , | ||
uint32_t | , | ||
const void * | , | ||
size_t | |||
) |
int pk_to_wallet | ( | char * | out, |
char * | prefix, | ||
NANO_PUBLIC_KEY_EXTENDED | pubkey_extended | ||
) |
Parse a Nano public key to Base32 Nano wallet string.
[out] | out | Output string containing the wallet |
[in] | prefix | Nano prefix. NANO_PREFIX for nano_ XRB_PREFIX for xrb_ |
[in,out] | pubkey_extended | Public key to be parsed to string |
WARNING: pubkey_extended is destroyed when parsing to Nano base32 encoding
0 | On Success, otherwise Error |
double to_multiplier | ( | uint64_t | difficulty, |
uint64_t | base_difficulty | ||
) |
Calculates a relative difficulty compared PoW with another.
[in] | dificulty | Work difficulty |
[in] | base_difficulty | Base difficulty Details here |
Calculated | value |
int valid_nano_wallet | ( | const char * | wallet | ) |
Check if a string containing a Base32 Nano wallet is valid.
[in] | wallet | Base32 Nano wallet encoded string |
0 | If valid wallet otherwise is invalid |
int valid_raw_balance | ( | const char * | balance | ) |
Checks if a string buffer pointed in balance is a valid raw balance.
[in] | balance | Pointer containing a string buffer |
0 | On Success, otherwise Error |
uint8_t account[32] |
Account in raw binary data.
Definition at line 262 of file f_nano_crypto_util.h.
f_uint128_t balance |
Big number 128 bit raw balance.
Definition at line 270 of file f_nano_crypto_util.h.
F_NANO_WALLET_INFO_BODY body |
Body of the file info.
Definition at line 270 of file f_nano_crypto_util.h.
char desc[F_NANO_DESC_SZ] |
Description.
Definition at line 264 of file f_nano_crypto_util.h.
uint8_t description[F_DESC_SZ] |
File description.
Definition at line 264 of file f_nano_crypto_util.h.
uint8_t file_info_integrity[32] |
File info integrity of the body block.
Definition at line 268 of file f_nano_crypto_util.h.
uint8_t hash_sk_unencrypted[32] |
hash of Nano SEED when unencrypted
Definition at line 266 of file f_nano_crypto_util.h.
uint8_t header[sizeof(F_NANO_WALLET_INFO_MAGIC)] |
Header magic.
Definition at line 260 of file f_nano_crypto_util.h.
uint8_t iv |
Initial sub vector.
Initial vector of first encryption layer.
Definition at line 262 of file f_nano_crypto_util.h.
uint32_t last_used_wallet_number |
Last used wallet number.
Definition at line 262 of file f_nano_crypto_util.h.
uint8_t link[32] |
link or destination account
Definition at line 272 of file f_nano_crypto_util.h.
char max_fee[F_RAW_STR_MAX_SZ] |
Custom preferred max fee of Proof of Work.
Definition at line 266 of file f_nano_crypto_util.h.
uint8_t nano_hdr[sizeof(NANO_WALLET_MAGIC)] |
Header of the file.
Definition at line 260 of file f_nano_crypto_util.h.
uint8_t nanoseed_hash[32] |
Nano SEED hash file.
Definition at line 266 of file f_nano_crypto_util.h.
uint8_t preamble[32] |
Block preamble.
Definition at line 260 of file f_nano_crypto_util.h.
uint8_t prefixes |
Internal use for this API.
Definition at line 276 of file f_nano_crypto_util.h.
uint8_t previous[32] |
Previous block.
Definition at line 264 of file f_nano_crypto_util.h.
uint8_t representative[32] |
Representative for current account.
Definition at line 266 of file f_nano_crypto_util.h.
uint8_t reserved |
uint8_t salt[32] |
Salt of the first encryption layer.
Definition at line 266 of file f_nano_crypto_util.h.
F_ENCRYPTED_BLOCK seed_block |
Second encrypted block for Nano SEED.
Definition at line 270 of file f_nano_crypto_util.h.
uint8_t signature[64] |
Signature of the block.
Definition at line 274 of file f_nano_crypto_util.h.
uint8_t sk_encrypted[32] |
uint8_t sub_salt[32] |
Salt of the sub block to be stored.
Definition at line 260 of file f_nano_crypto_util.h.
uint32_t ver |
Version of the file.
Definition at line 262 of file f_nano_crypto_util.h.
uint16_t version |
Version.
Definition at line 262 of file f_nano_crypto_util.h.
uint8_t wallet_prefix |
Wallet prefix: 0 for NANO; 1 for XRB.
Definition at line 260 of file f_nano_crypto_util.h.
char wallet_representative[MAX_STR_NANO_CHAR] |
Wallet representative.
Definition at line 264 of file f_nano_crypto_util.h.
uint64_t work |
Internal use for this API.
Definition at line 278 of file f_nano_crypto_util.h.