Crate farcaster_core

source ·
Expand description

Farcaster core library aims to implement in Rust the core principles described in Farcaster RFCs:

  • Swap deals: data needed to start a swap with a counter-party
  • Swap roles and trade roles: who does what in the protocol
  • Transaction templates implementing on-chain behaviours
  • Signature and cryptographic utilities
    • ECDSA adaptor signatures
    • Cross-group discrete logarithm proof system
    • Schnorr adaptor signature [work in progress]

Core framework

This library is twofold: providing a flexible framework to add specific blockchain support and implementing these specific blockchains. The framework is accessible in all modules at the root of the crate. The blockchains support are added under the the following modules:

  • bitcoin: support for Bitcoin, implementation of the Arbitrating blockchain role.
  • monero: support for Monero, implementation of the Accordant blockchain role.
  • swap/btcxmr: definition of a swap between bitcoin and monero implementations.

Adding blockchain support

To add a blockchain implementation you must implements the Aribtrating or Accordant role requirements on your blockchain. That depends on its blockchain on-chain features, see RFCs for more details.

The protocol is executed with protocol::Alice and protocol::Bob structures, each implement a list of generic functions that allow performing one step in the protocol execution. Adding support for a chain means having the correct types to run those functions.

For an arbitrating implementation on-chain transactions are required, the trait Transactions allow defining the set of transaction to build and use during the swap execution.

Features

As default the experimental feature is enable.

  • experimental: enable experimental cryptography, i.e. not battle tested nor peer reviewed, use it at your own risks.
  • taproot: enable support for Bitcoin Taproot on-chain scripts as the arbitrating engine method.

Modules

Implementation for the Bitcoin blockchain as an arbitrating blockchain in a swap, with multiple strategies (ECDSA, Taproot, Taproot+MuSig2).
Defines types used to characterize a swap and behaviours a blockchain must implement to participate in a swap, either as an arbitrating or an accordant blockchain.
Farcaster consensus encoding used to strictly encode and decode data such as a deal: a data structure exchanged between swap participants during their trade setup.
Cryptographic types (keys, signatures, commitments, etc) and traits (commit, generate key, sign, etc) used to create the generic framework for supporting multiple blockchains under the same interface.
Implementation of the Monero blockchain as an accordant blockchain in a swap. This implementation should work in pair with any other arbitrating implementation, like Bitcoin.
Protocol execution and messages exchanged between peers. Execution steps of a swap are carried by Alice and Bob structures. Each contain the list of methods needed to proceed a swap.
Roles used to distinguish participants and blockchains during trade setup and swap phase. Defines the trading roles and swap roles distributed among participants and blockchain roles implemented on Bitcoin, Monero, etc.
Data structures used in scripts to create the arbitration engine on a blockchain.
Defines the high level of a swap between a Arbitrating blockchain and a Accordant blockchain and its concrete instances of swaps.
Trade structures. Buyer and seller use deals to communicate parameters of a swap.
Arbitrating transaction traits used as the on-chain arbitration engine on the arbitrating blockchain. These traits define the steps allowed in the arbitration engine enforced on-chain.

Macros

Implement strict encoding by wrapping the de/serialization of consensus encoding.
Helper that deserialize a consensus encoded byte vector.

Structs

A unique identifier used to identify trades and swaps.

Enums

A list of possible errors when performing a cross-chain atomic swap with the Farcaster software stack. Each error can have multiple level down to the blockchain implementation.

Type Definitions

Result of an high level computation such as in Alice and Bob roles executing the protocol, wraps the crate level Error type.