Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/triska/bitcoinolog

Reason about Bitcoin addresses with Prolog
https://github.com/triska/bitcoinolog

bitcoin bitcoin-wallet cryptocurrency elliptic-curves offline-capable prolog

Last synced: about 1 month ago
JSON representation

Reason about Bitcoin addresses with Prolog

Awesome Lists containing this project

README

        

# Bitcoinolog: Reason about Bitcoin addresses with Prolog

## Offline Bitcoin wallet creation

*Bitcoinolog* uses [Prolog](https://www.metalevel.at/prolog) and the
[`crrl`](https://github.com/pornin/crrl/) crate to create Bitcoin
addresses and private keys with several nice properties:

- generated keys are **cryptographically secure** to the extent that
`crrl` guarantees this property
- the Prolog code is **short** and uses **no external programs**
- keys can be generated **offline**, on a machine that has no
Internet connection.

Bitcoinolog requires Scryer Prolog.

To try it, download [**`bitcoinolog.pl`**](bitcoinolog.pl)
and run:

$ scryer-prolog bitcoinolog.pl

Here is an example query that you can try:

?- repeat,
new_private_key(PrivateKey),
private_key_to_public_key(PrivateKey, PublicKey),
public_key_to_address(PublicKey, Address),
private_key_to_wif(PrivateKey, WIF),
format:portray_clause((address_key(A, K) :- A=Address, K=WIF)),
false.

This Prolog query *generates* Bitcoin addresses and private keys
in Wallet Import Format (WIF), yielding:

address_key(A, B) :-
A="1Nis7V58Mb839kXb9RZMDzAN6ZTQbNfGC4",
B="L1T3AnvHDtaAhkr9zxKokKzqphx26cvdoU8HbEifsWH6chy4bzYS".
address_key(A, B) :-
A="1D34yFJGRtiLuW2abwPBfks4cCi1Usp9a3",
B="L5NUQyHr5zaJgG9ALbVGD1tcxodf51kUvQDANcNhpej1itV9KNLD".
address_key(A, B) :-
A="12TUkSL2yyiiAD2f4zAcGDQPev2FSQmVwF",
B="KyR4Ut96DFadt1LbdZNFzCLuJ2Hw9KSeX6wfMv2dnQwgympWZyyU".
address_key(A, B) :-
A="1HySx6JBQKZoPqjUPVnbitFASKJjdAWWzx",
B="Kxcr5G39Y7jUvsmsoDK5TnezsQ4FkTcYRVTcxzTT3uLYKnHFYiVh".

For more information, visit:

[**https://www.metalevel.at/bitcoinolog/**](https://www.metalevel.at/bitcoinolog/)

**Video**: https://www.metalevel.at/prolog/videos/bitcoinolog

## Elliptic Curve Cryptography in Prolog

Bitcoinolog uses
[**`library(crypto)`**](https://github.com/mthom/scryer-prolog/blob/master/src/lib/crypto.pl)
for hashing and reasoning over *elliptic curves*.

Alternatively, you can use [**`ecclog.pl`**](ecclog.pl) for reasoning
over elliptic curves *in Prolog*. Simply use the `ecc_`
predicates instead of those starting with `crypto_`:

- `crypto_curve_generator/2` → `ecc_curve_generator/2`
- `crypto_curve_order/2` → `ecc_curve_order/2`
- etc.

Internally, `library(ecc)` uses
[CLP(ℤ) constraints](https://www.metalevel.at/prolog/clpz)
to facilitate
[declarative debugging](https://www.metalevel.at/prolog/debugging).