nem.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /**
  2. * Copyright (c) 2017 Saleem Rashid
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included
  12. * in all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
  18. * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #include "../options.h"
  23. #if USE_NEM
  24. #ifndef __NEM_H__
  25. #define __NEM_H__
  26. #include <stdbool.h>
  27. #include <stddef.h>
  28. #include <stdint.h>
  29. #include "bip32.h"
  30. #include "ed25519_donna/ed25519.h"
  31. #define NEM_LEVY_PERCENTILE_DIVISOR 4
  32. #define NEM_MAX_DIVISIBILITY 6
  33. #define NEM_MAX_SUPPLY 9000000000
  34. #define NEM_NETWORK_MAINNET 0x68
  35. #define NEM_NETWORK_TESTNET 0x98
  36. #define NEM_NETWORK_MIJIN 0x60
  37. #define NEM_ADDRESS_SIZE 40
  38. #define NEM_ADDRESS_SIZE_RAW 25
  39. #define NEM_TRANSACTION_TYPE_TRANSFER 0x0101
  40. #define NEM_TRANSACTION_TYPE_IMPORTANCE_TRANSFER 0x0801
  41. #define NEM_TRANSACTION_TYPE_AGGREGATE_MODIFICATION 0x1001
  42. #define NEM_TRANSACTION_TYPE_MULTISIG_SIGNATURE 0x1002
  43. #define NEM_TRANSACTION_TYPE_MULTISIG 0x1004
  44. #define NEM_TRANSACTION_TYPE_PROVISION_NAMESPACE 0x2001
  45. #define NEM_TRANSACTION_TYPE_MOSAIC_CREATION 0x4001
  46. #define NEM_TRANSACTION_TYPE_MOSAIC_SUPPLY_CHANGE 0x4002
  47. #define NEM_SALT_SIZE sizeof(ed25519_public_key)
  48. #define NEM_ENCRYPTED_SIZE(size) (((size) + AES_BLOCK_SIZE) / AES_BLOCK_SIZE * AES_BLOCK_SIZE)
  49. #define NEM_ENCRYPTED_PAYLOAD_SIZE(size) \
  50. (AES_BLOCK_SIZE + NEM_SALT_SIZE + NEM_ENCRYPTED_SIZE(size))
  51. #define _NEM_PADDING_SIZE(buffer, size) ((buffer)[(size)-1])
  52. #define NEM_PADDING_SIZE(buffer, size) \
  53. (_NEM_PADDING_SIZE(buffer, size) > (size) ? (size) : _NEM_PADDING_SIZE(buffer, size))
  54. #define NEM_DECRYPTED_SIZE(buffer, size) ((size)-NEM_PADDING_SIZE(buffer, size))
  55. typedef struct {
  56. ed25519_public_key public_key;
  57. uint8_t* buffer;
  58. size_t offset;
  59. size_t size;
  60. } nem_transaction_ctx;
  61. const char* nem_network_name(uint8_t network);
  62. void nem_get_address_raw(const ed25519_public_key public_key, uint8_t version, uint8_t* address);
  63. bool nem_get_address(const ed25519_public_key public_key, uint8_t version, char* address);
  64. bool nem_validate_address_raw(const uint8_t* address, uint8_t network);
  65. bool nem_validate_address(const char* address, uint8_t network);
  66. void nem_transaction_start(
  67. nem_transaction_ctx* ctx,
  68. const ed25519_public_key public_key,
  69. uint8_t* buffer,
  70. size_t size);
  71. size_t nem_transaction_end(
  72. nem_transaction_ctx* ctx,
  73. const ed25519_secret_key private_key,
  74. ed25519_signature signature);
  75. bool nem_transaction_write_common(
  76. nem_transaction_ctx* context,
  77. uint32_t type,
  78. uint32_t version,
  79. uint32_t timestamp,
  80. const ed25519_public_key signer,
  81. uint64_t fee,
  82. uint32_t deadline);
  83. bool nem_transaction_create_transfer(
  84. nem_transaction_ctx* context,
  85. uint8_t network,
  86. uint32_t timestamp,
  87. const ed25519_public_key signer,
  88. uint64_t fee,
  89. uint32_t deadline,
  90. const char* recipient,
  91. uint64_t amount,
  92. const uint8_t* payload,
  93. uint32_t length,
  94. bool encrypted,
  95. uint32_t mosaics);
  96. bool nem_transaction_write_mosaic(
  97. nem_transaction_ctx* ctx,
  98. const char* namespace,
  99. const char* mosaic,
  100. uint64_t quantity);
  101. bool nem_transaction_create_multisig(
  102. nem_transaction_ctx* ctx,
  103. uint8_t network,
  104. uint32_t timestamp,
  105. const ed25519_public_key signer,
  106. uint64_t fee,
  107. uint32_t deadline,
  108. const nem_transaction_ctx* inner);
  109. bool nem_transaction_create_multisig_signature(
  110. nem_transaction_ctx* ctx,
  111. uint8_t network,
  112. uint32_t timestamp,
  113. const ed25519_public_key signer,
  114. uint64_t fee,
  115. uint32_t deadline,
  116. const nem_transaction_ctx* inner);
  117. bool nem_transaction_create_provision_namespace(
  118. nem_transaction_ctx* ctx,
  119. uint8_t network,
  120. uint32_t timestamp,
  121. const ed25519_public_key signer,
  122. uint64_t fee,
  123. uint32_t deadline,
  124. const char* namespace,
  125. const char* parent,
  126. const char* rental_sink,
  127. uint64_t rental_fee);
  128. bool nem_transaction_create_mosaic_creation(
  129. nem_transaction_ctx* ctx,
  130. uint8_t network,
  131. uint32_t timestamp,
  132. const ed25519_public_key signer,
  133. uint64_t fee,
  134. uint32_t deadline,
  135. const char* namespace,
  136. const char* mosaic,
  137. const char* description,
  138. uint32_t divisibility,
  139. uint64_t supply,
  140. bool mutable_supply,
  141. bool transferable,
  142. uint32_t levy_type,
  143. uint64_t levy_fee,
  144. const char* levy_address,
  145. const char* levy_namespace,
  146. const char* levy_mosaic,
  147. const char* creation_sink,
  148. uint64_t creation_fee);
  149. bool nem_transaction_create_mosaic_supply_change(
  150. nem_transaction_ctx* ctx,
  151. uint8_t network,
  152. uint32_t timestamp,
  153. const ed25519_public_key signer,
  154. uint64_t fee,
  155. uint32_t deadline,
  156. const char* namespace,
  157. const char* mosaic,
  158. uint32_t type,
  159. uint64_t delta);
  160. bool nem_transaction_create_aggregate_modification(
  161. nem_transaction_ctx* ctx,
  162. uint8_t network,
  163. uint32_t timestamp,
  164. const ed25519_public_key signer,
  165. uint64_t fee,
  166. uint32_t deadline,
  167. uint32_t modifications,
  168. bool relative_change);
  169. bool nem_transaction_write_cosignatory_modification(
  170. nem_transaction_ctx* ctx,
  171. uint32_t type,
  172. const ed25519_public_key cosignatory);
  173. bool nem_transaction_write_minimum_cosignatories(nem_transaction_ctx* ctx, int32_t relative_change);
  174. bool nem_transaction_create_importance_transfer(
  175. nem_transaction_ctx* ctx,
  176. uint8_t network,
  177. uint32_t timestamp,
  178. const ed25519_public_key signer,
  179. uint64_t fee,
  180. uint32_t deadline,
  181. uint32_t mode,
  182. const ed25519_public_key remote);
  183. #endif
  184. #endif // USE_NEM