bip32_dart 1.0.5

  • Readme
  • Changelog
  • Installing
  • 61

bip32 #

A BIP32 compatible library for Flutter writing in Dart.

Inspired by bitcoinjs

Example #


import 'package:bip32/bip32.dart' as bip32;
import 'package:hex/hex.dart';

main() {
  bip32.BIP32 node = bip32.BIP32.fromBase58('xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi');

  print(HEX.encode(node.privateKey));
  // => e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35

  bip32.BIP32 nodeNeutered = node.neutered();
  print(nodeNeutered.isNeutered());
  // => true

  print(HEX.encode(nodeNeutered.publicKey));
  // => 0339a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c2

  print(nodeNeutered.toBase58());
  // => xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8

  bip32.BIP32 child = node.derivePath('m/0/0');
  print(child.toBase58());
  // => xprv9ww7sMFLzJMzur2oEQDB642fbsMS4q6JRraMVTrM9bTWBq7NDS8ZpmsKVB4YF3mZecqax1fjnsPF19xnsJNfRp4RSyexacULXMKowSACTRc

  print(HEX.encode(child.privateKey));
  // => f26cf12f89ab91aeeb8d7324a22e8ba080829db15c9245414b073a8c342322aa

  bip32.BIP32 childNeutered = child.neutered();
  print(childNeutered.isNeutered());
  // => true

  print(HEX.encode(childNeutered.publicKey));
  // => 02756de182c5dd4b717ea87e693006da62dbb3cddaa4a5cad2ed1f5bbab755f0f5

  print(childNeutered.toBase58());
  // => xpub6AvUGrnEpfvJ8L7GLRkBTByQ9uBvUHp9o5VxHrFxhvzV4dSWkySpNaBoLR9FpbnwRmTa69yLHF3QfcaxbWT7gWdwws5k4dpmJvqpEuMWwnj

  bip32.BIP32 nodeFromSeed = bip32.BIP32.fromSeed(HEX.decode("000102030405060708090a0b0c0d0e0f"));
  print(nodeFromSeed.toBase58());
  // => xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi

  bip32.BIP32 nodeFromPub = bip32.BIP32.fromBase58("xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8");
  print(nodeFromPub.toBase58());
  // => xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8

  var message = HEX.decode("0202020202020202020202020202020202020202020202020202020202020202");
  var signature = nodeFromSeed.sign(message);
  print(signature);
  // => [63, 219, 20, 114, 95, 184, 192, 55, 216, 206, 126, 121, 17, 71, 64, 70, 163, 82, 247, 73, 243, 95, 30, 137, 177, 155, 100, 225, 177, 203, 217, 147, 122, 64, 208, 129, 54, 133, 113, 41, 216, 160, 191, 15, 136, 98, 235, 25, 219, 178, 70, 222, 127, 151, 135, 242, 25, 192, 161, 187, 187, 84, 81, 215]

  print(HEX.encode(signature));
  // => 3fdb14725fb8c037d8ce7e7911474046a352f749f35f1e89b19b64e1b1cbd9937a40d08136857129d8a0bf0f8862eb19dbb246de7f9787f219c0a1bbbb5451d7

  print(nodeFromSeed.verify(message, signature));
  // => true
}

1.0.0 #

  • Initial version, created by anicdh

1.0.1 #

  • Format code & add description

1.0.2 #

  • Change version bs58check

1.0.3 #

  • Change generate BIP32 from function to factory

1.0.4 #

  • Fix error message when generate BIP32 from private key
  • Fix argument of wif decode function

1.0.5 #

  • Fix wif decodeRaw function

Use this package as a library

1. Depend on it

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


dependencies:
  bip32_dart: ^1.0.5

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

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

  • Dart: 2.8.4
  • pana: 0.13.14

Health suggestions

Fix lib/src/bip32_base.dart. (-11.33 points)

Analysis of lib/src/bip32_base.dart reported 24 hints, including:

line 21 col 18: Unnecessary new keyword.

line 23 col 10: Unnecessary new keyword.

line 65 col 24: Unnecessary new keyword.

line 83 col 13: Unnecessary new keyword.

line 85 col 23: Unnecessary new keyword.

Fix lib/src/utils/ecurve.dart. (-10.89 points)

Analysis of lib/src/utils/ecurve.dart reported 23 hints, including:

line 14 col 19: Unnecessary new keyword.

line 92 col 28: Unnecessary new keyword.

line 100 col 26: Unnecessary new keyword.

line 101 col 36: Unnecessary new keyword.

line 113 col 28: Unnecessary new keyword.

Fix lib/src/utils/wif.dart. (-3.45 points)

Analysis of lib/src/utils/wif.dart reported 7 hints, including:

line 11 col 11: Unnecessary new keyword.

line 14 col 12: Unnecessary new keyword.

line 21 col 11: Unnecessary new keyword.

line 24 col 11: Unnecessary new keyword.

line 26 col 10: Unnecessary new keyword.

Fix lib/src/utils/crypto.dart. (-2.48 points)

Analysis of lib/src/utils/crypto.dart reported 5 hints:

line 12 col 20: Unnecessary new keyword.

line 13 col 10: Unnecessary new keyword.

line 17 col 16: Unnecessary new keyword.

line 17 col 25: Unnecessary new keyword.

line 17 col 56: Unnecessary new keyword.

Maintenance suggestions

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and bip32_dart.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
bs58check ^1.0.1 1.0.1
hex ^0.1.2 0.1.2
pointycastle ^1.0.2 1.0.2
Transitive dependencies
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
convert 2.1.1
crypto 2.1.5
typed_data 1.2.0 1.3.0-nullsafety
Dev dependencies
test ^1.0.0