autobahn.xbr._seller


Module Contents

Classes

KeySeries

Data encryption key series with automatic (time-based) key rotation

PayingChannel

SimpleSeller

class autobahn.xbr._seller.KeySeries(api_id, price, interval=None, count=None, on_rotate=None)[source]

Bases: object

Data encryption key series with automatic (time-based) key rotation and key offering (to the XBR market maker).

property key_id

Get current XBR data encryption key ID (of the keys being rotated in a series).

Returns

Current key ID in key series (16 bytes).

Return type

bytes

async encrypt(payload)[source]

Encrypt data with the current XBR data encryption key.

Parameters

payload (object) – Application payload to encrypt.

Returns

The ciphertext for the encrypted application payload.

Return type

bytes

encrypt_key(key_id, buyer_pubkey)[source]

Encrypt a (previously used) XBR data encryption key with a buyer public key.

Parameters
  • key_id (bytes) – ID of the data encryption key to encrypt.

  • buyer_pubkey (bytes) – Buyer WAMP public key (Ed25519) to asymmetrically encrypt the data encryption key (selected by key_id) against.

Returns

The ciphertext for the encrypted data encryption key.

Return type

bytes

abstract start()[source]
abstract stop()[source]
async _rotate()[source]
class autobahn.xbr._seller.PayingChannel(adr, seq, balance)[source]

Bases: object

class autobahn.xbr._seller.SimpleSeller(market_maker_adr, seller_key, provider_id=None)[source]

Bases: object

property public_key

This seller delegate public Ethereum key.

Returns

Ethereum public key of this seller delegate.

Return type

bytes

log
KeySeries
STATE_NONE = 0
STATE_STARTING = 1
STATE_STARTED = 2
STATE_STOPPING = 3
STATE_STOPPED = 4
add(api_id, prefix, price, interval=None, count=None, categories=None)[source]

Add a new (rotating) private encryption key for encrypting data on the given API.

Parameters
  • api_id (bytes) – API for which to create a new series of rotating encryption keys.

  • price (int) – Price in XBR token per key.

  • interval (int) – Interval (in seconds) after which to auto-rotate the encryption key.

  • count (int) – Number of encryption operations after which to auto-rotate the encryption key.

async start(session)[source]

Start rotating keys and placing key offers with the XBR market maker.

Parameters

session (autobahn.wamp.protocol.ApplicationSession) – WAMP session over which to communicate with the XBR market maker.

async stop()[source]

Stop rotating/offering keys to the XBR market maker.

async balance()[source]

Return current (off-chain) balance of paying channel:

  • amount: The initial amount with which the paying channel was opened.

  • remaining: The remaining amount of XBR in the paying channel that can be earned.

  • inflight: The amount of XBR allocated to sell transactions that are currently processed.

Returns

Current paying balance.

Return type

dict

async wrap(api_id, uri, payload)[source]

Encrypt and wrap application payload for a given API and destined for a specific WAMP URI.

Parameters
  • api_id (bytes) – API for which to encrypt and wrap the application payload for.

  • uri (str) – WAMP URI the application payload is destined for (eg the procedure or topic URI).

  • payload (object) – Application payload to encrypt and wrap.

Returns

The encrypted and wrapped application payload: a tuple with (key_id, serializer, ciphertext).

Return type

tuple

close_channel(market_maker_adr, channel_oid, channel_seq, channel_balance, channel_is_final, marketmaker_signature, details=None)[source]

Called by a XBR Market Maker to close a paying channel.

sell(market_maker_adr, buyer_pubkey, key_id, channel_oid, channel_seq, amount, balance, signature, details=None)[source]

Called by a XBR Market Maker to buy a data encyption key. The XBR Market Maker here is acting for (triggered by) the XBR buyer delegate.

Parameters
  • market_maker_adr (bytes of length 20) – The market maker Ethereum address. The technical buyer is usually the XBR market maker (== the XBR delegate of the XBR market operator).

  • buyer_pubkey (bytes of length 32) – The buyer delegate Ed25519 public key.

  • key_id (bytes of length 16) – The UUID of the data encryption key to buy.

  • channel_oid (bytes of length 16) – The on-chain channel contract address.

  • channel_seq (int) – Paying channel sequence off-chain transaction number.

  • amount (bytes) – The amount paid by the XBR Buyer via the XBR Market Maker.

  • balance (bytes) – Balance remaining in the payment channel (from the market maker to the seller) after successfully buying the key.

  • signature (bytes of length 65) – Signature over the supplied buying information, using the Ethereum private key of the market maker (which is the delegate of the marker operator).

  • details (autobahn.wamp.types.CallDetails) – Caller details. The call will come from the XBR Market Maker.

Returns

The data encryption key, itself encrypted to the public key of the original buyer.

Return type

bytes