Skip to content

Commit

Permalink
mostly readme updates
Browse files Browse the repository at this point in the history
  • Loading branch information
RCasatta committed Apr 18, 2020
1 parent fdc92cb commit a073527
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 112 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Firma [![Build Status]][travis]

[Build Status]: https://travis-ci.com/RCasatta/firma.svg?branch=master
[travis]: https://travis-ci.com/github/RCasatta/firma

**WARNING - Early stage software, do not use with real bitcoins.**

Firma is a tool to create bitcoin multisig wallet with private keys stored on offline machines.
The offline machine could be [CLI](bin) terminal or a spare [android](android) phone.
Informations are transferred between devices through QR codes, since PSBT could become large some kB, more than 1 qr code could be needed, those QRs are chained with qr [structured append](https://segno.readthedocs.io/en/stable/structured-append.html)

It is based on:
* [bitcoin core](https://bitcoincore.org/)
* [psbt](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki) (Partially Signed Bitcoin Transaction)
* [rust-bitcoin](https://github.com/rust-bitcoin/rust-bitcoin)

## High level process:

```
+---------------------+
+---------------------+ |+---------------------+
| | xpubs || |
| online machine | <------------ || offline machines |
| | || |
| * firma-online | PSBT || * firma-offline |
| * bitcoin node | ------------> || * xprv |
| * xpubs | <------------ || |
| | +| |
+---------------------+ +---------------------+
```

#### Setup

* Create one ore more extended private keys `xprv` on one or more offline devices.
* Group together corresponding extended public keys `xpub` and import these on a (on-line) Bitcoin core node in watch-only mode.
* Bring back the wallet descriptor with `xpubs` on offline machines. While not strictly necessary for signing, wallet on offline machine act as a backup and as added information (eg check if a change is owned by the wallet)

#### Usage

##### Receiving

* `firma-online` tool could create addresses to receive bitcoins.

##### Spending

* Create the transaction from the `firma-online` tool and export it in PSBT format.
* Bring PSBT to offline devices, check the transaction, if everything looks correct, sign the PSBT with the private key present on the device.
* Bring all the PSBT back to the node which can combine and finalize these as complete transaction (this operation could occur in parallel or serially).

## Requirements

You need [Bitcoin core 0.19.1](https://bitcoincore.org/)

To build executables you need [rust](https://www.rust-lang.org/).

```
git clone https://github.com/RCasatta/firma/
cd firma
cargo build --release
export PATH=$PATH:$PWD/target/release/
```

## Tests

Integration tests require an env var pointing to bitcoin core executable (`bitcoind`).

For example:

```
BITCOIN_EXE_DIR=./bitcoin-0.19.1/bin cargo test
```

## Example

Check the bin [readme](bin/README.md) for an example with CLI

## Donations

I am the maintainer of one of the OpenTimestamps calendar, you can donate [there](https://finney.calendar.eternitywall.com/) (onchain or lightning) if you want to support this work.
18 changes: 18 additions & 0 deletions android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Android



## Building

To build the android app you need the rust lib built with the android [ndk](https://developer.android.com/ndk).

For the emulator, modify the `build-android.sh` file to fit your system. Then launch the build.

```
cd lib
./build-android.sh
```

The script copy the file in the directory `android/app/src/main/jniLibs/x86/`

At this point you should be able to launch the android app in the emulator, for using the app in the android phone you will need to launch also `build-android-release.sh`.
12 changes: 8 additions & 4 deletions android/app/src/main/java/it/casatta/PSBTActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import it.casatta.ListActivity.Companion.network
import kotlinx.android.synthetic.main.activity_psbt.*
import java.io.File
import java.io.Serializable
import java.util.*
import kotlin.collections.ArrayList


class PSBTActivity : AppCompatActivity() {
Expand Down Expand Up @@ -86,11 +88,13 @@ class PSBTActivity : AppCompatActivity() {
if (!info.isEmpty()) {
itemsAdapter.list.add(DescItem("Info", info))
}
itemsAdapter.list.add(DescItem("Fee", psbtPretty.fee.absolute.toString()))
itemsAdapter.list.add(DescItem("Fee rate", psbtPretty.fee.rate.toString()))
itemsAdapter.list.add(DescItem("Estimated size", psbtPretty.size.estimated.toString()))
itemsAdapter.list.add(DescItem("Unsigned size", psbtPretty.size.unsigned.toString()))
val formattedRate = String.format(Locale.US, "%.2f sat/vB", psbtPretty.fee.rate) ;
itemsAdapter.list.add(DescItem("Fee", psbtPretty.fee.absolute_fmt))
itemsAdapter.list.add(DescItem("Fee rate", formattedRate))
itemsAdapter.list.add(DescItem("Balances", psbtPretty.balances))
itemsAdapter.list.add(DescItem("Estimated size", "${psbtPretty.size.estimated} bytes"))
itemsAdapter.list.add(DescItem("Unsigned size", "${psbtPretty.size.unsigned} bytes"))
itemsAdapter.list.add(DescItem("PSBT size", "${psbtPretty.size.psbt} bytes"))
itemsAdapter.list.add(DescItem("PSBT", psbtJson.psbt.psbt))

}
Expand Down
4 changes: 3 additions & 1 deletion android/app/src/main/java/it/casatta/Rust.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ class Rust {

data class Size (
val unsigned: Int,
val estimated: Int
val estimated: Int,
val psbt: Int
)

data class Fee (
val absolute_fmt: String,
val absolute: Long,
val rate : Double
)
Expand Down
2 changes: 1 addition & 1 deletion bin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "firma-bin"
version = "0.1.0"
version = "0.2.0"
authors = ["Riccardo Casatta <[email protected]>"]
edition = "2018"

Expand Down
69 changes: 1 addition & 68 deletions lib/README.md → bin/README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,5 @@
# Firma [![Build Status]][travis]

[Build Status]: https://travis-ci.com/RCasatta/firma.svg?branch=master
[travis]: https://travis-ci.com/github/RCasatta/firma

**WARNING - Early stage software, do not use with real bitcoins.**

Firma is a tool to create bitcoin multisig wallet with private keys stored on offline machines.

It is based on:
* [bitcoin core](https://bitcoincore.org/)
* [psbt](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki) (Partially Signed Bitcoin Transaction)
* [rust-bitcoin](https://github.com/rust-bitcoin/rust-bitcoin)

## High level process:

```
+---------------------+
+---------------------+ |+---------------------+
| | xpubs || |
| online machine | <------------ || offline machines |
| | || |
| * firma-online | PSBT || * firma-offline |
| * bitcoin node | ------------> || * xprv |
| * xpubs | <------------ || |
| | +| |
+---------------------+ +---------------------+
```


#### Setup

* Create one ore more extended private keys `xprv` on one or more offline devices.
* Group together corresponding extended public keys `xpub` and import these on a (on-line) Bitcoin core node in watch-only mode.

#### Usage

##### Receiving

* The Bitcoin core node could create addresses to receive bitcoins.

##### Spending

* Create the transaction from the Bitcoin core node and export it in PSBT format.
* Bring PSBT to offline devices, check the transaction, if everything looks correct, sign the PSBT with the `xprv`.
* Bring all the PSBT back to the node which can combine and finalize these as complete transaction.

## Requirements

You need [Bitcoin core 0.19.1](https://bitcoincore.org/)

To build executables you need [rust](https://www.rust-lang.org/).

```
git clone https://github.com/RCasatta/firma/
cd firma
cargo build --release
export PATH=$PATH:$PWD/target/release/
```

## Tests

Integration tests require an env var pointing to bitcoin core executables (`bitcoin-cli` and `bitcoind`).

For example:

```
BITCOIN_EXE_DIR=./bitcoin-0.19.1/bin cargo test
```
NOTE: written for firma 0.1.0 some command and/or output could be slightly different

# Creating a 2of2 multisig wallet p2wsh

Expand Down
1 change: 0 additions & 1 deletion bin/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ fn integration_test() {
client_default.stop().unwrap();
let ecode = bitcoind.wait().unwrap();
assert!(ecode.success());
thread::sleep(Duration::from_secs(1000));
}

struct FirmaCommand {
Expand Down
4 changes: 2 additions & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "firma"
version = "0.1.0"
version = "0.2.0"
authors = ["Riccardo Casatta <[email protected]>"]
edition = "2018"
#rust = "1.42"
Expand All @@ -11,7 +11,7 @@ bitcoin = "0.23.0"
bitcoincore-rpc = "0.10.0"
base64 = "0.12.0"
num-bigint = "0.2.6"
#qrcode = "0.12.0"
#qrcode = "0.12.0" # https://github.com/kennytm/qrcode-rust/pull/44
qrcode = { git = "https://github.com/RCasatta/qrcode-rust/", branch="append" }
structopt = "0.3.12"
log = "0.4.8"
Expand Down
30 changes: 0 additions & 30 deletions lib/build-android-arm32.sh

This file was deleted.

17 changes: 14 additions & 3 deletions lib/build-android-release.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
export NDK_HOME=$HOME/android-ndk-r21
export PATH=$PATH:$NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin
export CC_aarch64_linux_android=aarch64-linux-android21-clang
# configure this according to you system and your target
export NDK=$HOME/android-ndk-r21
export TARGET=i686-linux-android
export API=16
export HOST=darwin-x86_64
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$HOST
##### end configure

export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export LD=$TOOLCHAIN/bin/$TARGET-ld
export RANLIB=$TOOLCHAIN/bin/$TARGET-ranlib
export STRIP=$TOOLCHAIN/bin/$TARGET-strip
export AR=$TOOLCHAIN/bin/$TARGET-ar
export AS=$TOOLCHAIN/bin/$TARGET-as

cargo build --release --target aarch64-linux-android
cp ../target/aarch64-linux-android/release/libfirma.so ../android/app/src/main/jniLibs/arm64-v8a/
1 change: 1 addition & 0 deletions lib/build-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export NDK=$HOME/android-ndk-r21
export TARGET=i686-linux-android
export API=16
export HOST=darwin-x86_64
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$HOST
##### end configure

Expand Down

0 comments on commit a073527

Please sign in to comment.