Nano cryptocurrency C library with P2PoW/DPoW support  1.0.0
f_nano_crypto_util.h
Go to the documentation of this file.
1 /*
2  AUTHOR: Fábio Pereira da Silva
3  YEAR: 2019-20
4  LICENSE: MIT
5  EMAIL: fabioegel@gmail.com or fabioegel@protonmail.com
6 */
7 
8 #include <errors.h>
9 #include <stdint.h>
10 #include <f_util.h>
11 #include <f_bitcoin.h>
12 
13 #ifndef F_DOC_SKIP
14 
15  #ifdef F_XTENSA
16 
17  #ifndef F_ESP32
18  #define F_ESP32
19  #endif
20 
21  #include "esp_system.h"
22 
23  #endif
24 
25  #include "sodium/crypto_generichash.h"
26  #include "sodium/crypto_sign.h"
27  #include "sodium.h"
28 
29  #ifdef F_ESP32
30 
31  #include "sodium/private/curve25519_ref10.h"
32 
33  #else
34 
35  #include "sodium/private/ed25519_ref10.h"
36 
37  #define ge_p3 ge25519_p3
38  #define sc_reduce sc25519_reduce
39  #define sc_muladd sc25519_muladd
40  #define ge_scalarmult_base ge25519_scalarmult_base
41  #define ge_p3_tobytes ge25519_p3_tobytes
42 
43  #endif
44 
45 #endif
46 
47 #include <version.h>
48 
131 #ifdef __cplusplus
132 extern "C" {
133 #endif
134 
135 
140 #define F_NANO_POW_MAX_THREAD (size_t)10
141 
142 #ifndef F_DOC_SKIP
143  #ifdef F_ESP32
144  #undef F_NANO_POW_MAX_THREAD
145  #endif
146 #endif
147 
152 #define MAX_STR_NANO_CHAR (size_t)70 //5+56+8+1
153 
158 #define PUB_KEY_EXTENDED_MAX_LEN (size_t)40
159 
164 #define NANO_PREFIX "nano_"
165 
170 #define XRB_PREFIX "xrb_"
171 
172 #ifdef F_ESP32
173 
178 #define BIP39_DICTIONARY "/spiffs/dictionary.dic"
179 #else
180 
181  #ifndef F_DOC_SKIP
182  #define BIP39_DICTIONARY_SAMPLE "../../dictionary.dic"
183  #define BIP39_DICTIONARY "dictionary.dic"
184  #endif
185 
186 #endif
187 
194 #define NANO_ENCRYPTED_SEED_FILE "/spiffs/secure/nano.nse"
195 
200 #define NANO_PASSWD_MAX_LEN (size_t)80
201 
206 #define STR_NANO_SZ (size_t)66// 65+1 Null included
207 
212 #define NANO_FILE_WALLETS_INFO "/spiffs/secure/walletsinfo.i"
213 
218 typedef uint8_t F_TOKEN[16];
219 
224 typedef uint8_t NANO_SEED[crypto_sign_SEEDBYTES];
225 
230 typedef uint8_t f_uint128_t[16];
231 
232 #ifndef F_DOC_SKIP
233  #define EXPORT_KEY_TO_CHAR_SZ (size_t)sizeof(NANO_SEED)+1
234 #endif
235 
240 typedef uint8_t NANO_PRIVATE_KEY[sizeof(NANO_SEED)];
241 
246 typedef uint8_t NANO_PRIVATE_KEY_EXTENDED[crypto_sign_ed25519_SECRETKEYBYTES];
247 
252 typedef uint8_t NANO_PUBLIC_KEY[crypto_sign_ed25519_PUBLICKEYBYTES];
253 
259 
268 typedef struct f_block_transfer_t {
270  uint8_t preamble[32];
272  uint8_t account[32];
274  uint8_t previous[32];
276  uint8_t representative[32];
280  f_uint128_t balance;
282  uint8_t link[32];
284  uint8_t signature[64];
286  uint8_t prefixes;
288  uint64_t work;
289 } __attribute__((packed)) F_BLOCK_TRANSFER;
290 
291 #define F_BLOCK_TRANSFER_SIZE (size_t)sizeof(F_BLOCK_TRANSFER)
292 #define F_P2POW_BLOCK_TRANSFER_SIZE 2*F_BLOCK_TRANSFER_SIZE
293 
294 #ifndef F_DOC_SKIP
295  #define F_BLOCK_TRANSFER_SIGNABLE_SZ (size_t)(sizeof(F_BLOCK_TRANSFER)-64-sizeof(uint64_t)-sizeof(uint8_t))
296 #endif
297 
305 typedef enum f_nano_err_t {
354 } f_nano_err;
355 
356 #ifndef F_DOC_SKIP
357 
358  #define READ_SEED_FROM_STREAM (int)1
359  #define READ_SEED_FROM_FILE (int)2
360  #define WRITE_SEED_TO_STREAM (int)4
361  #define WRITE_SEED_TO_FILE (int)8
362  #define PARSE_JSON_READ_SEED_GENERIC (int)16
363  #define F_STREAM_DATA_FILE_VERSION (uint32_t)((1<<16)|0)
364 
365 #endif
366 
376  uint8_t sub_salt[32];
378  uint8_t iv[16];
380  uint8_t reserved[16];
382  uint8_t hash_sk_unencrypted[32];
384  uint8_t sk_encrypted[32];
385 } __attribute__ ((packed)) F_ENCRYPTED_BLOCK;
386 
387 #ifndef F_DOC_SKIP
388 
389  static const uint8_t NANO_WALLET_MAGIC[] = {'_', 'n', 'a', 'n', 'o', 'w', 'a', 'l', 'l', 'e', 't', 'f', 'i', 'l', 'e', '_'};
390  #define F_NANO_FILE_DESC "NANO Seed Encrypted file/stream. Keep it safe and backup it. This file is protected by password. BUY BITCOIN and NANO !!!"
391  #define F_DESC_SZ (size_t) (160-sizeof(uint32_t))
392 
393 #endif
394 
402 typedef struct f_nano_crypto_wallet_t {
404  uint8_t nano_hdr[sizeof(NANO_WALLET_MAGIC)];
406  uint32_t ver;
408  uint8_t description[F_DESC_SZ];
410  uint8_t salt[32];
412  uint8_t iv[16];
414  F_ENCRYPTED_BLOCK seed_block;
415 } __attribute__ ((packed)) F_NANO_CRYPTOWALLET;
416 
417 #ifndef F_DOC_SKIP
418 
419 _Static_assert((sizeof(F_NANO_CRYPTOWALLET)&0x1F)==0, "Error 1");
420 _Static_assert((sizeof(F_ENCRYPTED_BLOCK)&0x1F)==0, "Error 2");
421 
422 #endif
423 
428 #define REP_XRB (uint8_t)0x4
429 
434 #define SENDER_XRB (uint8_t)0x02
435 
440 #define DEST_XRB (uint8_t)0x01
441 
442 typedef enum f_write_seed_err_t {
468 
469 #ifndef F_DOC_SKIP
470 
471  #define F_RAW_TO_STR_UINT128 (int)1
472  #define F_RAW_TO_STR_STRING (int)2
473  #define F_RAW_STR_MAX_SZ (size_t)41 // 39 + '\0' + '.' -> 39 = log10(2^128)
474  #define F_MAX_STR_RAW_BALANCE_MAX (size_t)40 //39+'\0'
475  #define F_NANO_EMPTY_BALANCE "0.0"
476 
477 #endif
478 
486 typedef struct f_nano_wallet_info_bdy_t {
488  uint8_t wallet_prefix; // 0 for NANO; 1 for XRB
494  char max_fee[F_RAW_STR_MAX_SZ];
496  uint8_t reserved[44];
497 } __attribute__((packed)) F_NANO_WALLET_INFO_BODY;
498 
499 #ifndef F_DOC_SKIP
500 
501  _Static_assert((sizeof(F_NANO_WALLET_INFO_BODY)&0x1F)==0, "Error F_NANO_WALLET_INFO_BODY is not byte aligned");
502 
503  #define F_NANO_WALLET_INFO_DESC "Nano file descriptor used for fast custom access. BUY BITCOIN AND NANO."
504  #define F_NANO_WALLET_INFO_VERSION (uint16_t)((1<<8)|1)
505  static const uint8_t F_NANO_WALLET_INFO_MAGIC[] = {'_', 'n', 'a', 'n', 'o', 'w', 'a', 'l', 'l', 'e', 't', '_', 'n', 'f', 'o', '_'};
506 
507  #define F_NANO_DESC_SZ (size_t)78
508 
509 #endif
510 
518 typedef struct f_nano_wallet_info_t {
520  uint8_t header[sizeof(F_NANO_WALLET_INFO_MAGIC)];
522  uint16_t version;
524  char desc[F_NANO_DESC_SZ];
526  uint8_t nanoseed_hash[32];
528  uint8_t file_info_integrity[32];
530  F_NANO_WALLET_INFO_BODY body;
531 } __attribute__((packed)) F_NANO_WALLET_INFO;
532 
533 #ifndef F_DOC_SKIP
534 
535  _Static_assert((sizeof(F_NANO_WALLET_INFO)&0x1F)==0, "Error F_NANO_WALLET_INFO is not byte aligned");
536 
537 #endif
538 
546 typedef enum f_file_info_err_t {
578 
579 #ifndef F_DOC_SKIP
580 
581  #define F_NANO_ADD_A_B (uint32_t)(1<<0)
582  #define F_NANO_SUB_A_B (uint32_t)(1<<1)
583  #define F_NANO_A_RAW_128 (uint32_t)(1<<2)
584  #define F_NANO_A_RAW_STRING (uint32_t)(1<<3)
585  #define F_NANO_A_REAL_STRING (uint32_t)(1<<4)
586  #define F_NANO_B_RAW_128 (uint32_t)(1<<5)
587  #define F_NANO_B_RAW_STRING (uint32_t)(1<<6)
588  #define F_NANO_B_REAL_STRING (uint32_t)(1<<7)
589  #define F_NANO_RES_RAW_128 (uint32_t)(1<<8)
590  #define F_NANO_RES_RAW_STRING (uint32_t)(1<<9)
591  #define F_NANO_RES_REAL_STRING (uint32_t)(1<<10)
592  #define F_NANO_C_RAW_128 (uint32_t)(F_NANO_B_RAW_128<<16)
593  #define F_NANO_C_RAW_STRING (uint32_t)(F_NANO_B_RAW_STRING<<16)
594  #define F_NANO_C_REAL_STRING (uint32_t)(F_NANO_B_REAL_STRING<<16)
595 
596  #define F_NANO_COMPARE_EQ (uint32_t)(1<<16) //Equal
597  #define F_NANO_COMPARE_LT (uint32_t)(1<<17) // Lesser than
598  #define F_NANO_COMPARE_LEQ (F_NANO_COMPARE_LT|F_NANO_COMPARE_EQ) // Less or equal
599  #define F_NANO_COMPARE_GT (uint32_t)(1<<18) // Greater
600  #define F_NANO_COMPARE_GEQ (F_NANO_COMPARE_GT|F_NANO_COMPARE_EQ) // Greater or equal
601  #define DEFAULT_MAX_FEE "0.001"
602 
603 #endif
604 
605 #ifndef F_ESP32
610 // NANO_CREATE_BLK_DYN_PREV_NULL,
628 
637 
638 #endif
639 
651 double to_multiplier(uint64_t, uint64_t);
652 
664 uint64_t from_multiplier(double, uint64_t);
665 
675 void f_set_dictionary_path(const char *);
676 
684 char *f_get_dictionary_path(void);
685 
698 int f_generate_token(F_TOKEN, void *, size_t, const char *);
699 
712 int f_verify_token(F_TOKEN, void *, size_t, const char *);
713 
736 int f_cloud_crypto_wallet_nano_create_seed(size_t, char *, char *);
737 
750 int f_generate_nano_seed(NANO_SEED, uint32_t);
751 
766 int pk_to_wallet(char *, char *, NANO_PUBLIC_KEY_EXTENDED);
767 
785 int f_seed_to_nano_wallet(NANO_PRIVATE_KEY, NANO_PUBLIC_KEY, NANO_SEED, uint32_t);
786 
796 int f_nano_is_valid_block(F_BLOCK_TRANSFER *);
797 
810 int f_nano_block_to_json(char *, size_t *, size_t, F_BLOCK_TRANSFER *);
811 
822 int f_nano_get_block_hash(uint8_t *, F_BLOCK_TRANSFER *);
823 
835 int f_nano_get_p2pow_block_hash(uint8_t *, uint8_t *, F_BLOCK_TRANSFER *);
836 
849 int f_nano_p2pow_to_JSON(char *, size_t *, size_t, F_BLOCK_TRANSFER *);
850 
860 char *f_nano_key_to_str(char *, unsigned char *);
861 
880 int f_nano_seed_to_bip39(char *, size_t, size_t *, NANO_SEED, char *);
881 
896 int f_bip39_to_nano_seed(uint8_t *, char *, char *);
897 
919 int f_parse_nano_seed_and_bip39_to_JSON(char *, size_t, size_t *, void *, int, const char *);
920 
938 int f_read_seed(uint8_t *, const char *, void *, int, int);
939 
954 int f_nano_raw_to_string(char *, size_t *, size_t, void *, int);
955 
964 int f_nano_valid_nano_str_value(const char *);
965 
973 int valid_nano_wallet(const char *);
974 
984 int nano_base_32_2_hex(uint8_t *, char *);
985 
1000 int f_nano_transaction_to_JSON(char *, size_t, size_t *, NANO_PRIVATE_KEY_EXTENDED, F_BLOCK_TRANSFER *);
1001 
1009 int valid_raw_balance(const char *);
1010 
1018 int is_null_hash(uint8_t *);
1019 
1031 int is_nano_prefix(const char *, const char *);
1032 
1041 F_FILE_INFO_ERR f_get_nano_file_info(F_NANO_WALLET_INFO *);
1042 
1052 F_FILE_INFO_ERR f_set_nano_file_info(F_NANO_WALLET_INFO *, int);
1053 
1075 f_nano_err f_nano_value_compare_value(void *, void *, uint32_t *);
1076 
1097 f_nano_err f_nano_verify_nano_funds(void *, void *, void *, uint32_t);
1098 
1108 f_nano_err f_nano_parse_raw_str_to_raw128_t(uint8_t *, const char *);
1109 
1119 f_nano_err f_nano_parse_real_str_to_raw128_t(uint8_t *, const char *);
1120 
1143 f_nano_err f_nano_add_sub(void *, void *, void *, uint32_t);
1144 
1155 int f_nano_sign_block(F_BLOCK_TRANSFER *, F_BLOCK_TRANSFER *, NANO_PRIVATE_KEY_EXTENDED);
1156 
1170 f_write_seed_err f_write_seed(void *, int, uint8_t *, char *);
1171 
1184 f_nano_err f_nano_balance_to_str(char *, size_t, size_t *, f_uint128_t);
1185 
1186 
1191 #define F_BRAIN_WALLET_VERY_POOR (uint32_t)0
1192 
1197 #define F_BRAIN_WALLET_POOR (uint32_t)1
1198 
1203 #define F_BRAIN_WALLET_VERY_BAD (uint32_t)2
1204 
1209 #define F_BRAIN_WALLET_BAD (uint32_t)3
1210 
1215 #define F_BRAIN_WALLET_VERY_WEAK (uint32_t)4
1216 
1221 #define F_BRAIN_WALLET_WEAK (uint32_t)5
1222 
1227 #define F_BRAIN_WALLET_STILL_WEAK (uint32_t)6
1228 
1233 #define F_BRAIN_WALLET_MAYBE_GOOD (uint32_t)7
1234 
1235 
1240 #define F_BRAIN_WALLET_GOOD (uint32_t)8
1241 
1246 #define F_BRAIN_WALLET_VERY_GOOD (uint32_t)9
1247 
1252 #define F_BRAIN_WALLET_NICE (uint32_t)10
1253 
1258 #define F_BRAIN_WALLET_PERFECT (uint32_t)11
1259 
1286 int f_extract_seed_from_brainwallet(uint8_t *, char **, uint32_t, const char *, const char *);
1287 
1299 int f_verify_work(uint64_t *, const unsigned char *, uint64_t *, uint64_t);
1300 
1306 #define F_SIGNATURE_RAW (uint32_t)1
1307 
1313 #define F_SIGNATURE_STRING (uint32_t)2
1314 
1320 #define F_SIGNATURE_OUTPUT_RAW_PK (uint32_t)4
1321 
1327 #define F_SIGNATURE_OUTPUT_STRING_PK (uint32_t)8
1328 
1334 #define F_SIGNATURE_OUTPUT_XRB_PK (uint32_t)16
1335 
1341 #define F_SIGNATURE_OUTPUT_NANO_PK (uint32_t)32
1342 
1348 #define F_IS_SIGNATURE_RAW_HEX_STRING (uint32_t)64
1349 
1355 #define F_MESSAGE_IS_HASH_STRING (uint32_t)128
1356 
1361 #define F_DEFAULT_THRESHOLD (uint64_t) 0xffffffc000000000
1362 
1386 int f_sign_data(
1387  unsigned char *signature,
1388  void *out_public_key,
1389  uint32_t ouput_type,
1390  const unsigned char *message,
1391  size_t msg_len,
1392  const unsigned char *private_key);
1393 
1399 #define F_VERIFY_SIG_NANO_WALLET (uint32_t)1
1400 
1406 #define F_PUBLIC_KEY_RAW_HEX (uint32_t)2
1407 
1413 #define F_PUBLIC_KEY_ASCII_HEX (uint32_t)4
1414 
1435 int f_verify_signed_data( const unsigned char *, const unsigned char *, size_t, const void *, uint32_t);
1436 
1446 int f_is_valid_nano_seed_encrypted(void *, size_t, int);
1447 
1452 #define F_BALANCE_RAW_128 F_NANO_A_RAW_128
1453 
1458 #define F_BALANCE_REAL_STRING F_NANO_A_REAL_STRING
1459 
1464 #define F_BALANCE_RAW_STRING F_NANO_A_RAW_STRING
1465 
1470 #define F_VALUE_SEND_RECEIVE_RAW_128 F_NANO_B_RAW_128
1471 
1476 #define F_VALUE_SEND_RECEIVE_REAL_STRING F_NANO_B_REAL_STRING
1477 
1482 #define F_VALUE_SEND_RECEIVE_RAW_STRING F_NANO_B_RAW_STRING
1483 
1488 #define F_VALUE_TO_SEND (int)(1<<0)
1489 
1494 #define F_VALUE_TO_RECEIVE (int)(1<<1)
1495 
1500 #define F_FEE_VALUE_RAW_128 F_NANO_B_RAW_128
1501 
1506 #define F_FEE_VALUE_REAL_STRING F_NANO_B_REAL_STRING
1507 
1512 #define F_FEE_VALUE_RAW_STRING F_NANO_B_RAW_STRING
1513 
1561  F_BLOCK_TRANSFER **,
1562  const void *,
1563  size_t,
1564  const void *,
1565  size_t,
1566  const void *,
1567  size_t,
1568  const void *,
1569  const void *,
1570  uint32_t,
1571  const void *,
1572  size_t,
1573  int
1574 );
1575 
1577  F_BLOCK_TRANSFER **,
1578  F_BLOCK_TRANSFER *,
1579  const void *,
1580  size_t,
1581  const void *,
1582  uint32_t,
1583  const void *,
1584  size_t
1585 );
1586 
1587 int f_verify_signed_block(F_BLOCK_TRANSFER *);
1588 
1601 int f_nano_pow(uint64_t *, unsigned char *, const uint64_t, int);
1602 
1603 #ifdef __cplusplus
1604 }
1605 #endif
1606 
f_write_seed_err f_write_seed(void *, int, uint8_t *, char *)
Writes a SEED into a ecrypted with password with non deterministic stream in memory or file...
uint8_t account[32]
Account in raw binary data.
int f_nano_pow(uint64_t *, unsigned char *, const uint64_t, int)
Calculates a Proof of Work given a hash, threshold and number of threads n_thr
struct of the block of encrypted file to store Nano SEED
int f_nano_get_block_hash(uint8_t *, F_BLOCK_TRANSFER *)
Gets a hash from Nano block.
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
uint8_t hash_sk_unencrypted[32]
hash of Nano SEED when unencrypted
uint8_t NANO_PUBLIC_KEY_EXTENDED[PUB_KEY_EXTENDED_MAX_LEN]
Size of Public Key Extended.
uint64_t from_multiplier(double, uint64_t)
Calculates a PoW given a multiplier and base difficulty.
enum f_nano_err_t f_nano_err
Error function enumerator.
uint8_t nano_hdr[sizeof(NANO_WALLET_MAGIC)]
Header of the file.
Can not parse to MPI.
int f_nano_is_valid_block(F_BLOCK_TRANSFER *)
Checks if Binary Nano Block is valid.
int f_verify_work(uint64_t *, const unsigned char *, uint64_t *, uint64_t)
Verifies if Proof of Work of a given hash is valid.
f_uint128_t balance
Big number 128 bit raw balance.
f_write_seed_err_t
f_nano_create_block_dyn_err_t
Invalid A mode value.
uint8_t NANO_PRIVATE_KEY_EXTENDED[crypto_sign_ed25519_SECRETKEYBYTES]
Size of Nano Private Key extended.
int valid_raw_balance(const char *)
Checks if a string buffer pointed in balance is a valid raw balance.
enum f_nano_p2pow_block_dyn_err_t F_NANO_P2POW_BLOCK_DYN_ERR
F_FILE_INFO_ERR f_set_nano_file_info(F_NANO_WALLET_INFO *, int)
Saves wallet information stored at buffer struct info to file walletsinfo.i
f_nano_err f_nano_balance_to_str(char *, size_t, size_t *, f_uint128_t)
Converts a raw Nano balance to string raw balance.
char desc[F_NANO_DESC_SZ]
Description.
int f_nano_raw_to_string(char *, size_t *, size_t, void *, int)
Converts Nano raw balance [string | f_uint128_t] to real string value.
int is_null_hash(uint8_t *)
Check if 32 bytes hash is filled with zeroes.
uint8_t wallet_prefix
Wallet prefix: 0 for NANO; 1 for XRB.
#define MAX_STR_NANO_CHAR
Defines a max size of Nano char (70 bytes)
Invalid A mode value.
int f_nano_block_to_json(char *, size_t *, size_t, F_BLOCK_TRANSFER *)
Parse a Nano Block to JSON.
int f_nano_p2pow_to_JSON(char *, size_t *, size_t, F_BLOCK_TRANSFER *)
Parse binary P2PoW block to JSON.
struct of the block of encrypted file to store Nano SEED
Can not create file.
int f_nano_sign_block(F_BLOCK_TRANSFER *, F_BLOCK_TRANSFER *, NANO_PRIVATE_KEY_EXTENDED)
Signs user_block and worker fee_block given a private key private_key
int f_verify_signed_data(const unsigned char *, const unsigned char *, size_t, const void *, uint32_t)
Verifies if a signed message is valid.
uint8_t iv[16]
Initial sub vector.
Can not complete NULL char.
Does not make sense send empty value.
int nano_base_32_2_hex(uint8_t *, char *)
Parse Nano Base32 wallet string to public key binary.
uint32_t ver
Version of the file.
uint16_t version
Version.
uint8_t salt[32]
Salt of the first encryption layer.
uint8_t nanoseed_hash[32]
Nano SEED hash file.
f_nano_p2pow_block_dyn_err_t
int pk_to_wallet(char *, char *, NANO_PUBLIC_KEY_EXTENDED)
Parse a Nano public key to Base32 Nano wallet string.
F_ENCRYPTED_BLOCK seed_block
Second encrypted block for Nano SEED.
uint8_t NANO_SEED[crypto_sign_SEEDBYTES]
Size of Nano SEED.
This ABI is a utility for myNanoEmbedded library and sub routines are implemented here...
int f_nano_valid_nano_str_value(const char *)
Check if a real string or raw string are valid Nano balance.
int valid_nano_wallet(const char *)
Check if a string containing a Base32 Nano wallet is valid.
int f_verify_token(F_TOKEN, void *, size_t, const char *)
Verifies if a token is valid given data and password.
int f_bip39_to_nano_seed(uint8_t *, char *, char *)
Parse Nano Bip39 encoded string to raw Nano SEED given a dictionary file.
int nano_create_p2pow_block_dynamic(F_BLOCK_TRANSFER **, F_BLOCK_TRANSFER *, const void *, size_t, const void *, uint32_t, const void *, size_t)
Can not write file.
int f_nano_transaction_to_JSON(char *, size_t, size_t *, NANO_PRIVATE_KEY_EXTENDED, F_BLOCK_TRANSFER *)
Sign a block pointed in block_transfer with a given private_key and stores signed block to block_tran...
char * f_nano_key_to_str(char *, unsigned char *)
Parse a raw binary public key to string.
f_nano_err_t
enum f_write_seed_err_t f_write_seed_err
#define PUB_KEY_EXTENDED_MAX_LEN
Max size of public key (extended)
int f_read_seed(uint8_t *, const char *, void *, int, int)
Extracts a Nano SEED from encrypted stream in memory or in a file.
int f_cloud_crypto_wallet_nano_create_seed(size_t, char *, char *)
Generates a new SEED and saves it to an non deterministic encrypted file.
Encrypted file with Nano SEED not found.
Error SUCCESS.
Nano signed block raw data defined in this reference
Does not make sense send negativative balance.
void f_set_dictionary_path(const char *)
Set default dictionary file and path to myNanoEmbedded library.
Invalid output result.
struct of the body block of the info file
uint8_t NANO_PUBLIC_KEY[crypto_sign_ed25519_PUBLICKEYBYTES]
Size of Nano Public Key.
char max_fee[F_RAW_STR_MAX_SZ]
Custom preferred max fee of Proof of Work.
Can not parse to block transfer.
int f_extract_seed_from_brainwallet(uint8_t *, char **, uint32_t, const char *, const char *)
Analyzes a text given a mode and if pass then the text in braiwallet is translated to a Nano SEED...
Fatal ERROR MALLOC.
uint8_t representative[32]
Representative for current account.
Error NULL password.
F_NANO_WALLET_INFO_BODY body
Body of the file info.
uint8_t F_TOKEN[16]
uint8_t sub_salt[32]
Salt of the sub block to be stored.
int f_verify_signed_block(F_BLOCK_TRANSFER *)
f_nano_err f_nano_verify_nano_funds(void *, void *, void *, uint32_t)
Check if Nano balance has sufficient funds.
Can not parse value.
double to_multiplier(uint64_t, uint64_t)
Calculates a relative difficulty compared PoW with another.
enum f_nano_create_block_dyn_err_t F_NANO_CREATE_BLOCK_DYN_ERR
int f_nano_seed_to_bip39(char *, size_t, size_t *, NANO_SEED, char *)
Parse Nano SEED to Bip39 encoding given a dictionary file.
f_nano_err f_nano_parse_raw_str_to_raw128_t(uint8_t *, const char *)
Parse a raw string balance to raw big number 128 bit.
uint8_t file_info_integrity[32]
File info integrity of the body block.
Can not parse temporary memory to uint_128_t.
uint8_t prefixes
Internal use for this API.
char wallet_representative[MAX_STR_NANO_CHAR]
Wallet representative.
uint8_t f_uint128_t[16]
128 bit big number of Nano balance
uint8_t reserved[16]
Reserved (not used)
Can not generate main private key.
Can not parse raw A value to MPI.
uint64_t work
Internal use for this API.
Invalid info file header.
Error multiplication MPI.
enum f_file_info_err_t F_FILE_INFO_ERR
Typedef Error enumerator for info file functions.
Can not read encrypted Nano SEED in file.
Can not open info file for write.
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)
Creates a Nano block dynamically in memory.
f_nano_err f_nano_add_sub(void *, void *, void *, uint32_t)
Add/Subtract two Nano balance values and stores value in res
uint8_t description[F_DESC_SZ]
File description.
uint8_t NANO_PRIVATE_KEY[sizeof(NANO_SEED)]
Size of Nano Private Key.
Error add MPI.
uint32_t last_used_wallet_number
Last used wallet number.
Can not encrypt sub block.
Error empty string.
int f_generate_token(F_TOKEN, void *, size_t, const char *)
Generates a non deterministic token given a message data and a password.
Can not parse string big number.
char * f_get_dictionary_path(void)
Get default dictionary path in myNanoEmbedded library.
uint8_t sk_encrypted[32]
Secret.
uint8_t signature[64]
Signature of the block.
uint8_t link[32]
link or destination account
Can not parse raw B value to MPI.
Error encrypt private key.
int f_seed_to_nano_wallet(NANO_PRIVATE_KEY, NANO_PUBLIC_KEY, NANO_SEED, uint32_t)
Extracts one key pair from Nano SEED given a wallet number.
uint8_t preamble[32]
Block preamble.
Does not make sense negative balance.
int f_parse_nano_seed_and_bip39_to_JSON(char *, size_t, size_t *, void *, int, const char *)
Parse Nano SEED and Bip39 to JSON given a encrypted data in memory or encrypted data in file or unenc...
Can not parse big number factor.
uint8_t header[sizeof(F_NANO_WALLET_INFO_MAGIC)]
Header magic.
Error subtract MPI.
int f_is_valid_nano_seed_encrypted(void *, size_t, int)
Verifies if ecrypted Nano SEED is valid.
int f_nano_get_p2pow_block_hash(uint8_t *, uint8_t *, F_BLOCK_TRANSFER *)
Get Nano user block hash and Nano fee block hashes from P2PoW block.
int is_nano_prefix(const char *, const char *)
Checks prefix in nano_wallet
F_FILE_INFO_ERR f_get_nano_file_info(F_NANO_WALLET_INFO *)
Opens default file walletsinfo.i (if exists) containing information F_NANO_WALLET_INFO structure and ...
f_nano_err f_nano_parse_real_str_to_raw128_t(uint8_t *, const char *)
Parse a real string balance to raw big number 128 bit.
f_nano_err f_nano_value_compare_value(void *, void *, uint32_t *)
Comparare two Nano balance.
Can not parse MPI to string.
struct of the body block of the info file
Error enumerator for info file functions.
uint8_t previous[32]
Previous block.
Can not generate sub private key.
Fatal Error MALLOC.
struct f_block_transfer_t __attribute__((packed)) F_BLOCK_TRANSFER
int f_generate_nano_seed(NANO_SEED, uint32_t)
Generates a new SEED and stores it to seed pointer.