dart_wif 2.1.1 copy "dart_wif: ^2.1.1" to clipboard
dart_wif: ^2.1.1 copied to clipboard

Dart Bitcoin Wallet Import Format encoding/decoding package.

example/dart_wif_example.dart

import 'dart:typed_data';

import 'package:convert/convert.dart';
import 'package:dart_wif/dart_wif.dart';

void main() {
  Uint8List privateKey = Uint8List.fromList(hex.decode(
      '0000000000000000000000000000000000000000000000000000000000000001'));
  final WIF decoded =
      WIF(version: 128, privateKey: privateKey, compressed: true);
  String key = wif.encode(decoded); // for the testnet use: Wif.encode(239, ...
  print(key);
  // => KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn

  var obj = wif.decode(key);

  print(obj);
  // => {
  //	version: 128,
  //	privateKey: "0000000000000000000000000000000000000000000000000000000000000001",
  //	compressed: true
  //}

  try {
    wif.decode(key, 0x09);
  } catch (e) {
    print(e);
  }
  // => Invalid argument(s): Invalid network version

  print(obj == decoded);
  // => true

  print(obj == WIF(privateKey: Uint8List(0), version: 1, compressed: false));
  // => false
}
0
likes
140
pub points
62%
popularity

Publisher

verified publishermahsumurebe.com

Dart Bitcoin Wallet Import Format encoding/decoding package.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

dart_bs58check

More

Packages that depend on dart_wif