You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_interfaces.py 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. ###############################################################################
  2. #
  3. # The MIT License (MIT)
  4. #
  5. # Copyright (c) Crossbar.io Technologies GmbH
  6. #
  7. # Permission is hereby granted, free of charge, to any person obtaining a copy
  8. # of this software and associated documentation files (the "Software"), to deal
  9. # in the Software without restriction, including without limitation the rights
  10. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. # copies of the Software, and to permit persons to whom the Software is
  12. # furnished to do so, subject to the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be included in
  15. # all copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. # THE SOFTWARE.
  24. #
  25. ###############################################################################
  26. import abc
  27. import six
  28. @six.add_metaclass(abc.ABCMeta)
  29. class IMarketMaker(object):
  30. """
  31. XBR Market Maker interface.
  32. """
  33. @abc.abstractmethod
  34. def status(self, details):
  35. """
  36. :param details:
  37. :return:
  38. """
  39. @abc.abstractmethod
  40. def offer(self, key_id, price, details):
  41. """
  42. :param key_id:
  43. :param price:
  44. :param details:
  45. :return:
  46. """
  47. @abc.abstractmethod
  48. def revoke(self, key_id, details):
  49. """
  50. :param key_id:
  51. :param details:
  52. :return:
  53. """
  54. @abc.abstractmethod
  55. def quote(self, key_id, details):
  56. """
  57. :param key_id:
  58. :param details:
  59. :return:
  60. """
  61. @abc.abstractmethod
  62. def buy(self, channel_id, channel_seq, buyer_pubkey, datakey_id, amount, balance, signature, details):
  63. """
  64. :param channel_id:
  65. :param channel_seq:
  66. :param buyer_pubkey:
  67. :param datakey_id:
  68. :param amount:
  69. :param balance:
  70. :param signature:
  71. :param details:
  72. :return:
  73. """
  74. @abc.abstractmethod
  75. def get_payment_channels(self, address, details):
  76. """
  77. :param address:
  78. :param details:
  79. :return:
  80. """
  81. @abc.abstractmethod
  82. def get_payment_channel(self, channel_id, details):
  83. """
  84. :param channel_id:
  85. :param details:
  86. :return:
  87. """
  88. @six.add_metaclass(abc.ABCMeta)
  89. class IProvider(object):
  90. """
  91. XBR Provider interface.
  92. """
  93. @abc.abstractmethod
  94. def sell(self, key_id, buyer_pubkey, amount_paid, post_balance, signature, details):
  95. """
  96. :param key_id:
  97. :param buyer_pubkey:
  98. :param amount_paid:
  99. :param post_balance:
  100. :param signature:
  101. :param details:
  102. :return:
  103. """
  104. @six.add_metaclass(abc.ABCMeta)
  105. class IConsumer(object):
  106. """
  107. XBR Consumer interface.
  108. """
  109. @six.add_metaclass(abc.ABCMeta)
  110. class ISeller(object):
  111. """
  112. XBR Seller interface.
  113. """
  114. @abc.abstractmethod
  115. async def start(self, session):
  116. """
  117. :param session:
  118. :return:
  119. """
  120. @abc.abstractmethod
  121. async def wrap(self, uri, payload):
  122. """
  123. :param uri:
  124. :param payload:
  125. :return:
  126. """
  127. @six.add_metaclass(abc.ABCMeta)
  128. class IBuyer(object):
  129. """
  130. XBR Buyer interface.
  131. """
  132. @abc.abstractmethod
  133. async def start(self, session):
  134. """
  135. Start buying keys over the provided session.
  136. :param session: WAMP session that allows to talk to the XBR Market Maker.
  137. """
  138. @abc.abstractmethod
  139. async def unwrap(self, key_id, enc_ser, ciphertext):
  140. """
  141. Decrypt and deserialize received XBR payload.
  142. :param key_id: The ID of the datakey the payload is encrypted with.
  143. :type key_id: bytes
  144. :param enc_ser: The serializer that was used for serializing the payload. One of ``cbor``, ``json``, ``msgpack``, ``ubjson``.
  145. :type enc_ser: str
  146. :param ciphertext: The encrypted payload to unwrap.
  147. :type ciphertext: bytes
  148. :returns: The unwrapped application payload.
  149. :rtype: object
  150. """