dartsv 0.2.5-RC1

Introduction #

Overview #

TwoStack WalletSDK is a Bitcoin library for the Dart Language ( dartlang.org ), loosely based on the Moneybutton/BSV Javascript library. This library has been built in line with the ideals espoused by BitcoinSV, i.e. massive on-chain scaling, protocol stability and original-bitcoin-protocol implementation.

This library therefore lacks , and will not implement :

  • Segregated Witness (Segwit) Transaction support
  • Schnorr Signature support
  • Check Datasig (OP_CHECKDATASIG)

Current Supported features are :

  • P2PKH Transactions (building and spending from)
  • Data-only Transactions
  • HD Key Derivation (BIP32)
  • Original Bitcoin Address format
  • Bitcoin Signed Messages
  • Bip39 Mnemonic Support (BIP39)
  • A built-in Bitcoin Script Interpreter

Pending Features :

  • P2SH support (low priority since it will be deprecated in BitcoinSV)

Sample of the Transaction API: #

String createWalletTxn(Address address, List<TransactionInput> utxosToSpendFrom, BigInt amount ){

    var transaction = new Transaction()
        .spendTo(address, amount)
        .sendChangeTo(_receivingAddress) // spend change to myself
        .signWith(this._walletPrivKey, sighashType: SighashType.SIGHASH_ALL | SighashType.SIGHASH_FORKID);

    return transaction.serialize();

Installation #

This library was built using version (2.3.1) of the Dart SDK https://dart.dev/tools/sdk, but should work with Dart SDK 2.1.x onwards.
Therefore, as a pre-requisite ensure that you have at least that version of the Dart SDK installed before proceeding.

Navigate to the root folder of this project, and pull the required supported Dart libraries using the pub package manager.

> pub get

Running the Tests #

In the root folder of this project, run the shell script :

> ./runtests.sh

Acknowledgement #

A debt of gratitude is owed to the developers acknowledged in the LICENSE file. Without the hard work of individuals working on earlier library and node implementations like Bitcoin Core, Bitcoin Cash, MoneyButton/BSV, BitcoinJ and many more, this library would likely not have come to fruition. Thank you.

Contact #

You can reach the author at :

  • @beardpappa on Twitter
  • beardpappa@moneybutton.com (PayMail to buy me a beer)
  • stephan@werkswinkel.com

0.2.5-RC1 #

  • Added CLI example app

0.2.4-RC1 #

  • Additional test coverage for Signatures
  • Minor code refactor to improve code readability in line with linter suggestions

0.2.3-RC1 #

  • Minor code refactor to improve code readability in line with linter suggestions

0.2.1-RC1 #

  • Minor code refactor to improve code readability in line with linter suggestions

0.2.0-RC1 #

  • Completed the API documentation
  • Small API changes and cleanup

0.1.0-RC1 #

  • Library is now functionally complete
  • Script Interpreter Implementation is complete
  • Handling of Raw Blocks has been implemented
  • Bip39 mnemonics now has complete test coverage
  • Minor updates to various APIs

0.1.0-alpha2 #

  • Added support for contributed Bip39 mnemonics
  • Added support for Bitcoin Signed Messages

0.1.0-alpha #

  • Initial Release


Getting Started #

Install Dart-SDK #

Documentation : https://dart.dev/tools/sdk Installation Instructions : https://dart.dev/get-dart

Running the app #

Navigate to the top-level folder of the dartsv-cli project and pull your dependencies

> pub get

Now run the app...

> pub run bin/main.dart

When you run the app on the CLI it will :

  • Print two Addresses on the console
    • Receiving address where you send Testnet coins
    • Spending address where the app will send 10k satoshis automatically

You will notice that the app comes ready-to-run with pre-funded testnet addresses. You should change the mnemonic and consequently get new addresses for local testing.

Testnet Faucet #

Grab some coins from the faucet located here: BitcoinSV Testnet Faucet Link (remember to donate some BSV to the dev)

BitIndex #

Bitindex is a great service which I have used in this example application to :

  • Get a list of UTXOs associated with an address
  • Broadcast the raw transaction to the testnet

Check them out : https://www.bitindex.network

Feedback #

I welcome any and all feedback. Please post a comment on GitHub.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  dartsv: ^0.2.5-RC1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:dartsv/dartsv.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Health suggestions

Fix lib/src/encoding/utils.dart. (-9.99 points)

Analysis of lib/src/encoding/utils.dart reported 21 hints, including:

line 13 col 17: Unnecessary new keyword.

line 14 col 18: Unnecessary new keyword.

line 19 col 12: Unnecessary new keyword.

line 23 col 12: Unnecessary new keyword.

line 27 col 25: Unnecessary new keyword.

Fix lib/src/crypto/childnumber.dart. (-4.89 points)

Analysis of lib/src/crypto/childnumber.dart reported 10 hints, including:

line 11 col 5: Prefer using /// for doc comments.

line 20 col 37: Unnecessary new keyword.

line 21 col 36: Unnecessary new keyword.

line 22 col 46: Unnecessary new keyword.

line 24 col 5: Prefer using /// for doc comments.

Fix lib/src/crypto/hdutils.dart. (-4.89 points)

Analysis of lib/src/crypto/hdutils.dart reported 10 hints, including:

line 16 col 34: Unnecessary new keyword.

line 19 col 31: Unnecessary new keyword.

line 20 col 21: Unnecessary new keyword.

line 21 col 19: Unnecessary new keyword.

line 30 col 25: Unnecessary new keyword.

Fix additional 29 files with analysis or formatting issues. (-26.25 points)

Additional issues in the following files:

  • lib/src/sighash.dart (10 hints)
  • lib/src/encoding/base58check.dart (8 hints)
  • lib/src/encoding/ckdserializer.dart (5 hints)
  • lib/src/hdpublickey.dart (4 hints)
  • lib/src/networks.dart (4 hints)
  • lib/src/block/merkleblock.dart (3 hints)
  • lib/src/script/OpReturnScriptPubkey.dart (3 hints)
  • lib/src/script/stack.dart (3 hints)
  • lib/src/block/blockheader.dart (2 hints)
  • lib/src/encoding/wifcodec.dart (2 hints)
  • lib/src/hdprivatekey.dart (2 hints)
  • lib/src/message.dart (2 hints)
  • lib/src/script/svscript.dart (2 hints)
  • lib/src/transaction/transaction_output.dart (2 hints)
  • lib/src/script/interpreter.dart (1 hint)
  • lib/dartsv.dart (Run dartfmt to format lib/dartsv.dart.)
  • lib/src/address.dart (Run dartfmt to format lib/src/address.dart.)
  • lib/src/bip39/bip39.dart (Run dartfmt to format lib/src/bip39/bip39.dart.)
  • lib/src/block/block.dart (Run dartfmt to format lib/src/block/block.dart.)
  • lib/src/exceptions.dart (Run dartfmt to format lib/src/exceptions.dart.)
  • lib/src/privatekey.dart (Run dartfmt to format lib/src/privatekey.dart.)
  • lib/src/publickey.dart (Run dartfmt to format lib/src/publickey.dart.)
  • lib/src/script/P2PKHScriptPubkey.dart (Run dartfmt to format lib/src/script/P2PKHScriptPubkey.dart.)
  • lib/src/script/P2PKHScriptSig.dart (Run dartfmt to format lib/src/script/P2PKHScriptSig.dart.)
  • lib/src/script/opcodes.dart (Run dartfmt to format lib/src/script/opcodes.dart.)
  • lib/src/script/scriptflags.dart (Run dartfmt to format lib/src/script/scriptflags.dart.)
  • lib/src/signature.dart (Run dartfmt to format lib/src/signature.dart.)
  • lib/src/transaction/transaction.dart (Run dartfmt to format lib/src/transaction/transaction.dart.)
  • lib/src/transaction/transaction_input.dart (Run dartfmt to format lib/src/transaction/transaction_input.dart.)

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (asn1lib).

Package is pre-release. (-5 points)

Pre-release versions should be used with caution; their API can change in breaking ways.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
asn1lib ^0.5.15 0.5.15 0.6.4
buffer ^1.0.6 1.0.6
collection ^1.14.11 1.14.12
hex ^0.1.2 0.1.2
pointycastle ^1.0.1 1.0.2
resource ^2.1.5 2.1.6
sprintf ^4.0.2 4.0.2
unorm_dart ^0.1.1 0.1.2
Transitive dependencies
typed_data 1.1.6
Dev dependencies
mockito ^4.0.0
pedantic ^1.0.0
test ^1.0.0