bitcoin_flutter 2.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 80

pub version

bitcoin_flutter #

A dart Bitcoin library for Flutter.

Released under the terms of the MIT LICENSE.

Inspired by bitcoinjs

Otherwise, pull requests are appreciated.

Installing #

Flutter Packages

Examples #

import 'package:bitcoin_flutter/bitcoin_flutter.dart';
import 'package:bip39/bip39.dart' as bip39;

main() {
  var seed = bip39.mnemonicToSeed("praise you muffin lion enable neck grocery crumble super myself license ghost");
  var hdWallet = new HDWallet(seed);
  print(hdWallet.address);
  // => 12eUJoaWBENQ3tNZE52ZQaHqr3v4tTX4os
  print(hdWallet.pubKey);
  // => 0360729fb3c4733e43bf91e5208b0d240f8d8de239cff3f2ebd616b94faa0007f4
  print(hdWallet.privKey);
  // => 01304181d699cd89db7de6337d597adf5f78dc1f0784c400e41a3bd829a5a226
  print(hdWallet.wif);
  // => KwG2BU1ERd3ndbFUrdpR7ymLZbsd7xZpPKxsgJzUf76A4q9CkBpY
  
  var wallet = Wallet.fromWIF("Kxr9tQED9H44gCmp6HAdmemAzU3n84H3dGkuWTKvE23JgHMW8gct");
  print(wallet.address);
  // => 19AAjaTUbRjQCMuVczepkoPswiZRhjtg31
  print(wallet.pubKey);
  // => 03aea0dfd576151cb399347aa6732f8fdf027b9ea3ea2e65fb754803f776e0a509
  print(wallet.privKey);
  // => 3095cb26affefcaaa835ff968d60437c7c764da40cdd1a1b497406c7902a8ac9
  print(wallet.wif);
  // => Kxr9tQED9H44gCmp6HAdmemAzU3n84H3dGkuWTKvE23JgHMW8gct
}

The below examples are implemented as integration tests:

TODO #

  • Generate a SegWit P2SH address
  • Generate a SegWit multisig address
  • Create a Transaction with a P2SH(multisig) input
  • Build a Transaction w/ psbt format
  • Add Tapscript / Taproot feature

Running the test suite #

dart run test

Complementing Libraries #

  • BIP39 - Mnemonic generation for deterministic keys
  • BIP32 - BIP32
  • Base58 Check - Base58 check encoding/decoding

LICENSE MIT #

2.0.0 Backwards Incompatibility #

  • Please update your sign function if you use this version. sign now required parameter name
  • Support building a Transaction with a SegWit P2WPKH input
  • Add Address.validateAddress to validate address

1.1.0 #

  • Add PaymentData, P2PKHData to be deprecated, will remove next version
  • Support p2wpkh

1.0.7 #

  • Try catch getter privKey, base58Priv, wif
  • Possible to create a neutered HD Wallet

1.0.6 #

  • Accept non-standard payment

1.0.5 #

  • Add ECPair to index

1.0.4 #

  • Add transaction to index

1.0.3 #

  • Fix bug testnet BIP32

1.0.2 #

  • Add sign and verify for HD Wallet and Wallet

1.0.1 #

  • Add derive and derive path for HD Wallet

1.0.0 #

  • Transaction implementation

0.1.1 #

  • HDWallet from Seed implementation
  • Wallet from WIF implementation

example/bitcoin_flutter_example.dart

import 'package:bitcoin_flutter/bitcoin_flutter.dart';
import 'package:bip39/bip39.dart' as bip39;
main() {
  var seed = bip39.mnemonicToSeed(
      "praise you muffin lion enable neck grocery crumble super myself license ghost");
  var hdWallet = new HDWallet.fromSeed(seed);
  print(hdWallet.address);
  // => 12eUJoaWBENQ3tNZE52ZQaHqr3v4tTX4os
  print(hdWallet.pubKey);
  // => 0360729fb3c4733e43bf91e5208b0d240f8d8de239cff3f2ebd616b94faa0007f4
  print(hdWallet.privKey);
  // => 01304181d699cd89db7de6337d597adf5f78dc1f0784c400e41a3bd829a5a226
  print(hdWallet.wif);
  // => KwG2BU1ERd3ndbFUrdpR7ymLZbsd7xZpPKxsgJzUf76A4q9CkBpY

  var wallet =
      Wallet.fromWIF("Kxr9tQED9H44gCmp6HAdmemAzU3n84H3dGkuWTKvE23JgHMW8gct");
  print(wallet.address);
  // => 19AAjaTUbRjQCMuVczepkoPswiZRhjtg31
  print(wallet.pubKey);
  // => 03aea0dfd576151cb399347aa6732f8fdf027b9ea3ea2e65fb754803f776e0a509
  print(wallet.privKey);
  // => 3095cb26affefcaaa835ff968d60437c7c764da40cdd1a1b497406c7902a8ac9
  print(wallet.wif);
  // => Kxr9tQED9H44gCmp6HAdmemAzU3n84H3dGkuWTKvE23JgHMW8gct
}

Use this package as a library

1. Depend on it

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


dependencies:
  bitcoin_flutter: ^2.0.0

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:bitcoin_flutter/bitcoin_flutter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
76
Health:
Code health derived from static analysis. [more]
74
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
80
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6

Health issues and suggestions

Document public APIs. (-0.69 points)

191 out of 193 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/transaction.dart. (-22.95 points)

Analysis of lib/src/transaction.dart reported 52 hints, including:

line 22 col 23: Unnecessary new keyword.

line 27 col 5: Unnecessary new keyword.

line 37 col 13: Unnecessary new keyword.

line 47 col 14: Unnecessary new keyword.

line 53 col 45: Use isNotEmpty instead of length

Fix lib/src/transaction_builder.dart. (-22.17 points)

Analysis of lib/src/transaction_builder.dart reported 50 hints, including:

line 4 col 8: Unused import: 'package:bs58check/bs58check.dart'.

line 5 col 8: Unused import: 'package:bech32/bech32.dart'.

line 28 col 16: Unnecessary new keyword.

line 36 col 17: Unnecessary new keyword.

line 47 col 50: Unnecessary new keyword.

Fix lib/src/payments/p2wpkh.dart. (-9.08 points)

Analysis of lib/src/payments/p2wpkh.dart reported 19 hints, including:

line 26 col 7: DO use curly braces for all flow control structures.

line 26 col 13: Unnecessary new keyword.

line 38 col 9: DO use curly braces for all flow control structures.

line 38 col 15: Unnecessary new keyword.

line 52 col 9: DO use curly braces for all flow control structures.

Fix additional 17 files with analysis or formatting issues. (-46.33 points)

Additional issues in the following files:

  • lib/src/utils/script.dart (17 hints)
  • lib/src/payments/p2pkh.dart (15 hints)
  • lib/src/bitcoin_flutter_base.dart (13 hints)
  • lib/src/ecpair.dart (11 hints)
  • lib/src/address.dart (10 hints)
  • lib/src/payments/p2pk.dart (8 hints)
  • lib/src/crypto.dart (7 hints)
  • lib/src/classify.dart (4 hints)
  • lib/src/models/networks.dart (4 hints)
  • lib/src/templates/pubkey.dart (2 hints)
  • lib/src/utils/push_data.dart (2 hints)
  • lib/src/utils/magic_hash.dart (1 hint)
  • lib/src/utils/varuint.dart (1 hint)
  • lib/src/payments/index.dart (Run dartfmt to format lib/src/payments/index.dart.)
  • lib/src/templates/witnesspubkeyhash.dart (Run dartfmt to format lib/src/templates/witnesspubkeyhash.dart.)
  • lib/src/utils/check_types.dart (Run dartfmt to format lib/src/utils/check_types.dart.)
  • lib/src/utils/constants/op.dart (Run dartfmt to format lib/src/utils/constants/op.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.58.0 <3.0.0
bech32 0.1.2 0.1.2
bip32 ^1.0.5 1.0.5
bip39 ^1.0.3 1.0.3
bs58check ^1.0.1 1.0.1
hex ^0.1.2 0.1.2
meta ^1.1.5 1.1.8
pointycastle ^1.0.0-rc2 1.0.2
Transitive dependencies
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.4
typed_data 1.1.6
Dev dependencies
test ^1.0.0