Build Status unsafe forbidden Crates.io Documentation License: LGPL v3 MSRV

Farcaster Core Library

:warning: This library is a :construction: work in progress :construction: and does not implement everything yet, nor is suitable for production use.

The Farcaster atomic swaps project core library aim to implement in Rust the following functionnalities needed to build a swap node:

Documentation

Currently can be found on docs.rs/farcaster_core. All possible improvments, to add usage examples and to expand on existing docs would be extremely appreciated.

Core framework

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

The blockchain specific support is added under the the following modules:

Features

As default the experimental feature is enable.

Adding blockchain support

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

To add support for Bitcoin we implement the Arbitrating trait on our definition of Bitcoin. The implementation contains a strategy allowing variations in SegWit versions or with cryptographic protocols. An experimental feature include SegwitV0 implementation that supports ECDSA for SegWit v0.

```rust

[derive(Clone, Debug, Copy, Eq, PartialEq)]

pub struct Bitcoin { ... };

[derive(Clone, Debug, Copy, Eq, PartialEq)]

pub struct SegwitV0;

impl Strategy for SegwitV0 {}

impl Arbitrating for Bitcoin {} ```

The implementation of Arbitrating is void but requires a list of other traits (see src/role.rs):

rust pub trait Arbitrating: Asset + Address + Fee + Keys + Onchain + Signatures + Timelock + Transactions + SharedPrivateKeys + ... { }

By implementing all the required traits on our Bitcoin definition we associate external concrete types used later in the framework logic.

```rust impl blockchain::Asset for Bitcoin { /// Type for the traded asset unit for a blockchain. type AssetUnit = bitcoin::Amount;

...

}

impl blockchain::Address for Bitcoin { /// Defines the address format for the arbitrating blockchain type Address = bitcoin::Address; }

impl blockchain::Timelock for Bitcoin { /// Defines the type of timelock used for the arbitrating transactions type Timelock = bitcoin::timelock::CSVTimelock; } ```

Some traits only associate types, some carry more logic such as Keys in crypto module that defines the type of keys (public and private) and the number of extra keys needed during the swap. This is useful when off-chain cryptographic protocols such as MuSig2 is used in the implementation and requires extra keys, e.g. nonces.

```rust impl crypto::Keys for Bitcoin { /// Private key type for the blockchain type PrivateKey = bitcoin::PrivateKey;

/// Public key type for the blockchain
type PublicKey = bitcoin::PublicKey;

fn extra_keys() -> Vec<u16> {
    // No extra key
    vec![]
}

} ```

For an arbitrating implementation transactions are required through Onchain and Transactions traits, former associate types for partial and final transaction and latter give concrete implementation for every type of transaction.

```rust impl blockchain::Onchain for Bitcoin { /// Defines the transaction format used to transfer partial transaction between participant for /// the arbitrating blockchain type PartialTransaction = bitcoin::PartiallySignedTransaction;

/// Defines the finalized transaction format for the arbitrating blockchain
type Transaction = bitcoin::Transaction;

}

impl blockchain::Transactions for Bitcoin { type Metadata = transaction::MetadataOutput;

type Funding = Funding;
type Lock = Tx<Lock>;
type Buy = Tx<Buy>;
type Cancel = Tx<Cancel>;
type Refund = Tx<Refund>;
type Punish = Tx<Punish>;

} ```

Releases and Changelog

See CHANGELOG.md and RELEASING.md.

About

This work is part of the Farcaster cross-chain atomic swap project, see Farcaster Project.

Licensing

The code in this project is licensed under the LGPL-3.0 License