nem.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. #ifndef __NEM_H__
  23. #define __NEM_H__
  24. #include <stdbool.h>
  25. #include <stddef.h>
  26. #include <stdint.h>
  27. #include "bip32.h"
  28. #include "ed25519-donna/ed25519.h"
  29. #define NEM_LEVY_PERCENTILE_DIVISOR 4
  30. #define NEM_MAX_DIVISIBILITY 6
  31. #define NEM_MAX_SUPPLY 9000000000
  32. #define NEM_NETWORK_MAINNET 0x68
  33. #define NEM_NETWORK_TESTNET 0x98
  34. #define NEM_NETWORK_MIJIN 0x60
  35. #define NEM_ADDRESS_SIZE 40
  36. #define NEM_ADDRESS_SIZE_RAW 25
  37. #define NEM_TRANSACTION_TYPE_TRANSFER 0x0101
  38. #define NEM_TRANSACTION_TYPE_IMPORTANCE_TRANSFER 0x0801
  39. #define NEM_TRANSACTION_TYPE_AGGREGATE_MODIFICATION 0x1001
  40. #define NEM_TRANSACTION_TYPE_MULTISIG_SIGNATURE 0x1002
  41. #define NEM_TRANSACTION_TYPE_MULTISIG 0x1004
  42. #define NEM_TRANSACTION_TYPE_PROVISION_NAMESPACE 0x2001
  43. #define NEM_TRANSACTION_TYPE_MOSAIC_CREATION 0x4001
  44. #define NEM_TRANSACTION_TYPE_MOSAIC_SUPPLY_CHANGE 0x4002
  45. #define NEM_SALT_SIZE sizeof(ed25519_public_key)
  46. #define NEM_ENCRYPTED_SIZE(size) \
  47. (((size) + AES_BLOCK_SIZE) / AES_BLOCK_SIZE * AES_BLOCK_SIZE)
  48. #define NEM_ENCRYPTED_PAYLOAD_SIZE(size) \
  49. (AES_BLOCK_SIZE + NEM_SALT_SIZE + NEM_ENCRYPTED_SIZE(size))
  50. #define _NEM_PADDING_SIZE(buffer, size) ((buffer)[(size)-1])
  51. #define NEM_PADDING_SIZE(buffer, size) \
  52. (_NEM_PADDING_SIZE(buffer, size) > (size) ? (size) \
  53. : _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,
  63. uint8_t *address);
  64. bool nem_get_address(const ed25519_public_key public_key, uint8_t version,
  65. char *address);
  66. bool nem_validate_address_raw(const uint8_t *address, uint8_t network);
  67. bool nem_validate_address(const char *address, uint8_t network);
  68. void nem_transaction_start(nem_transaction_ctx *ctx,
  69. const ed25519_public_key public_key, uint8_t *buffer,
  70. size_t size);
  71. size_t nem_transaction_end(nem_transaction_ctx *ctx,
  72. const ed25519_secret_key private_key,
  73. ed25519_signature signature);
  74. bool nem_transaction_write_common(nem_transaction_ctx *context, uint32_t type,
  75. uint32_t version, uint32_t timestamp,
  76. const ed25519_public_key signer, uint64_t fee,
  77. uint32_t deadline);
  78. bool nem_transaction_create_transfer(nem_transaction_ctx *context,
  79. uint8_t network, uint32_t timestamp,
  80. const ed25519_public_key signer,
  81. uint64_t fee, uint32_t deadline,
  82. const char *recipient, uint64_t amount,
  83. const uint8_t *payload, uint32_t length,
  84. bool encrypted, uint32_t mosaics);
  85. bool nem_transaction_write_mosaic(nem_transaction_ctx *ctx,
  86. const char *namespace, const char *mosaic,
  87. uint64_t quantity);
  88. bool nem_transaction_create_multisig(nem_transaction_ctx *ctx, uint8_t network,
  89. uint32_t timestamp,
  90. const ed25519_public_key signer,
  91. uint64_t fee, uint32_t deadline,
  92. const nem_transaction_ctx *inner);
  93. bool nem_transaction_create_multisig_signature(
  94. nem_transaction_ctx *ctx, uint8_t network, uint32_t timestamp,
  95. const ed25519_public_key signer, uint64_t fee, uint32_t deadline,
  96. const nem_transaction_ctx *inner);
  97. bool nem_transaction_create_provision_namespace(
  98. nem_transaction_ctx *ctx, uint8_t network, uint32_t timestamp,
  99. const ed25519_public_key signer, uint64_t fee, uint32_t deadline,
  100. const char *namespace, const char *parent, const char *rental_sink,
  101. uint64_t rental_fee);
  102. bool nem_transaction_create_mosaic_creation(
  103. nem_transaction_ctx *ctx, uint8_t network, uint32_t timestamp,
  104. const ed25519_public_key signer, uint64_t fee, uint32_t deadline,
  105. const char *namespace, const char *mosaic, const char *description,
  106. uint32_t divisibility, uint64_t supply, bool mutable_supply,
  107. bool transferable, uint32_t levy_type, uint64_t levy_fee,
  108. const char *levy_address, const char *levy_namespace,
  109. const char *levy_mosaic, const char *creation_sink, uint64_t creation_fee);
  110. bool nem_transaction_create_mosaic_supply_change(
  111. nem_transaction_ctx *ctx, uint8_t network, uint32_t timestamp,
  112. const ed25519_public_key signer, uint64_t fee, uint32_t deadline,
  113. const char *namespace, const char *mosaic, uint32_t type, uint64_t delta);
  114. bool nem_transaction_create_aggregate_modification(
  115. nem_transaction_ctx *ctx, uint8_t network, uint32_t timestamp,
  116. const ed25519_public_key signer, uint64_t fee, uint32_t deadline,
  117. uint32_t modifications, bool relative_change);
  118. bool nem_transaction_write_cosignatory_modification(
  119. nem_transaction_ctx *ctx, uint32_t type,
  120. const ed25519_public_key cosignatory);
  121. bool nem_transaction_write_minimum_cosignatories(nem_transaction_ctx *ctx,
  122. int32_t relative_change);
  123. bool nem_transaction_create_importance_transfer(
  124. nem_transaction_ctx *ctx, uint8_t network, uint32_t timestamp,
  125. const ed25519_public_key signer, uint64_t fee, uint32_t deadline,
  126. uint32_t mode, const ed25519_public_key remote);
  127. #endif