cash_addr.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Copyright (c) 2017 Jochen Hoenicke, Pieter Wuille
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. #ifndef _CASH_ADDR_H_
  22. #define _CASH_ADDR_H_ 1
  23. #include <stdint.h>
  24. /** Encode a Cashaddr address
  25. *
  26. * Out: output: Pointer to a buffer of size 105 + strlen(hrp) that will be
  27. * updated to contain the null-terminated address.
  28. * In: hrp: Pointer to the null-terminated human readable part to use
  29. * (chain/network specific).
  30. * prog: Data bytes for the hash (between 21 and 65 bytes).
  31. * prog_len: Number of data bytes in prog.
  32. * Returns 1 if successful.
  33. */
  34. int cash_addr_encode(char* output, const char* hrp, const uint8_t* prog, size_t prog_len);
  35. /** Decode a CashAddr address
  36. *
  37. * Out: prog: Pointer to a buffer of size 65 that will be updated to
  38. * contain the witness program bytes.
  39. * prog_len: Pointer to a size_t that will be updated to contain the
  40. * length of bytes in prog. hrp: Pointer to the null-terminated human
  41. * readable part that is expected (chain/network specific). addr: Pointer to
  42. * the null-terminated address. Returns 1 if successful.
  43. */
  44. int cash_addr_decode(uint8_t* prog, size_t* prog_len, const char* hrp, const char* addr);
  45. /** Encode a Cash string
  46. *
  47. * Out: output: Pointer to a buffer of size strlen(hrp) + data_len + 8 that
  48. * will be updated to contain the null-terminated Cash string.
  49. * In: hrp : Pointer to the null-terminated human readable part.
  50. * data : Pointer to an array of 5-bit values.
  51. * data_len: Length of the data array.
  52. * Returns 1 if successful.
  53. */
  54. int cash_encode(char* output, const char* hrp, const uint8_t* data, size_t data_len);
  55. /** Decode a Cash string
  56. *
  57. * Out: hrp: Pointer to a buffer of size strlen(input) - 6. Will be
  58. * updated to contain the null-terminated human readable part.
  59. * data: Pointer to a buffer of size strlen(input) - 8 that will
  60. * hold the encoded 5-bit data values.
  61. * data_len: Pointer to a size_t that will be updated to be the number
  62. * of entries in data.
  63. * In: input: Pointer to a null-terminated Cash string.
  64. * Returns 1 if succesful.
  65. */
  66. int cash_decode(char* hrp, uint8_t* data, size_t* data_len, const char* input);
  67. #endif