bip32_keys 3.0.0 copy "bip32_keys: ^3.0.0" to clipboard
bip32_keys: ^3.0.0 copied to clipboard

A BIP32 (https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) compatible library for Flutter writing by Dart.

codecov

bip32-keys #

A BIP32 compatible library for Flutter writing in Dart.

Inspired by bitcoinjs Forked from bip32

Example #

import 'dart:typed_data';
import 'package:bip32_keys/bip32_keys.dart';
import 'package:hex/hex.dart';

main() {
  Bip32Keys node = Bip32Keys.fromBase58(
      'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi');

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

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

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

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

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

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

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

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

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

  Bip32Keys nodeFromSeed = Bip32Keys.fromSeed(
      HEX.decode("000102030405060708090a0b0c0d0e0f") as Uint8List);
  print(nodeFromSeed.toBase58());
  // => xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi

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

  var message = HEX.decode(
          "0202020202020202020202020202020202020202020202020202020202020202")
      as Uint8List;
  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
}

Contributor #

0
likes
0
points
214
downloads

Publisher

verified publisherethicnology.com

Weekly Downloads

A BIP32 (https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) compatible library for Flutter writing by Dart.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

bs58check, hex, pointycastle

More

Packages that depend on bip32_keys