Nano cryptocurrency C library with P2PoW/DPoW support  1.0.0
f_nano_crypto_util.h File Reference
#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
 

Enumerations

enum  f_nano_err_t {
  NANO_ERR_OK =0, NANO_ERR_CANT_PARSE_BN_STR =5151, NANO_ERR_MALLOC, NANO_ERR_CANT_PARSE_FACTOR,
  NANO_ERR_MPI_MULT, NANO_ERR_CANT_PARSE_TO_BLK_TRANSFER, NANO_ERR_EMPTY_STR, NANO_ERR_CANT_PARSE_VALUE,
  NANO_ERR_PARSE_MPI_TO_STR, NANO_ERR_CANT_COMPLETE_NULL_CHAR, NANO_ERR_CANT_PARSE_TO_MPI, NANO_ERR_INSUFICIENT_FUNDS,
  NANO_ERR_SUB_MPI, NANO_ERR_ADD_MPI, NANO_ERR_NO_SENSE_VALUE_TO_SEND_NEGATIVE, NANO_ERR_NO_SENSE_VALUE_TO_SEND_ZERO,
  NANO_ERR_NO_SENSE_BALANCE_NEGATIVE, NANO_ERR_VAL_A_INVALID_MODE, NANO_ERR_CANT_PARSE_TO_TEMP_UINT128_T, NANO_ERR_VAL_B_INVALID_MODE,
  NANO_ERR_CANT_PARSE_RAW_A_TO_MPI, NANO_ERR_CANT_PARSE_RAW_B_TO_MPI, NANO_ERR_UNKNOWN_ADD_SUB_MODE, NANO_ERR_INVALID_RES_OUTPUT
}
 
enum  f_write_seed_err_t {
  WRITE_ERR_OK =0, WRITE_ERR_NULL_PASSWORD =7180, WRITE_ERR_EMPTY_STRING, WRITE_ERR_MALLOC,
  WRITE_ERR_ENCRYPT_PRIV_KEY, WRITE_ERR_GEN_SUB_PRIV_KEY, WRITE_ERR_GEN_MAIN_PRIV_KEY, WRITE_ERR_ENCRYPT_SUB_BLOCK,
  WRITE_ERR_UNKNOWN_OPTION, WRITE_ERR_FILE_ALREDY_EXISTS, WRITE_ERR_CREATING_FILE, WRITE_ERR_WRITING_FILE
}
 
enum  f_file_info_err_t {
  F_FILE_INFO_ERR_OK =0, F_FILE_INFO_ERR_CANT_OPEN_INFO_FILE =7001, F_FILE_INFO_ERR_NANO_SEED_ENCRYPTED_FILE_NOT_FOUND, F_FILE_INFO_ERR_CANT_DELETE_NANO_INFO_FILE,
  F_FILE_INFO_ERR_MALLOC, F_FILE_INFO_ERR_CANT_READ_NANO_SEED_ENCRYPTED_FILE, F_FILE_INFO_ERR_CANT_READ_INFO_FILE, F_FILE_INFO_INVALID_HEADER_FILE,
  F_FILE_INFO_ERR_INVALID_SHA256_INFO_FILE, F_FILE_INFO_ERR_NANO_SEED_HASH_FAIL, F_FILE_INFO_ERR_NANO_INVALID_REPRESENTATIVE, F_FILE_INFO_ERR_NANO_INVALID_MAX_FEE_VALUE,
  F_FILE_INFO_ERR_OPEN_FOR_WRITE_INFO, F_FILE_INFO_ERR_EXISTING_FILE, F_FILE_INFO_ERR_CANT_WRITE_FILE_INFO
}
 
enum  f_nano_create_block_dyn_err_t {
  NANO_CREATE_BLK_DYN_OK = 0, NANO_CREATE_BLK_DYN_BLOCK_NULL = 8000, NANO_CREATE_BLK_DYN_ACCOUNT_NULL, NANO_CREATE_BLK_DYN_COMPARE_BALANCE,
  NANO_CREATE_BLK_DYN_GENESIS_WITH_NON_EMPTY_BALANCE, NANO_CREATE_BLK_DYN_CANT_SEND_IN_GENESIS_BLOCK, NANO_CREATE_BLK_DYN_REP_NULL, NANO_CREATE_BLK_DYN_BALANCE_NULL,
  NANO_CREATE_BLK_DYN_SEND_RECEIVE_NULL, NANO_CREATE_BLK_DYN_LINK_NULL, NANO_CREATE_BLK_DYN_BUF_MALLOC, NANO_CREATE_BLK_DYN_MALLOC,
  NANO_CREATE_BLK_DYN_WRONG_PREVIOUS_SZ, NANO_CREATE_BLK_DYN_WRONG_PREVIOUS_STR_SZ, NANO_CREATE_BLK_DYN_PARSE_STR_HEX_ERR, NANO_CREATE_BLK_DYN_FORBIDDEN_AMOUNT_TYPE,
  NANO_CREATE_BLK_DYN_COMPARE, NANO_CREATE_BLK_DYN_EMPTY_VAL_TO_SEND_OR_REC, NANO_CREATE_BLK_DYN_INVALID_DIRECTION_OPTION
}
 
enum  f_nano_p2pow_block_dyn_err_t {
  NANO_P2POW_CREATE_BLOCK_OK = 0, NANO_P2POW_CREATE_BLOCK_INVALID_USER_BLOCK = 8400, NANO_P2POW_CREATE_BLOCK_MALLOC, NANO_P2POW_CREATE_BLOCK_NULL,
  NANO_P2POW_CREATE_OUTPUT, NANO_P2POW_CREATE_OUTPUT_MALLOC
}
 

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
 

Detailed Description

This API Integrates Nano Cryptocurrency to low computational devices.

Definition in file f_nano_crypto_util.h.

Macro Definition Documentation

◆ DEST_XRB

#define DEST_XRB   (uint8_t)0x01

Definition at line 440 of file f_nano_crypto_util.h.

◆ F_BALANCE_RAW_128

#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.

◆ F_BALANCE_RAW_STRING

#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.

◆ F_BALANCE_REAL_STRING

#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.

◆ F_BLOCK_TRANSFER_SIZE

#define F_BLOCK_TRANSFER_SIZE   (size_t)sizeof(F_BLOCK_TRANSFER)

Definition at line 291 of file f_nano_crypto_util.h.

◆ F_BRAIN_WALLET_BAD

#define F_BRAIN_WALLET_BAD   (uint32_t)3

[bad].

Crack within one day

Definition at line 1209 of file f_nano_crypto_util.h.

◆ F_BRAIN_WALLET_GOOD

#define F_BRAIN_WALLET_GOOD   (uint32_t)8

[good].

Crack within one thousand year

Definition at line 1240 of file f_nano_crypto_util.h.

◆ F_BRAIN_WALLET_MAYBE_GOOD

#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.

◆ F_BRAIN_WALLET_NICE

#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.

◆ F_BRAIN_WALLET_PERFECT

#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.

◆ F_BRAIN_WALLET_POOR

#define F_BRAIN_WALLET_POOR   (uint32_t)1

[poor].

Crack within minutes

Definition at line 1197 of file f_nano_crypto_util.h.

◆ F_BRAIN_WALLET_STILL_WEAK

#define F_BRAIN_WALLET_STILL_WEAK   (uint32_t)6

[still weak].

Crack within one year

Definition at line 1227 of file f_nano_crypto_util.h.

◆ F_BRAIN_WALLET_VERY_BAD

#define F_BRAIN_WALLET_VERY_BAD   (uint32_t)2

[very bad].

Crack within one hour

Definition at line 1203 of file f_nano_crypto_util.h.

◆ F_BRAIN_WALLET_VERY_GOOD

#define F_BRAIN_WALLET_VERY_GOOD   (uint32_t)9

[very good].

Crack within ten thousand year

Definition at line 1246 of file f_nano_crypto_util.h.

◆ F_BRAIN_WALLET_VERY_POOR

#define F_BRAIN_WALLET_VERY_POOR   (uint32_t)0

[very poor].

Crack within seconds or less

Definition at line 1191 of file f_nano_crypto_util.h.

◆ F_BRAIN_WALLET_VERY_WEAK

#define F_BRAIN_WALLET_VERY_WEAK   (uint32_t)4

[very weak].

Crack within one week

Definition at line 1215 of file f_nano_crypto_util.h.

◆ F_BRAIN_WALLET_WEAK

#define F_BRAIN_WALLET_WEAK   (uint32_t)5

[weak].

Crack within one month

Definition at line 1221 of file f_nano_crypto_util.h.

◆ F_DEFAULT_THRESHOLD

#define F_DEFAULT_THRESHOLD   (uint64_t) 0xffffffc000000000

Default Nano Proof of Work Threshold.

Definition at line 1361 of file f_nano_crypto_util.h.

◆ F_FEE_VALUE_RAW_128

#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.

◆ F_FEE_VALUE_RAW_STRING

#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.

◆ F_FEE_VALUE_REAL_STRING

#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.

◆ F_IS_SIGNATURE_RAW_HEX_STRING

#define F_IS_SIGNATURE_RAW_HEX_STRING   (uint32_t)64

Signature is raw hex string flag.

See also
f_sign_data()

Definition at line 1348 of file f_nano_crypto_util.h.

◆ F_MESSAGE_IS_HASH_STRING

#define F_MESSAGE_IS_HASH_STRING   (uint32_t)128

Message is raw hex hash string.

See also
f_sign_data()

Definition at line 1355 of file f_nano_crypto_util.h.

◆ F_NANO_POW_MAX_THREAD

#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.

◆ F_P2POW_BLOCK_TRANSFER_SIZE

#define F_P2POW_BLOCK_TRANSFER_SIZE   2*F_BLOCK_TRANSFER_SIZE

Definition at line 292 of file f_nano_crypto_util.h.

◆ F_PUBLIC_KEY_ASCII_HEX

#define F_PUBLIC_KEY_ASCII_HEX   (uint32_t)4

Public key is a hex ASCII encoded string.

See also
f_verify_signed_data()

Definition at line 1413 of file f_nano_crypto_util.h.

◆ F_PUBLIC_KEY_RAW_HEX

#define F_PUBLIC_KEY_RAW_HEX   (uint32_t)2

Public key raw 32 bytes data.

See also
f_verify_signed_data()

Definition at line 1406 of file f_nano_crypto_util.h.

◆ F_SIGNATURE_OUTPUT_NANO_PK

#define F_SIGNATURE_OUTPUT_NANO_PK   (uint32_t)32

Public key is a NANO wallet encoded base32 string.

See also
f_sign_data()

Definition at line 1341 of file f_nano_crypto_util.h.

◆ F_SIGNATURE_OUTPUT_RAW_PK

#define F_SIGNATURE_OUTPUT_RAW_PK   (uint32_t)4

Public key is raw data.

See also
f_sign_data()

Definition at line 1320 of file f_nano_crypto_util.h.

◆ F_SIGNATURE_OUTPUT_STRING_PK

#define F_SIGNATURE_OUTPUT_STRING_PK   (uint32_t)8

Public key is hex ASCII encoded string.

See also
f_sign_data()

Definition at line 1327 of file f_nano_crypto_util.h.

◆ F_SIGNATURE_OUTPUT_XRB_PK

#define F_SIGNATURE_OUTPUT_XRB_PK   (uint32_t)16

Public key is a XRB wallet encoded base32 string.

See also
f_sign_data()

Definition at line 1334 of file f_nano_crypto_util.h.

◆ F_SIGNATURE_RAW

#define F_SIGNATURE_RAW   (uint32_t)1

Signature is raw data.

See also
f_sign_data()

Definition at line 1306 of file f_nano_crypto_util.h.

◆ F_SIGNATURE_STRING

#define F_SIGNATURE_STRING   (uint32_t)2

Signature is hex ASCII encoded string.

See also
f_sign_data()

Definition at line 1313 of file f_nano_crypto_util.h.

◆ F_VALUE_SEND_RECEIVE_RAW_128

#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.

◆ F_VALUE_SEND_RECEIVE_RAW_STRING

#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.

◆ F_VALUE_SEND_RECEIVE_REAL_STRING

#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.

◆ F_VALUE_TO_RECEIVE

#define F_VALUE_TO_RECEIVE   (int)(1<<1)

Value to receive.

Definition at line 1494 of file f_nano_crypto_util.h.

◆ F_VALUE_TO_SEND

#define F_VALUE_TO_SEND   (int)(1<<0)

Value to send.

Definition at line 1488 of file f_nano_crypto_util.h.

◆ F_VERIFY_SIG_NANO_WALLET

#define F_VERIFY_SIG_NANO_WALLET   (uint32_t)1

Public key is a NANO wallet with XRB or NANO prefixes encoded base32 string.

See also
f_verify_signed_data()

Definition at line 1399 of file f_nano_crypto_util.h.

◆ MAX_STR_NANO_CHAR

#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.

◆ NANO_ENCRYPTED_SEED_FILE

#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.

◆ NANO_FILE_WALLETS_INFO

#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.

◆ NANO_PASSWD_MAX_LEN

#define NANO_PASSWD_MAX_LEN   (size_t)80

Password max length.

Definition at line 200 of file f_nano_crypto_util.h.

◆ NANO_PREFIX

#define NANO_PREFIX   "nano_"

Nano prefix.

Definition at line 164 of file f_nano_crypto_util.h.

◆ PUB_KEY_EXTENDED_MAX_LEN

#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.

◆ REP_XRB

#define REP_XRB   (uint8_t)0x4

Representative XRB flag.

Destination XRB flag.

Sender XRB flag.

◆ SENDER_XRB

#define SENDER_XRB   (uint8_t)0x02

Definition at line 434 of file f_nano_crypto_util.h.

◆ STR_NANO_SZ

#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.

◆ XRB_PREFIX

#define XRB_PREFIX   "xrb_"

XRB (old Raiblocks) prefix.

Definition at line 170 of file f_nano_crypto_util.h.

Typedef Documentation

◆ F_FILE_INFO_ERR

Typedef Error enumerator for info file functions.

◆ F_NANO_CREATE_BLOCK_DYN_ERR

◆ f_nano_err

Error function enumerator.

See also
f_nano_err_t

◆ F_NANO_P2POW_BLOCK_DYN_ERR

◆ F_TOKEN

typedef uint8_t F_TOKEN[16]

Definition at line 218 of file f_nano_crypto_util.h.

◆ f_uint128_t

f_uint128_t

128 bit big number of Nano balance

Definition at line 230 of file f_nano_crypto_util.h.

◆ f_write_seed_err

◆ NANO_PRIVATE_KEY

NANO_PRIVATE_KEY

Size of Nano Private Key.

Definition at line 240 of file f_nano_crypto_util.h.

◆ NANO_PRIVATE_KEY_EXTENDED

NANO_PRIVATE_KEY_EXTENDED

Size of Nano Private Key extended.

Definition at line 246 of file f_nano_crypto_util.h.

◆ NANO_PUBLIC_KEY

NANO_PUBLIC_KEY

Size of Nano Public Key.

Definition at line 252 of file f_nano_crypto_util.h.

◆ NANO_PUBLIC_KEY_EXTENDED

NANO_PUBLIC_KEY_EXTENDED

Size of Public Key Extended.

Definition at line 258 of file f_nano_crypto_util.h.

◆ NANO_SEED

NANO_SEED

Size of Nano SEED.

Definition at line 224 of file f_nano_crypto_util.h.

Enumeration Type Documentation

◆ f_file_info_err_t

Enumerator
F_FILE_INFO_ERR_OK 

SUCCESS.

F_FILE_INFO_ERR_CANT_OPEN_INFO_FILE 

Can't open info file.

F_FILE_INFO_ERR_NANO_SEED_ENCRYPTED_FILE_NOT_FOUND 

Encrypted file with Nano SEED not found.

F_FILE_INFO_ERR_CANT_DELETE_NANO_INFO_FILE 

Can not delete Nano info file.

F_FILE_INFO_ERR_MALLOC 

Fatal Error MALLOC.

F_FILE_INFO_ERR_CANT_READ_NANO_SEED_ENCRYPTED_FILE 

Can not read encrypted Nano SEED in file.

F_FILE_INFO_ERR_CANT_READ_INFO_FILE 

Can not read info file.

F_FILE_INFO_INVALID_HEADER_FILE 

Invalid info file header.

F_FILE_INFO_ERR_INVALID_SHA256_INFO_FILE 

Invalid SHA256 info file.

F_FILE_INFO_ERR_NANO_SEED_HASH_FAIL 

Nano SEED hash failed.

F_FILE_INFO_ERR_NANO_INVALID_REPRESENTATIVE 

Invalid representative.

F_FILE_INFO_ERR_NANO_INVALID_MAX_FEE_VALUE 

Invalid max fee value.

F_FILE_INFO_ERR_OPEN_FOR_WRITE_INFO 

Can not open info file for write.

F_FILE_INFO_ERR_EXISTING_FILE 

Error File Exists.

F_FILE_INFO_ERR_CANT_WRITE_FILE_INFO 

Can not write info file.

Definition at line 546 of file f_nano_crypto_util.h.

◆ f_nano_create_block_dyn_err_t

Enumerator
NANO_CREATE_BLK_DYN_OK 
NANO_CREATE_BLK_DYN_BLOCK_NULL 
NANO_CREATE_BLK_DYN_ACCOUNT_NULL 
NANO_CREATE_BLK_DYN_COMPARE_BALANCE 
NANO_CREATE_BLK_DYN_GENESIS_WITH_NON_EMPTY_BALANCE 
NANO_CREATE_BLK_DYN_CANT_SEND_IN_GENESIS_BLOCK 
NANO_CREATE_BLK_DYN_REP_NULL 
NANO_CREATE_BLK_DYN_BALANCE_NULL 
NANO_CREATE_BLK_DYN_SEND_RECEIVE_NULL 
NANO_CREATE_BLK_DYN_LINK_NULL 
NANO_CREATE_BLK_DYN_BUF_MALLOC 
NANO_CREATE_BLK_DYN_MALLOC 
NANO_CREATE_BLK_DYN_WRONG_PREVIOUS_SZ 
NANO_CREATE_BLK_DYN_WRONG_PREVIOUS_STR_SZ 
NANO_CREATE_BLK_DYN_PARSE_STR_HEX_ERR 
NANO_CREATE_BLK_DYN_FORBIDDEN_AMOUNT_TYPE 
NANO_CREATE_BLK_DYN_COMPARE 
NANO_CREATE_BLK_DYN_EMPTY_VAL_TO_SEND_OR_REC 
NANO_CREATE_BLK_DYN_INVALID_DIRECTION_OPTION 

Definition at line 606 of file f_nano_crypto_util.h.

◆ f_nano_err_t

Enumerator
NANO_ERR_OK 

SUCCESS.

NANO_ERR_CANT_PARSE_BN_STR 

Can not parse string big number.

NANO_ERR_MALLOC 

Fatal ERROR MALLOC.

NANO_ERR_CANT_PARSE_FACTOR 

Can not parse big number factor.

NANO_ERR_MPI_MULT 

Error multiplication MPI.

NANO_ERR_CANT_PARSE_TO_BLK_TRANSFER 

Can not parse to block transfer.

NANO_ERR_EMPTY_STR 

Error empty string.

NANO_ERR_CANT_PARSE_VALUE 

Can not parse value.

NANO_ERR_PARSE_MPI_TO_STR 

Can not parse MPI to string.

NANO_ERR_CANT_COMPLETE_NULL_CHAR 

Can not complete NULL char.

NANO_ERR_CANT_PARSE_TO_MPI 

Can not parse to MPI.

NANO_ERR_INSUFICIENT_FUNDS 

Insuficient funds.

NANO_ERR_SUB_MPI 

Error subtract MPI.

NANO_ERR_ADD_MPI 

Error add MPI.

NANO_ERR_NO_SENSE_VALUE_TO_SEND_NEGATIVE 

Does not make sense send negativative balance.

NANO_ERR_NO_SENSE_VALUE_TO_SEND_ZERO 

Does not make sense send empty value.

NANO_ERR_NO_SENSE_BALANCE_NEGATIVE 

Does not make sense negative balance.

NANO_ERR_VAL_A_INVALID_MODE 

Invalid A mode value.

NANO_ERR_CANT_PARSE_TO_TEMP_UINT128_T 

Can not parse temporary memory to uint_128_t.

NANO_ERR_VAL_B_INVALID_MODE 

Invalid A mode value.

NANO_ERR_CANT_PARSE_RAW_A_TO_MPI 

Can not parse raw A value to MPI.

NANO_ERR_CANT_PARSE_RAW_B_TO_MPI 

Can not parse raw B value to MPI.

NANO_ERR_UNKNOWN_ADD_SUB_MODE 

Unknown ADD/SUB mode.

NANO_ERR_INVALID_RES_OUTPUT 

Invalid output result.

Definition at line 305 of file f_nano_crypto_util.h.

◆ f_nano_p2pow_block_dyn_err_t

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.

◆ f_write_seed_err_t

Enumerator
WRITE_ERR_OK 

Error SUCCESS.

WRITE_ERR_NULL_PASSWORD 

Error NULL password.

WRITE_ERR_EMPTY_STRING 

Empty string.

WRITE_ERR_MALLOC 

Error MALLOC.

WRITE_ERR_ENCRYPT_PRIV_KEY 

Error encrypt private key.

WRITE_ERR_GEN_SUB_PRIV_KEY 

Can not generate sub private key.

WRITE_ERR_GEN_MAIN_PRIV_KEY 

Can not generate main private key.

WRITE_ERR_ENCRYPT_SUB_BLOCK 

Can not encrypt sub block.

WRITE_ERR_UNKNOWN_OPTION 

Unknown option.

WRITE_ERR_FILE_ALREDY_EXISTS 

File already exists.

WRITE_ERR_CREATING_FILE 

Can not create file.

WRITE_ERR_WRITING_FILE 

Can not write file.

Definition at line 442 of file f_nano_crypto_util.h.

Function Documentation

◆ __attribute__()

struct f_block_transfer_t __attribute__ ( (packed)  )

◆ f_bip39_to_nano_seed()

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.

Parameters
[out]seedNano SEED
[in]strA encoded Bip39 string pointer
[in]dictionaryA string pointer path to file

WARNING Sensive data. Do not share any SEED or Bip39 encoded string !

Return values
0On Success, otherwise Error
See also
f_nano_seed_to_bip39()

◆ f_cloud_crypto_wallet_nano_create_seed()

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

Parameters
[in]entropyEntropy 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_nameThe 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]passwordPassword 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

Return values
0On Success, otherwise Error

◆ f_extract_seed_from_brainwallet()

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.

Parameters
[out]seedOutput Nano SEED extracted from brainwallet
[out]warning_msgWarning message parsed to application. It can be NULL
[in]allow_modeAllow mode. Funtion will return SUCCESS only if permitted mode set by user

Allow mode are:
  • F_BRAIN_WALLET_VERY_POOR Crack within seconds or less
  • F_BRAIN_WALLET_POOR Crack within minutes
  • F_BRAIN_WALLET_VERY_BAD Crack within one hour
  • F_BRAIN_WALLET_BAD Crack within one day
  • F_BRAIN_WALLET_VERY_WEAK Crack within one week
  • F_BRAIN_WALLET_WEAK Crack within one month
  • F_BRAIN_WALLET_STILL_WEAK Crack within one year
  • F_BRAIN_WALLET_MAYBE_GOOD Crack within one century
  • F_BRAIN_WALLET_GOOD Crack within one thousand year
  • F_BRAIN_WALLET_VERY_GOOD Crack within ten thousand year
  • F_BRAIN_WALLET_NICE Crack withing one hundred thousand year
  • F_BRAIN_WALLET_PERFECT 3.34x10^53 Years to crack
[in]brainwalletBrainwallet text to be parsed. It can be NOT NULL or null string
[in]saltSalt of the Braiwallet. It can be NOT NULL or null string
Return values
0If success, otherwise error.
See also
f_bip39_to_nano_seed()

◆ f_generate_nano_seed()

int f_generate_nano_seed ( NANO_SEED  seed,
uint32_t  entropy 
)

Generates a new SEED and stores it to seed pointer.

Parameters
[out]seedSEED generated in system PRNG or TRNG
[in]entropyEntropy 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
Return values
0On Success, otherwise Error

◆ f_generate_token()

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.

Parameters
[out]signature128 bit non deterministic token
[in]dataData to be signed in token
[in]data_szSize of data
[in]passwordPassword
Return values
0On Success, otherwise Error
See also
f_verify_token()

◆ f_get_dictionary_path()

char * f_get_dictionary_path ( void  )

Get default dictionary path in myNanoEmbedded library.

Return values
Pathand name of the dictionary file
See also
f_set_dictionary_path()

◆ f_get_nano_file_info()

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.

Parameters
[out]infoPointer to buffer to be parsed struct from $PATH/walletsinfo.i file.
Return values
F_FILE_INFO_ERR_OKIf Success, otherwise F_FILE_INFO_ERR enum type error
See also
F_FILE_INFO_ERR enum type error for detailed error and f_nano_wallet_info_t for info type details

◆ f_is_valid_nano_seed_encrypted()

int f_is_valid_nano_seed_encrypted ( void *  stream,
size_t  stream_len,
int  read_from 
)

Verifies if ecrypted Nano SEED is valid.

Parameters
[in]streamEncrypted binary data block coming from memory or file
[in]stream_lensize of stream data
[in]read_fromSource READ_SEED_FROM_STREAM if encrypted binary data is in memory or READ_SEED_FROM_FILE is in a file.
Return values
0If invalid, greater than zero if is valid or error if less than zero.

◆ f_nano_add_sub()

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

Parameters
[out]resResult value res = valA + valB or res = valA - valB
[in]valAInput balance A value
[in]valBInput balance B value
[in]modeMode type:
  • F_NANO_ADD_A_B valA + valB
  • F_NANO_SUB_A_B valA - valB
  • F_NANO_RES_RAW_128 Output is a raw data 128 bit big number result
  • F_NANO_RES_RAW_STRING Output is a 128 bit Big Integer string
  • F_NANO_RES_REAL_STRING Output is a Real string value
  • F_NANO_A_RAW_128 if balance is big number raw buffer type
  • F_NANO_A_RAW_STRING if balance is big number raw string type
  • F_NANO_A_REAL_STRING if balance is real number string type
  • F_NANO_B_RAW_128 if value_to_send is big number raw buffer type
  • F_NANO_B_RAW_STRING if value_to_send is big number raw string type
  • F_NANO_B_REAL_STRING if value_to_send is real number string type
Return values
NANO_ERR_OKIf Success, otherwise f_nano_err_t enum type error
See also
f_nano_err_t for f_nano_err enum error type

◆ f_nano_balance_to_str()

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.

Parameters
[out]strOutput string pointer
[in]str_lenSize of string pointer memory
[out]out_lenOutput length of converted value to string. If out_len is NULL then str returns converted value with NULL terminated string
[in]valueRaw Nano balance value
Return values
0If success, otherwise error.
See also
function f_nano_parse_raw_str_to_raw128_t() and return errors f_nano_err

◆ f_nano_block_to_json()

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.

Parameters
[out]destDestination of the converted JSON block
[out]olenOutput length of the converted JSON block. olen can be NULL. If NULL, destination size contains a NULL char
[in]dest_sizeSize of dest memory buffer
[in]user_blockUser Nano block
Returns
0 if success, non zero if error

◆ f_nano_get_block_hash()

int f_nano_get_block_hash ( uint8_t *  hash,
F_BLOCK_TRANSFER *  block 
)

Gets a hash from Nano block.

Parameters
[out]hashOutput hash
[in]blockNano Block
Returns
0 if success, non zero if error

◆ f_nano_get_p2pow_block_hash()

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.

Parameters
[out]user_hashHash of the user block
[out]fee_hashHash of the P2PoW block
[in]blockInput Nano Block
Returns
0 if success, non zero if error

◆ f_nano_is_valid_block()

int f_nano_is_valid_block ( F_BLOCK_TRANSFER *  block)

Checks if Binary Nano Block is valid.

Parameters
[in]blockNano Block
Returns
0 if is invalid block or 1 if is valid block

◆ f_nano_key_to_str()

char * f_nano_key_to_str ( char *  out,
unsigned char *  key 
)

Parse a raw binary public key to string.

Parameters
[out]outPointer to outuput string
[in]inPointer to raw public key
Returns
A pointer to output string

◆ f_nano_p2pow_to_JSON()

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.

Parameters
[out]bufferOutput JSON string
[out]olenOutput JSON string size. olen can be NULL. If NULL, buffer will be terminated with a NULL char
[in]buffer_szSize of memory buffer
[in]blockP2PoW block
Returns
0 if success, non zero if error

◆ f_nano_parse_raw_str_to_raw128_t()

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.

Parameters
[out]resBinary raw balance
[in]raw_str_valueRaw balance string
Return values
NANO_ERR_OKIf Success, otherwise f_nano_err_t enum type error
See also
f_nano_err_t for f_nano_err enum error type

◆ f_nano_parse_real_str_to_raw128_t()

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.

Parameters
[out]resBinary raw balance
[in]real_str_valueReal balance string
Return values
NANO_ERR_OKIf Success, otherwise f_nano_err_t enum type error
See also
f_nano_err_t for f_nano_err enum error type

◆ f_nano_pow()

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

Parameters
[out]PoW_resOutput Proof of Work
[in]hashInput hash
[in]thresholdInput threshold
[in]n_thrNumber 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()

Return values
0If success, otherwise error.
See also
f_verify_work()

◆ f_nano_raw_to_string()

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.

Parameters
[out]strOutput real string value
[out]olenSize of output real string value. It can be NULL. If NULL output str will have a NULL char at the end.
[in]str_szSize of str buffer
[in]rawRaw balance.
[in]raw_typeRaw balance type:
  • F_RAW_TO_STR_UINT128 for raw f_uint128_t balance
  • F_RAW_TO_STR_STRING for raw char balance
Return values
0On Success, otherwise Error
See also
f_nano_valid_nano_str_value()

◆ f_nano_seed_to_bip39()

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.

Parameters
[out]bufOutput string containing encoded Bip39 SEED
[in]buf_szSize of memory of buf pointer
[out]out_buf_lenIf 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]seedNano SEED
[in]dictionary_filePath to dictionary file

WARNING Sensive data. Do not share any SEED or Bip39 encoded string !

Return values
0On Success, otherwise Error
See also
f_bip39_to_nano_seed()

◆ f_nano_sign_block()

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

Parameters
[in,out]user_blockUser block to be signed with a private key private_key
[in,out]fee_blockFee block to be signed with a private key private_key. Can be NULL if worker does not require fee
[in]private_keyPrivate key to sign block(s)
Return values
0If Success, otherwise error
See also
f_nano_transaction_to_JSON()

◆ f_nano_transaction_to_JSON()

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.

Parameters
[out]strA string pointer to store JSON Nano RPC
[in]str_lenSize of buffer in str pointer
[out]str_outSize of JSON string. str_out can be NULL
[in]private_keyPrivate key to sign the block block_transfer
[in,out]block_transferNano block containing raw data to be stored in Nano Blockchain

WARNING Sensive data. Do not share any PRIVATE KEY

Return values
0On Success, otherwise Error

◆ f_nano_valid_nano_str_value()

int f_nano_valid_nano_str_value ( const char *  str)

Check if a real string or raw string are valid Nano balance.

Parameters
[in]strValue to be checked
Return values
0If valid, otherwise is invalid
See also
f_nano_raw_to_string()

◆ f_nano_value_compare_value()

f_nano_err f_nano_value_compare_value ( void *  valA,
void *  valB,
uint32_t *  mode_compare 
)

Comparare two Nano balance.

Parameters
[in]valANano balance value A
[in]valBNano balance value B
[in,out]mode_compareInput mode and output result

Input mode:
  • F_NANO_A_RAW_128 if valA is big number raw buffer type
  • F_NANO_A_RAW_STRING if valA is big number raw string type
  • F_NANO_A_REAL_STRING if valA is real number string type
  • F_NANO_B_RAW_128 if valB is big number raw buffer type
  • F_NANO_B_RAW_STRING if valB is big number raw string type
  • F_NANO_B_REAL_STRING if valB is real number string type

    Output type:
  • F_NANO_COMPARE_EQ If valA is equal valB
  • F_NANO_COMPARE_LT if valA is lesser than valB
  • F_NANO_COMPARE_GT if valA is greater than valB
Return values
NANO_ERR_OKIf Success, otherwise f_nano_err_t enum type error
See also
f_nano_err_t for f_nano_err enum error type

◆ f_nano_verify_nano_funds()

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.

Parameters
[in]balanceNano balance
[in]value_to_sendValue to send
[in]feeFee value (it can be NULL)
[in]modeValue type mode
  • F_NANO_A_RAW_128 if balance is big number raw buffer type
  • F_NANO_A_RAW_STRING if balance is big number raw string type
  • F_NANO_A_REAL_STRING if balance is real number string type
  • F_NANO_B_RAW_128 if value_to_send is big number raw buffer type
  • F_NANO_B_RAW_STRING if value_to_send is big number raw string type
  • F_NANO_B_REAL_STRING if value_to_send is real number string type
  • F_NANO_C_RAW_128 if fee is big number raw buffer type (can be ommited if fee is NULL)
  • F_NANO_C_RAW_STRING if fee is big number raw string type (can be ommited if fee is NULL)
  • F_NANO_C_REAL_STRING if fee is real number string type (can be ommited if fee is NULL)
Return values
NANO_ERR_OKIf Success, otherwise f_nano_err_t enum type error
See also
f_nano_err_t for f_nano_err enum error type

◆ f_parse_nano_seed_and_bip39_to_JSON()

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.

Parameters
[out]destDestination JSON string pointer
[in]dest_szBuffer size of dest pointer
[out]olenSize 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_dataInput data source (encrypted file | encrypted data in memory | unencrypted seed in memory)
[in]sourceSource data type:
  • PARSE_JSON_READ_SEED_GENERIC: If seed are in memory pointed in source_data. Password is ignored. Can be NULL.
  • READ_SEED_FROM_STREAM: Read encrypted data from stream pointed in source_data. Password is required.
  • READ_SEED_FROM_FILE: Read encrypted data stored in a file where source_data is path to file. Password is required.
[in]passwordRequired for READ_SEED_FROM_STREAM and READ_SEED_FROM_FILE sources

WARNING Sensive data. Do not share any SEED or Bip39 encoded string !

Return values
0On Success, otherwise Error
See also
f_read_seed()

◆ f_read_seed()

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.

Parameters
[out]seedOutput Nano SEED
[in]passwdPassword (always required)
[in]source_dataEncrypted source data from memory or path pointed in source_data
[in]force_readIf non zero value then forces reading from a corrupted file. This param is ignored when reading source_data from memory
[in]sourceSource data type:
  • READ_SEED_FROM_STREAM: Read encrypted data from stream pointed in source_data. Password is required.
  • READ_SEED_FROM_FILE: Read encrypted data stored in a file where source_data is path to file. Password is required.

WARNING Sensive data. Do not share any SEED !

Return values
0On Success, otherwise Error
See also
f_parse_nano_seed_and_bip39_to_JSON() f_write_seed()

◆ f_seed_to_nano_wallet()

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.

Parameters
[out]private_keyPrivate key of the wallet_number from given seed
[out]public_keyPublic key of the wallet_number from given seed
[in,out]seedNano SEED
[in]wallet_numberWallet number of key pair to be extracted from Nano SEED

WARNING 1:

  • Seed must be read from memory
  • Seed is destroyed when extracting public and private keys

WARNING 2:

  • Never expose SEED and private key. This function destroys seed and any data after execution and finally parse public and private keys to output.
Return values
0On Success, otherwise Error

◆ f_set_dictionary_path()

void f_set_dictionary_path ( const char *  path)

Set default dictionary file and path to myNanoEmbedded library.

Parameters
[in]pathPath to dictionary file

If f_set_dictionary_path() is not used in myNanoEmbedded library then default path stored in BIP39_DICTIONARY is used

See also
f_get_dictionary_path()

◆ f_set_nano_file_info()

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

Parameters
[in]infoPointer to data to be saved at $PATH/walletsinfo.i file.
[in]overwrite_existing_fileIf non zero then overwrites file $PATH/walletsinfo.i
Return values
F_FILE_INFO_ERR_OKIf Success, otherwise F_FILE_INFO_ERR enum type error
See also
F_FILE_INFO_ERR enum type error for detailed error and f_nano_wallet_info_t for info type details

◆ f_sign_data()

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

Parameters
[out]signatureOutput signature
[out]out_public_keyOutput public key. It can be NULL
[in]output_typeOutput type of public key. Public key types are:

  • F_SIGNATURE_RAW Signature is raw 64 bytes long
  • F_SIGNATURE_STRING Singnature is hex ASCII encoded string
  • F_SIGNATURE_OUTPUT_RAW_PK Public key is raw 32 bytes data
  • F_SIGNATURE_OUTPUT_STRING_PK Public key is hes ASCII encoded string
  • F_SIGNATURE_OUTPUT_XRB_PK Public key is a XRB wallet encoded base32 string
  • F_SIGNATURE_OUTPUT_NANO_PK Public key is a NANO wallet encoded base32 string
[in]messageMessage to be signed with Elliptic Curve Ed25519 with blake2b hash
[in]msg_lenSize of message to be signed
[in]private_keyPrivate key to sign message
Return values
0If success, otherwise error.
See also
f_verify_signed_data()

◆ f_verify_signed_block()

int f_verify_signed_block ( F_BLOCK_TRANSFER *  )

◆ f_verify_signed_data()

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.

Parameters
[in]signatureSignature of the message
[in]messageMessage to be verified
[in]message_lenLength of the message
[in]public_keyPublic key to verify signed message
[in]pk_typeType of the public key. Types are:

  • F_VERIFY_SIG_NANO_WALLET Public key is a NANO wallet with XRB or NANO prefixes encoded base32 string
  • F_VERIFY_SIG_RAW_HEX Public key is raw 32 bytes data
  • F_PUBLIC_KEY_ASCII_HEX Public key is a hex ASCII encoded string

Return value are

  • Greater than zero if signature is VALID
  • 0 (zero) if signature is INVALID
  • Negative if ERROR occurred
See also
f_sign_data()

◆ f_verify_token()

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.

Parameters
[in]signature128 bit non deterministic token
[in]dataData to be signed in token
[in]data_szSize of data
[in]passwordPassword
Return values
0On if invalid; 1 if valid ; less than zero if an error occurs
See also
f_generate_token()

◆ f_verify_work()

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.

Parameters
[out]resultResult of work. It can be NULL
[in]hashInput hash for verification
[in]workWork previously calculated to be checked
[in]thresholdInput threshold
Return values
0If is not valid or less than zero if error or greater than zero if is valid
See also
f_nano_pow()

◆ f_write_seed()

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.

Parameters
[out]source_dataMemory pointer or file name
[in]sourceSource of output data:
  • WRITE_SEED_TO_STREAM Output data is a pointer to memory to store encrypted Nano SEED data
  • WRITE_SEED_TO_FILE Output is a string filename to store encrypted Nano SEED data
[in]seedNano 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
Return values
0If Success, otherwise error
See also
f_read_seed()

◆ from_multiplier()

uint64_t from_multiplier ( double  multiplier,
uint64_t  base_difficulty 
)

Calculates a PoW given a multiplier and base difficulty.

Parameters
[in]multiplierMultiplier of the work
[in]base_difficultyBase difficulty Details here
See also
to_multiplier()
Return values
Calculatedvalue

◆ is_nano_prefix()

int is_nano_prefix ( const char *  nano_wallet,
const char *  prefix 
)

Checks prefix in nano_wallet

Parameters
[in]nano_walletBase32 Nano wallet encoded string
[in]prefixPrefix type
  • NANO_PREFIX for nano_
  • XRB_PREFIX for xrb_
Return values
1If prefix in nano_wallet, otherwise 0

◆ is_null_hash()

int is_null_hash ( uint8_t *  hash)

Check if 32 bytes hash is filled with zeroes.

Parameters
[in]hash32 bytes binary hash
Return values
1If zero filled buffer, otherwise 0

◆ nano_base_32_2_hex()

int nano_base_32_2_hex ( uint8_t *  res,
char *  str_wallet 
)

Parse Nano Base32 wallet string to public key binary.

Parameters
[out]resOutput raw binary public key
[in]str_walletValid Base32 encoded Nano string to be parsed
Return values
0On Success, otherwise Error
See also
pk_to_wallet()

◆ nano_create_block_dynamic()

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.

Parameters
[out]blockPointer to new allocated Nano block
[in]accountnano or xrb or raw hex string or raw hex binary account (public key)
[in]account_lenAccount length. If zero it is assumed as nano, xrb or raw hex string public key
[in]previousHex string or raw hex binary previous block
[in]previous_lenPrevious length size. If zero it is assumed previous is a NULL terminated string
[in]representativenano or xrb or raw hex string or raw hex binary representative account
[in]representative_lenRepresentative length. If zero it is assumed as nano, xrb or raw hex string representative
[in]balanceReal balance or raw string balance or raw binary balance
[in]value_to_send_or_receiveReal 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_typesBalance and value to send/receive types:

  • F_BALANCE_RAW_128 Balance is raw binary 128 bit
  • F_BALANCE_REAL_STRING Balance is real string
  • F_BALANCE_RAW_STRING Balance is raw string
  • F_VALUE_SEND_RECEIVE_RAW_128 Value to send/receive is raw binary 128 bit
  • F_VALUE_SEND_RECEIVE_REAL_STRING Value to send/receive is real string
  • F_VALUE_SEND_RECEIVE_RAW_STRING Value to send/receive is raw string
[in]linknano or xrb or raw hex string or raw hex binary link
[in]link_lenLink length. If zero it is assumed as nano, xrb or raw hex string link
[in]directionDirection of the Nano block:

  • F_VALUE_TO_SEND Value to send to link = destination account
  • F_VALUE_TO_RECEIVE Value to receive from link = receive amount

WARNING: block must be free after used.

Return values
ERROR_SUCCESSwhen success or non zero otherwise
See also
nano_create_p2pow_block_dynamic()

◆ nano_create_p2pow_block_dynamic()

int nano_create_p2pow_block_dynamic ( F_BLOCK_TRANSFER **  ,
F_BLOCK_TRANSFER *  ,
const void *  ,
size_t  ,
const void *  ,
uint32_t  ,
const void *  ,
size_t   
)

◆ pk_to_wallet()

int pk_to_wallet ( char *  out,
char *  prefix,
NANO_PUBLIC_KEY_EXTENDED  pubkey_extended 
)

Parse a Nano public key to Base32 Nano wallet string.

Parameters
[out]outOutput string containing the wallet
[in]prefixNano prefix.

NANO_PREFIX for nano_
XRB_PREFIX for xrb_
[in,out]pubkey_extendedPublic key to be parsed to string

WARNING: pubkey_extended is destroyed when parsing to Nano base32 encoding

Return values
0On Success, otherwise Error
See also
nano_base_32_2_hex()

◆ to_multiplier()

double to_multiplier ( uint64_t  difficulty,
uint64_t  base_difficulty 
)

Calculates a relative difficulty compared PoW with another.

Parameters
[in]dificultyWork difficulty
[in]base_difficultyBase difficulty Details here
See also
from_multiplier()
Return values
Calculatedvalue

◆ valid_nano_wallet()

int valid_nano_wallet ( const char *  wallet)

Check if a string containing a Base32 Nano wallet is valid.

Parameters
[in]walletBase32 Nano wallet encoded string
Return values
0If valid wallet otherwise is invalid

◆ valid_raw_balance()

int valid_raw_balance ( const char *  balance)

Checks if a string buffer pointed in balance is a valid raw balance.

Parameters
[in]balancePointer containing a string buffer
Return values
0On Success, otherwise Error

Variable Documentation

◆ account

uint8_t account[32]

Account in raw binary data.

Definition at line 262 of file f_nano_crypto_util.h.

◆ balance

f_uint128_t balance

Big number 128 bit raw balance.

See also
f_uint128_t

Definition at line 270 of file f_nano_crypto_util.h.

◆ body

F_NANO_WALLET_INFO_BODY body

Body of the file info.

Definition at line 270 of file f_nano_crypto_util.h.

◆ desc

char desc[F_NANO_DESC_SZ]

Description.

Definition at line 264 of file f_nano_crypto_util.h.

◆ description

uint8_t description[F_DESC_SZ]

File description.

Definition at line 264 of file f_nano_crypto_util.h.

◆ file_info_integrity

uint8_t file_info_integrity[32]

File info integrity of the body block.

Definition at line 268 of file f_nano_crypto_util.h.

◆ hash_sk_unencrypted

uint8_t hash_sk_unencrypted[32]

hash of Nano SEED when unencrypted

Definition at line 266 of file f_nano_crypto_util.h.

◆ header

uint8_t header[sizeof(F_NANO_WALLET_INFO_MAGIC)]

Header magic.

Definition at line 260 of file f_nano_crypto_util.h.

◆ iv

uint8_t iv

Initial sub vector.

Initial vector of first encryption layer.

Definition at line 262 of file f_nano_crypto_util.h.

◆ last_used_wallet_number

uint32_t last_used_wallet_number

Last used wallet number.

Definition at line 262 of file f_nano_crypto_util.h.

◆ link

uint8_t link[32]

link or destination account

Definition at line 272 of file f_nano_crypto_util.h.

◆ max_fee

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.

◆ nano_hdr

uint8_t nano_hdr[sizeof(NANO_WALLET_MAGIC)]

Header of the file.

Definition at line 260 of file f_nano_crypto_util.h.

◆ nanoseed_hash

uint8_t nanoseed_hash[32]

Nano SEED hash file.

Definition at line 266 of file f_nano_crypto_util.h.

◆ preamble

uint8_t preamble[32]

Block preamble.

Definition at line 260 of file f_nano_crypto_util.h.

◆ prefixes

uint8_t prefixes

Internal use for this API.

Definition at line 276 of file f_nano_crypto_util.h.

◆ previous

uint8_t previous[32]

Previous block.

Definition at line 264 of file f_nano_crypto_util.h.

◆ representative

uint8_t representative[32]

Representative for current account.

Definition at line 266 of file f_nano_crypto_util.h.

◆ reserved

uint8_t reserved

Reserved (not used)

Reserved.

Definition at line 264 of file f_nano_crypto_util.h.

◆ salt

uint8_t salt[32]

Salt of the first encryption layer.

Definition at line 266 of file f_nano_crypto_util.h.

◆ seed_block

F_ENCRYPTED_BLOCK seed_block

Second encrypted block for Nano SEED.

Definition at line 270 of file f_nano_crypto_util.h.

◆ signature

uint8_t signature[64]

Signature of the block.

Definition at line 274 of file f_nano_crypto_util.h.

◆ sk_encrypted

uint8_t sk_encrypted[32]

Secret.

SEED encrypted (second layer)

Definition at line 268 of file f_nano_crypto_util.h.

◆ sub_salt

uint8_t sub_salt[32]

Salt of the sub block to be stored.

Definition at line 260 of file f_nano_crypto_util.h.

◆ ver

uint32_t ver

Version of the file.

Definition at line 262 of file f_nano_crypto_util.h.

◆ version

uint16_t version

Version.

Definition at line 262 of file f_nano_crypto_util.h.

◆ wallet_prefix

uint8_t wallet_prefix

Wallet prefix: 0 for NANO; 1 for XRB.

Definition at line 260 of file f_nano_crypto_util.h.

◆ wallet_representative

char wallet_representative[MAX_STR_NANO_CHAR]

Wallet representative.

Definition at line 264 of file f_nano_crypto_util.h.

◆ work

uint64_t work

Internal use for this API.

Definition at line 278 of file f_nano_crypto_util.h.