Module autobahn.xbr

class autobahn.xbr.ActorType[source]

XBR Market Actor type.

CONSUMER = 2

Actor is a XBR Consumer.

NONE = 0

Unset

PROVIDER = 1

Actor is a XBR Provider.

PROVIDER_CONSUMER = 3

Actor is both a XBR Provider and XBR Consumer.

class autobahn.xbr.ChannelType[source]

Type of a XBR off-chain channel: paying channel (for provider delegates selling data services) or payment channel (for consumer delegates buying data services).

NONE = 0

Unset

PAYING = 2

Paying channel: from market maker to seller/provider delegate.

PAYMENT = 1

Payment channel: from buyer/consumer delegate to maker maker.

class autobahn.xbr.EthereumKey(key_or_address: LocalAccount | str | bytes, can_sign: bool, security_module: ISecurityModule | None = None, key_no: int | None = None)[source]

Base class to implement autobahn.wamp.interfaces.IEthereumKey.

address(binary: bool = False) str | bytes[source]

Implements autobahn.wamp.interfaces.IEthereumKey.address().

property can_sign: bool

Implements autobahn.wamp.interfaces.IKey.can_sign().

classmethod from_address(address: str | bytes) EthereumKey[source]

Create a public key from an address, which can be used to verify signatures.

Parameters:

address – The Ethereum address (20 octets).

Returns:

New instance of EthereumKey

classmethod from_bytes(key: bytes) EthereumKey[source]

Create a private key from seed bytes, which can be used to sign and create signatures.

Parameters:

key – The Ethereum private key seed (32 octets).

Returns:

New instance of EthereumKey

classmethod from_keyfile(keyfile: str) EthereumKey[source]

Create a public or private key from reading the given public or private key file.

Here is an example key file that includes an Ethereum private key private-key-eth, which is loaded in this function, and other fields, which are ignored by this function:

This is a comment (all lines until the first empty line are comments indeed).

creator: oberstet@intel-nuci7
created-at: 2022-07-05T12:29:48.832Z
user-id: oberstet@intel-nuci7
public-key-ed25519: 7326d9dc0307681cc6940fde0e60eb31a6e4d642a81e55c434462ce31f95deed
public-adr-eth: 0x10848feBdf7f200Ba989CDf7E3eEB3EC03ae7768
private-key-ed25519: f750f42b0430e28a2e272c3cedcae4dcc4a1cf33bc345c35099d3322626ab666
private-key-eth: 4d787714dcb0ae52e1c5d2144648c255d660b9a55eac9deeb80d9f506f501025
Parameters:

keyfile – Path (relative or absolute) to a public or private keys file.

Returns:

New instance of EthereumKey

classmethod from_seedphrase(seedphrase: str, index: int = 0) EthereumKey[source]

Create a private key from the given BIP-39 mnemonic seed phrase and index, which can be used to sign and create signatures.

Parameters:
  • seedphrase – The BIP-39 seedphrase (“Mnemonic”) from which to derive the account.

  • index – The account index in account hierarchy defined by the seedphrase.

Returns:

New instance of EthereumKey

property key_no: int | None

Implements autobahn.wamp.interfaces.IKey.key_no().

property key_type: str

Implements autobahn.wamp.interfaces.IKey.key_type().

public_key(binary: bool = False) str | bytes[source]

Implements autobahn.wamp.interfaces.IKey.public_key().

recover(data: bytes, signature: bytes) bytes[source]

Implements autobahn.wamp.interfaces.IKey.recover().

property security_module: ISecurityModule | None

Implements autobahn.wamp.interfaces.IKey.security_module().

sign(data: bytes) bytes[source]

Implements autobahn.wamp.interfaces.IKey.sign().

sign_typed_data(data: Dict[str, Any], binary=True) bytes[source]

Implements autobahn.wamp.interfaces.IEthereumKey.sign_typed_data().

verify_typed_data(data: Dict[str, Any], signature: bytes) bool[source]

Implements autobahn.wamp.interfaces.IEthereumKey.verify_typed_data().

class autobahn.xbr.FbsEnum(repository: FbsRepository, schema: FbsSchema, declaration_file: str, name: str, id: int, values: Dict[str, FbsEnumValue], values_by_id: List[FbsEnumValue], is_union: bool, underlying_type: int, attrs: Dict[str, FbsAttribute], docs: str)[source]

FlatBuffers enum type.

See https://github.com/google/flatbuffers/blob/11a19887053534c43f73e74786b46a615ecbf28e/reflection/reflection.fbs#L61

class autobahn.xbr.FbsRepository(basemodule: str)[source]
crossbar.interfaces.IInventory
  • add: FbsRepository[] - load: FbsSchema[]

https://github.com/google/flatbuffers/blob/master/reflection/reflection.fbs

load(filename: str) Tuple[int, int][source]

Load and add all schemata from Flatbuffers binary schema files (*.bfbs) found in the given directory. Alternatively, a path to a single schema file can be provided.

Parameters:

filename – Filesystem path of a directory or single file from which to load and add Flatbuffers schemata.

render(jinja2_env, output_dir, output_lang)[source]
Parameters:
  • jinja2_env

  • output_dir

  • output_lang

Returns:

validate(validation_type: str, args: List[Any], kwargs: Dict[str, Any]) FbsObject | None[source]

Validate the WAMP application payload provided in positional argument in args and in keyword-based arguments in kwargs against the FlatBuffers table type validation_type from this repository.

If the application payload does not validate against the provided type, an autobahn.wamp.exception.InvalidPayload is raised.

Parameters:
  • validation_type – Flatbuffers type (fully qualified) against to validate application payload.

  • args – The application payload WAMP positional arguments.

  • kwargs – The application payload WAMP keyword-based arguments.

Returns:

The validation type object from this repository (reference in validation_type) which has been used for validation.

validate_obj(validation_type: str | None, value: Any | None)[source]

Validate value against the validation type given.

If the application payload does not validate against the provided type, an autobahn.wamp.exception.InvalidPayload is raised.

Parameters:
  • validation_type – Flatbuffers type (fully qualified) against to validate application payload.

  • value – Value to validate.

Returns:

class autobahn.xbr.FbsSchema(repository: FbsRepository, file_name: str, file_sha256: str, file_size: int, file_ident: str, file_ext: str, fbs_files: List[Dict[str, str]], root_table: FbsObject, root: Schema, objs: Dict[str, FbsObject] | None = None, objs_by_id: List[FbsObject] | None = None, enums: Dict[str, FbsEnum] | None = None, enums_by_id: List[FbsEnum] | None = None, services: Dict[str, FbsService] | None = None, services_by_id: List[FbsService] | None = None)[source]
Parameters:
  • repository

  • file_name

  • file_sha256

  • file_size

  • file_ident

  • file_ext

  • fbs_files

  • root_table

  • root

  • objs

  • objs_by_id

  • enums

  • enums_by_id

  • services

  • services_by_id

static load(repository: FbsRepository, sfile: str | RawIOBase | IO[bytes], filename: str | None = None) FbsSchema[source]
Parameters:
  • repository

  • sfile

  • filename

Returns:

marshal() Dict[str, object][source]
Returns:

class autobahn.xbr.FbsType(repository: FbsRepository, schema: FbsSchema, basetype: int, element: int, index: int, objtype: str | None = None, elementtype: str | None = None)[source]

Flatbuffers type.

See: https://github.com/google/flatbuffers/blob/11a19887053534c43f73e74786b46a615ecbf28e/reflection/reflection.fbs#L33

property basetype: int

Flatbuffers base type.

Returns:

property element: int

Only if basetype == Vector

Returns:

property elementtype: str | None

If basetype == Vector, fully qualified element type name.

Returns:

property index: int

If basetype == Object, index into “objects”. If base_type == Union, UnionType, or integral derived from an enum, index into “enums”. If base_type == Vector && element == Union or UnionType.

Returns:

map(language: str, attrs: Dict | None = None, required: bool | None = True, objtype_as_string: bool = False) str[source]
Parameters:
  • language

  • attrs

  • required

  • objtype_as_string

Returns:

property objtype: str | None

If basetype == Object, fully qualified object type name.

Returns:

class autobahn.xbr.FederatedRealm(name_or_address: str, gateway_config: Dict[str, Any] | None = None)[source]

A federated realm is a WAMP application realm with a trust anchor rooted in Ethereum, and which can be shared between multiple parties.

A federated realm is globally identified on an Ethereum chain (e.g. on Mainnet or Rinkeby) by an Ethereum address associated to a federated realm owner by an on-chain record stored in the WAMP Network contract. The federated realm address thus only needs to exist as an identifier of the federated realm-owner record.

Instantiate a federated realm from a federated realm ENS name (which is resolved to an Ethereum address) or Ethereum address.

Parameters:
  • name_or_address – Ethereum ENS name or address.

  • gateway_config – If provided, use this Ethereum gateway. If not provided, connect via Infura to Ethereum Mainnet, which requires an environment variable WEB3_INFURA_PROJECT_ID with your Infura project ID.

initialize()[source]
Returns:

class autobahn.xbr.IBuyer[source]

XBR Buyer interface.

abstract async start(session)[source]

Start buying keys over the provided session.

Parameters:

session – WAMP session that allows to talk to the XBR Market Maker.

abstract async unwrap(key_id, enc_ser, ciphertext)[source]

Decrypt and deserialize received XBR payload.

Parameters:
  • key_id (bytes) – The ID of the datakey the payload is encrypted with.

  • enc_ser (str) – The serializer that was used for serializing the payload. One of cbor, json, msgpack, ubjson.

  • ciphertext (bytes) – The encrypted payload to unwrap.

Returns:

The unwrapped application payload.

Return type:

object

class autobahn.xbr.IConsumer[source]

XBR Consumer interface.

class autobahn.xbr.IDelegate[source]

XBR Delegate interface.

class autobahn.xbr.IMarketMaker[source]

XBR Market Maker interface.

abstract buy(channel_id, channel_seq, buyer_pubkey, datakey_id, amount, balance, signature, details)[source]
Parameters:
  • channel_id

  • channel_seq

  • buyer_pubkey

  • datakey_id

  • amount

  • balance

  • signature

  • details

Returns:

abstract get_payment_channel(channel_id, details)[source]
Parameters:
  • channel_id

  • details

Returns:

abstract get_payment_channels(address, details)[source]
Parameters:
  • address

  • details

Returns:

abstract offer(key_id, price, details)[source]
Parameters:
  • key_id

  • price

  • details

Returns:

abstract quote(key_id, details)[source]
Parameters:
  • key_id

  • details

Returns:

abstract revoke(key_id, details)[source]
Parameters:
  • key_id

  • details

Returns:

abstract status(details)[source]
Parameters:

details

Returns:

class autobahn.xbr.IProvider[source]

XBR Provider interface.

abstract sell(key_id, buyer_pubkey, amount_paid, post_balance, signature, details)[source]
Parameters:
  • key_id

  • buyer_pubkey

  • amount_paid

  • post_balance

  • signature

  • details

Returns:

class autobahn.xbr.ISeller[source]

XBR Seller interface.

abstract async start(session)[source]
Parameters:

session

Returns:

abstract async wrap(uri, payload)[source]
Parameters:
  • uri

  • payload

Returns:

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

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

Parameters:
  • api_id (bytes) – ID of the API for which to generate keys.

  • price (int) – Price per key in key series.

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

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

  • on_rotate (callable) – Optional user callback fired after key was rotated.

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

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

class autobahn.xbr.MemberLevel[source]

XBR Network member levels.

class autobahn.xbr.NodeType[source]

XBR Cloud node types.

class autobahn.xbr.Profile(path: str | None = None, name: str | None = None, member_adr: str | None = None, ethkey: bytes | None = None, cskey: bytes | None = None, username: str | None = None, email: str | None = None, network_url: str | None = None, network_realm: str | None = None, member_oid: UUID | None = None, vaction_oid: UUID | None = None, vaction_requested: datetime64 | None = None, vaction_verified: datetime64 | None = None, data_url: str | None = None, data_realm: str | None = None, infura_url: str | None = None, infura_network: str | None = None, infura_key: str | None = None, infura_secret: str | None = None)[source]

User profile, stored as named section in ${HOME}/.xbrnetwork/config.ini:

[default]
# username used with this profile
username=joedoe

# user email used with the profile (e.g. for verification emails)
email=joe.doe@example.com

# XBR network node used as a directory server and gateway to XBR smart contracts
network_url=ws://localhost:8090/ws

# WAMP realm on network node, usually "xbrnetwork"
network_realm=xbrnetwork

# user private WAMP-cryptosign key (for client authentication)
cskey=0xb18bbe88ca0e189689e99f87b19addfb179d46aab3d59ec5d93a15286b949eb6

# user private Ethereum key (for signing transactions and e2e data encryption)
ethkey=0xfbada363e724d4db2faa2eeaa7d7aca37637b1076dd8cf6fefde13983abaa2ef
Parameters:
  • path

  • name

  • member_adr

  • ethkey

  • cskey

  • username

  • email

  • network_url

  • network_realm

  • member_oid

  • vaction_oid

  • vaction_requested

  • vaction_verified

  • data_url

  • data_realm

  • infura_url

  • infura_network

  • infura_key

  • infura_secret

class autobahn.xbr.SecurityModuleMemory(keys: List[CryptosignKey | EthereumKey] | None = None)[source]

A transient, memory-based implementation of ISecurityModule.

property can_lock: bool

Implements ISecurityModule.can_lock()

close()[source]

Implements ISecurityModule.close()

classmethod from_config(config: str, profile: str = 'default') SecurityModuleMemory[source]

Create a new memory-backed security module with keys referred from a profile in the given configuration file.

Parameters:
  • config – Path (relative or absolute) to an INI configuration file.

  • profile – Name of the profile within the given INI configuration file.

Returns:

New memory-backed security module instance.

classmethod from_keyfile(keyfile: str) SecurityModuleMemory[source]

Create a new memory-backed security module with keys referred from a profile in the given configuration file.

Parameters:

keyfile – Path (relative or absolute) to a private keys file.

Returns:

New memory-backed security module instance.

classmethod from_seedphrase(seedphrase: str, num_eth_keys: int = 1, num_cs_keys: int = 1) SecurityModuleMemory[source]

Create a new memory-backed security module with

  1. num_eth_keys keys of type EthereumKey, followed by

  2. num_cs_keys keys of type CryptosignKey

computed from a (common) BIP44 seedphrase.

Parameters:
  • seedphrase – BIP44 seedphrase to use.

  • num_eth_keys – Number of Ethereum keys to derive.

  • num_cs_keys – Number of Cryptosign keys to derive.

Returns:

New memory-backed security module instance.

get_counter(counter_no: int) int[source]

Implements ISecurityModule.get_counter()

get_random(octets: int) bytes[source]

Implements ISecurityModule.get_random()

increment_counter(counter_no: int) int[source]

Implements ISecurityModule.increment_counter()

property is_locked: bool

Implements ISecurityModule.is_locked()

property is_open: bool

Implements ISecurityModule.is_open()

lock()[source]

Implements ISecurityModule.lock()

open()[source]

Implements ISecurityModule.open()

unlock()[source]

Implements ISecurityModule.unlock()

class autobahn.xbr.Seeder(frealm: FederatedRealm, operator: str | None = None, label: str | None = None, country: str | None = None, legal: str | None = None, endpoint: str | None = None, bandwidth_requested: int | None = None, bandwidth_offered: int | None = None)[source]
Parameters:
  • frealm

  • operator

  • label

  • country

  • legal

  • endpoint

  • bandwidth_requested

  • bandwidth_offered

property bandwidth_offered: int | None
Returns:

property bandwidth_requested: int | None
Returns:

property country: str | None

Operator country (ISO 3166-1 alpha-2), e.g. "US".

Returns:

ISO 3166-1 alpha-2 country code.

create_authextra(client_key: ICryptosignKey, delegate_key: IEthereumKey, bandwidth_requested: int, channel_id: bytes | None = None, channel_binding: str | None = None) Deferred[source]
Parameters:
  • client_key

  • delegate_key

  • bandwidth_requested

  • channel_id

  • channel_binding

Returns:

property endpoint: str | None

Public WAMP endpoint of seeder. Secure WebSocket URL resolving to a public IPv4 or IPv6 listening url accepting incoming WAMP-WebSocket connections, e.g. wss://service1.example.com/ws.

Returns:

The endpoint URL.

property frealm: FederatedRealm
Returns:

property label: str | None

Operator endpoint label.

Returns:

A human readable label for the operator or specific operator endpoint.

property legal: str | None
Returns:

property operator: str | None

Operator address, e.g. "0xe59C7418403CF1D973485B36660728a5f4A8fF9c".

Returns:

The Ethereum address of the endpoint operator.

class autobahn.xbr.SimpleBlockchain(gateway=None)[source]

Simple Ethereum blockchain XBR client.

Parameters:

gateway (str) – Optional explicit Ethereum gateway URL to use. If no explicit gateway is specified, let web3 auto-choose.

get_actor_status(delegate_adr)[source]
Parameters:

delegate_adr (bytes) –

Returns:

Return type:

dict

async get_balances(account_adr)[source]

Return current ETH and XBR balances of account with given address.

Parameters:

account_adr (bytes) – Ethereum address of account to get balances for.

Returns:

A dictionary with "ETH" and "XBR" keys and respective current on-chain balances as values.

Return type:

dict

get_channel_status(channel_adr)[source]
Parameters:

channel_adr (bytes) –

Returns:

Return type:

dict

get_contract_adrs()[source]

Get XBR smart contract addresses.

Returns:

A dictionary with "XBRToken" and "XBRNetwork" keys and Ethereum contract addresses as values.

Return type:

dict

get_delegate_status(delegate_adr)[source]
Parameters:

delegate_adr (bytes) –

Returns:

Return type:

dict

async get_domain_status(domain_id)[source]
Parameters:

domain_id (bytes) –

Returns:

Return type:

dict

async get_market_status(market_id)[source]
Parameters:

market_id

Returns:

async get_member_status(member_adr)[source]
Parameters:

member_adr (bytes) –

Returns:

Return type:

dict

get_node_status(delegate_adr)[source]
Parameters:

delegate_adr (bytes) –

Returns:

Return type:

dict

start()[source]

Start the blockchain client using the configured blockchain gateway.

stop()[source]

Stop the blockchain client.

class autobahn.xbr.SimpleBuyer(market_maker_adr, buyer_key, max_price)[source]

Simple XBR buyer component. This component can be used by a XBR buyer delegate to handle the automated buying of data encryption keys from the XBR market maker.

Parameters:
  • market_maker_adr

  • buyer_key (bytes) – Consumer delegate (buyer) private Ethereum key.

  • max_price (int) – Maximum price we are willing to buy per key.

async balance()[source]

Return current balance of payment channel:

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

  • remaining: The remaining amount of XBR in the payment channel that can be spent.

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

Returns:

Current payment balance.

Return type:

dict

async close_channel(details=None)[source]

Requests to close the currently active payment channel.

Returns:

count_transactions()[source]
Returns:

get_transaction(key_id)[source]
Parameters:

key_id

Returns:

is_complete(key_id)[source]
Parameters:

key_id

Returns:

async open_channel(buyer_addr, amount, details=None)[source]
Parameters:
  • amount

  • details

Returns:

Return type:

past_transactions(filter_complete=True, limit=1)[source]
Parameters:
  • filter_complete

  • limit

Returns:

async start(session, consumer_id)[source]

Start buying keys to decrypt XBR data by calling unwrap().

Parameters:
Returns:

Current remaining balance in payment channel.

Return type:

int

async stop()[source]

Stop buying keys.

async unwrap(key_id, serializer, ciphertext)[source]

Decrypt XBR data. This functions will potentially make the buyer call the XBR market maker to buy data encryption keys from the XBR provider.

Parameters:
  • key_id (bytes) – ID of the data encryption used for decryption of application payload.

  • serializer (str) – Application payload serializer.

  • ciphertext (bytes) – Ciphertext of encrypted application payload to decrypt.

Returns:

Decrypted application payload.

Return type:

object

class autobahn.xbr.UserConfig(config_path)[source]

Local user configuration file. The data is either a plain text (unencrypted) .ini file, or such a file encrypted with XSalsa20-Poly1305, and with a binary file header of 48 octets.

Parameters:

config_path – The user configuration file path.

property config_path: List[str]

Return the path to the user configuration file exposed by this object.,

Returns:

Local filesystem path.

load(cb_get_password=None) List[str][source]

Load this object from the underlying user configuration file. When the file is encrypted, call back into cb_get_password to get the user password.

Parameters:

cb_get_password – Callback called when password is needed.

Returns:

List of profiles loaded.

property profiles: Dict[str, object]

Access to a map of user profiles in this user configuration.

Returns:

Map of user profiles.

save(password: str | None = None)[source]

Save this user configuration to the underlying configuration file. The user configuration file can be encrypted using Argon2id when a password is given.

Parameters:

password – The optional Argon2id password.

Returns:

Number of octets written to the user configuration file.

autobahn.xbr.account_from_seedphrase(seedphrase: str, index: int = 0) Account[source]

Create an account from the given BIP-39 mnemonic seed phrase.

Parameters:
  • seedphrase – The BIP-39 seedphrase from which to derive the account.

  • index – The account index in account hierarchy defined by the seedphrase.

Returns:

The new Eth account object

autobahn.xbr.check_seedphrase(seedphrase: str, language: str = 'english')[source]

Check a BIP-39 mnemonic seed phrase.

Parameters:
  • seedphrase – The BIP-39 seedphrase from which to derive the account.

  • language – The BIP-39 user language to generate the seedphrase for.

Returns:

autobahn.xbr.create_eip712_authority_certificate(chainId: int, verifyingContract: bytes, validFrom: int, issuer: bytes, subject: bytes, realm: bytes, capabilities: int, meta: str) dict[source]

Authority certificate: long-lived, on-chain L2.

Parameters:
  • chainId

  • verifyingContract

  • validFrom

  • issuer

  • subject

  • realm

  • capabilities

  • meta

Returns:

autobahn.xbr.create_eip712_delegate_certificate(chainId: int, verifyingContract: bytes, validFrom: int, delegate: bytes, csPubKey: bytes, bootedAt: int, meta: str) dict[source]

Delegate certificate: dynamic/one-time, off-chain.

Parameters:
  • chainId

  • verifyingContract

  • validFrom

  • delegate

  • csPubKey

  • bootedAt

  • meta

Returns:

autobahn.xbr.expand_argon2_secret(pkm: bytes, context: bytes, salt: bytes | None = None) bytes[source]

Expand pkm and context into a key of length bytes using HKDF’s expand function based on HMAC SHA-512). See the HKDF draft RFC and paper for usage notes.

Parameters:
  • pkm

  • context

  • salt

Returns:

autobahn.xbr.generate_seedphrase(strength=128, language='english') str[source]

Generate a new BIP-39 mnemonic seed phrase for use in Ethereum (Metamask, etc).

See: * https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki * https://github.com/trezor/python-mnemonic

Parameters:

strength – Strength of seed phrase in bits, one of the following [128, 160, 192, 224, 256], generating seed phrase of 12 - 24 words inlength.

Returns:

Newly generated seed phrase (in english).

autobahn.xbr.is_address(provided: Any) bool[source]

Check if the value is a proper Ethereum address.

Parameters:

provided – The value to check.

Returns:

True iff the value is of correct type.

autobahn.xbr.is_block_number(provided: Any) bool[source]

Check if the value is a proper Ethereum block number.

Parameters:

provided – The value to check.

Returns:

True iff the value is of correct type.

autobahn.xbr.is_bytes16(provided: Any) bool[source]

Check if the value is a proper (binary) UUID.

Parameters:

provided – The value to check.

Returns:

True iff the value is of correct type.

autobahn.xbr.is_chain_id(provided: Any) bool[source]

Check if the value is a proper Ethereum chain ID.

Parameters:

provided – The value to check.

Returns:

True iff the value is of correct type.

autobahn.xbr.is_cs_pubkey(provided: Any) bool[source]

Check if the value is a proper WAMP-cryptosign public key.

Parameters:

provided – The value to check.

Returns:

True iff the value is of correct type.

autobahn.xbr.is_eth_privkey(provided: Any) bool[source]

Check if the value is a proper Ethereum private key (seed).

Parameters:

provided – The value to check.

Returns:

True iff the value is of correct type.

autobahn.xbr.is_signature(provided: Any) bool[source]

Check if the value is a proper Ethereum signature.

Parameters:

provided – The value to check.

Returns:

True iff the value is of correct type.

autobahn.xbr.make_w3(gateway_config=None)[source]

Create a Web3 instance configured and ready-to-use gateway to the blockchain.

Parameters:

gateway_config (dict) – Blockchain gateway configuration.

Returns:

Configured Web3 instance.

Return type:

web3.Web3

autobahn.xbr.parse_certificate_chain(certificates: List[Tuple[Dict[str, Any], str]]) List[EIP712DelegateCertificate | EIP712AuthorityCertificate][source]
Parameters:

certificates

Returns:

autobahn.xbr.pkm_from_argon2_secret(email: str, password: str, context: str, salt: bytes | None = None) bytes[source]
Parameters:
  • email

  • password

  • context

  • salt

Returns:

autobahn.xbr.recover_eip712_api_publish(chainId: int, verifyingContract: bytes, member: bytes, published: int, catalogId: bytes, apiId: bytes, schema: str, meta: str | None, signature: bytes) bytes[source]

Recover the signer address the given EIP712 signature was signed with.

Returns:

The (computed) signer address the signature was signed with.

Return type:

bytes

autobahn.xbr.recover_eip712_authority_certificate(chainId: int, verifyingContract: bytes, validFrom: int, issuer: bytes, subject: bytes, realm: bytes, capabilities: int, meta: str, signature: bytes) bytes[source]

Recover the signer address the given EIP712 signature was signed with.

Parameters:
  • chainId

  • verifyingContract

  • validFrom

  • issuer

  • subject

  • realm

  • capabilities

  • meta

  • signature

Returns:

The (computed) signer address the signature was signed with.

autobahn.xbr.recover_eip712_catalog_create(chainId: int, verifyingContract: bytes, member: bytes, created: int, catalogId: bytes, terms: str, meta: str | None, signature: bytes) bytes[source]

Recover the signer address the given EIP712 signature was signed with.

Returns:

The (computed) signer address the signature was signed with.

Return type:

bytes

autobahn.xbr.recover_eip712_channel_close(chainId: int, verifyingContract: bytes, closeAt: int, marketId: bytes, channelId: bytes, channelSeq: int, balance: int, isFinal: bool, signature: bytes) bytes[source]

Recover the signer address the given EIP712 signature was signed with.

Returns:

The (computed) signer address the signature was signed with.

Return type:

bytes

autobahn.xbr.recover_eip712_channel_open(chainId: int, verifyingContract: bytes, ctype: int, openedAt: int, marketId: bytes, channelId: bytes, actor: bytes, delegate: bytes, marketmaker: bytes, recipient: bytes, amount: int, signature: bytes) bytes[source]

Recover the signer address the given EIP712 signature was signed with.

Returns:

The (computed) signer address the signature was signed with.

Return type:

bytes

Recover the signer address the given EIP712 signature was signed with.

Returns:

The (computed) signer address the signature was signed with.

Return type:

bytes

autobahn.xbr.recover_eip712_delegate_certificate(chainId: int, verifyingContract: bytes, validFrom: int, delegate: bytes, csPubKey: bytes, bootedAt: int, meta: str, signature: bytes) bytes[source]

Recover the signer address the given EIP712 signature was signed with.

Parameters:
  • chainId

  • verifyingContract

  • validFrom

  • delegate

  • csPubKey

  • bootedAt

  • signature

  • meta

Returns:

The (computed) signer address the signature was signed with.

autobahn.xbr.recover_eip712_market_create(chainId: int, verifyingContract: bytes, member: bytes, created: int, marketId: bytes, coin: bytes, terms: str, meta: str, maker: bytes, providerSecurity: int, consumerSecurity: int, marketFee: int, signature: bytes) bytes[source]

Recover the signer address the given EIP712 signature was signed with.

Returns:

The (computed) signer address the signature was signed with.

Return type:

bytes

autobahn.xbr.recover_eip712_market_join(chainId: int, verifyingContract: bytes, member: bytes, joined: int, marketId: bytes, actorType: int, meta: str, signature: bytes) bytes[source]

Recover the signer address the given EIP712 signature was signed with.

Returns:

The (computed) signer address the signature was signed with.

Return type:

bytes

autobahn.xbr.recover_eip712_member_login(chainId: int, verifyingContract: bytes, member: bytes, loggedIn: int, timestamp: int, member_email: str, client_pubkey: bytes, signature: bytes) bytes[source]

Recover the signer address the given EIP712 signature was signed with.

Returns:

The (computed) signer address the signature was signed with.

Return type:

bytes

autobahn.xbr.recover_eip712_member_register(chainId: int, verifyingContract: bytes, member: bytes, registered: int, eula: str, profile: str | None, signature: bytes) bytes[source]

Recover the signer address the given EIP712 signature was signed with.

Returns:

The (computed) signer address the signature was signed with.

Return type:

bytes

autobahn.xbr.setProvider(_w3)[source]

The XBR library must be initialized (once) first by setting the Web3 provider using this function.

autobahn.xbr.sign_eip712_api_publish(eth_privkey: bytes, chainId: int, verifyingContract: bytes, member: bytes, published: int, catalogId: bytes, apiId: bytes, schema: str, meta: str | None) bytes[source]
Parameters:

eth_privkey (bytes) – Ethereum address of buyer (a raw 20 bytes Ethereum address).

Returns:

The signature according to EIP712 (32+32+1 raw bytes).

Return type:

bytes

autobahn.xbr.sign_eip712_authority_certificate(eth_privkey: bytes, chainId: int, verifyingContract: bytes, validFrom: int, issuer: bytes, subject: bytes, realm: bytes, capabilities: int, meta: str) bytes[source]

Sign the given data using a EIP712 based signature with the provided private key.

Parameters:
  • eth_privkey

  • chainId

  • verifyingContract

  • validFrom

  • issuer

  • subject

  • realm

  • capabilities

  • meta

Returns:

autobahn.xbr.sign_eip712_catalog_create(eth_privkey: bytes, chainId: int, verifyingContract: bytes, member: bytes, created: int, catalogId: bytes, terms: str, meta: str | None) bytes[source]
Parameters:

eth_privkey (bytes) – Ethereum address of buyer (a raw 20 bytes Ethereum address).

Returns:

The signature according to EIP712 (32+32+1 raw bytes).

Return type:

bytes

autobahn.xbr.sign_eip712_channel_close(eth_privkey: bytes, chainId: int, verifyingContract: bytes, closeAt: int, marketId: bytes, channelId: bytes, channelSeq: int, balance: int, isFinal: bool) bytes[source]
Parameters:

eth_privkey (bytes) – Ethereum address of buyer (a raw 20 bytes Ethereum address).

Returns:

The signature according to EIP712 (32+32+1 raw bytes).

Return type:

bytes

autobahn.xbr.sign_eip712_channel_open(eth_privkey: bytes, chainId: int, verifyingContract: bytes, ctype: int, openedAt: int, marketId: bytes, channelId: bytes, actor: bytes, delegate: bytes, marketmaker: bytes, recipient: bytes, amount: int) bytes[source]
Parameters:

eth_privkey (bytes) – Ethereum address of buyer (a raw 20 bytes Ethereum address).

Returns:

The signature according to EIP712 (32+32+1 raw bytes).

Return type:

bytes

Parameters:

eth_privkey (bytes) – Ethereum address of buyer (a raw 20 bytes Ethereum address).

Returns:

The signature according to EIP712 (32+32+1 raw bytes).

Return type:

bytes

autobahn.xbr.sign_eip712_delegate_certificate(eth_privkey: bytes, chainId: int, verifyingContract: bytes, validFrom: int, delegate: bytes, csPubKey: bytes, bootedAt: int, meta: str) bytes[source]

Sign the given data using a EIP712 based signature with the provided private key.

Parameters:
  • eth_privkey – Signing key.

  • chainId

  • verifyingContract

  • validFrom

  • delegate

  • csPubKey

  • bootedAt

  • meta

Returns:

The signature according to EIP712 (32+32+1 raw bytes).

autobahn.xbr.sign_eip712_market_create(eth_privkey: bytes, chainId: int, verifyingContract: bytes, member: bytes, created: int, marketId: bytes, coin: bytes, terms: str, meta: str, maker: bytes, providerSecurity: int, consumerSecurity: int, marketFee: int) bytes[source]
Parameters:

eth_privkey (bytes) – Ethereum address of buyer (a raw 20 bytes Ethereum address).

Returns:

The signature according to EIP712 (32+32+1 raw bytes).

Return type:

bytes

autobahn.xbr.sign_eip712_market_join(eth_privkey: bytes, chainId: int, verifyingContract: bytes, member: bytes, joined: int, marketId: bytes, actorType: int, meta: str) bytes[source]
Parameters:

eth_privkey (bytes) – Ethereum address of buyer (a raw 20 bytes Ethereum address).

Returns:

The signature according to EIP712 (32+32+1 raw bytes).

Return type:

bytes

autobahn.xbr.sign_eip712_member_login(eth_privkey: bytes, chainId: int, verifyingContract: bytes, member: bytes, loggedIn: int, timestamp: int, member_email: str, client_pubkey: bytes) bytes[source]
Parameters:

eth_privkey (bytes) – Ethereum address of buyer (a raw 20 bytes Ethereum address).

Returns:

The signature according to EIP712 (32+32+1 raw bytes).

Return type:

bytes

autobahn.xbr.sign_eip712_member_register(eth_privkey: bytes, chainId: int, verifyingContract: bytes, member: bytes, registered: int, eula: str | None, profile: str) bytes[source]
Parameters:

eth_privkey (bytes) – Ethereum address of buyer (a raw 20 bytes Ethereum address).

Returns:

The signature according to EIP712 (32+32+1 raw bytes).

Return type:

bytes

autobahn.xbr.stretch_argon2_secret(email: str, password: str, salt: bytes | None = None) bytes[source]

Compute argon2id based secret from user email and password only. This uses Argon2id for stretching a potentially weak user password/PIN and subsequent HKDF based key extending to derive private key material (PKM) for different usage contexts.

The Argon2 parameters used are the following:

  • kdf argon2id-13

  • time cost 4096

  • memory cost 512

  • parallelism 1

See draft-irtf-cfrg-argon2 and argon2-cffi.

Parameters:
  • email – User email.

  • password – User password.

  • salt – Optional salt to use (must be 16 bytes long). If none is given, compute salt from email as salt = SHA256(email)[:16].

Returns:

The computed private key material (256b, 32 octets).

autobahn.xbr.xbrcatalog = None

Contract instance of XBRMarket.

autobahn.xbr.xbrchannel = None

Contract instance of XBRMarket.

autobahn.xbr.xbrmarket = None

Contract instance of XBRMarket.

autobahn.xbr.xbrnetwork = None

Contract instance of XBRNetwork.

autobahn.xbr.xbrtoken = None

Contract instance of XBRToken.