tether_libra_core 0.1.0

Libra Core Dart #

The TetherMedia Libra Core library is a pure Dart library designed for use by Dart and Flutter programs to interact with Libra (https://libra.org) nodes on the test network.

This is still under heavy testing as the Libra testnet is under constant change.

This code started out as a straight port of the Libra wallet library (https://github.com/libra/libra.git) to Dart. Somewhere along the way, Perfect Makanju released libra-core (https://github.com/perfectmak/libra-core), a JavaScript client for Libra, and parts of that effort were ported here as well to complete this Dart client library, along with some Dart spice added in (e.g. the use of isolates to keep heavy computing off the ui-thread to help with Flutter).

To see the library in action, there is an example Flutter application built for Android coming soon

Usage #

There are two main interface classes:

  • LibraWallet
  • LibraClient

LibraWallet #

The LibraWallet allows you to maintain a wallet for use in the Libra TestNetwork. It has interfaces to create a wallet (which is really just a secure keypair). New wallets are created with:

LibraWallet wallet = LibraWallet.create();

Wallets can be restored from a saved Mnemonic:

const String MNEMONIC = "cage blur unaware ... motion aware";
LibraWallet wallet = LibraWallet.fromMnemonic(Mnemonic.fromPhrase(MNEMONIC));

Async versions of create and fromMnemonic exist (createAsync and fromMnemonic asysc) which make use of isolates to run the cryptographic routines in the background, useful for mobile apps.

A LibraWallet holds Account objects. A wallet may hold more than one Account, each account being a "child" of the wallet. A child is numbered starting with 1. An Account contains an AccountAddress which is the address used for transferring coins and querying transactions. A wallet will always generate the same Account/AccountAddress for a child, since creation is dependendant on the keypair that make up the wallet.

Account account1 = wallet.newAccount();  // generated child 1
Account account2 = wallet.newAccount();  // generated child 2

The list of Accounts stored has a getter. It is often more convenient to get the addresses of the Accounts in the wallet, so there is a getter for that too.

List<AccountAddress> addresses = wallet.addresses;
List<Account> = wallet.accounts;

The LibraWallet can write a recovery string and restore from that string using abstract WalletLibraStorage interface that can be defined by the clients.

LibraWallet wallet = LibraWallet.create();
WalletLibraMemoryStorage storage = WalletLibraMemoryStorage();
await wallet.write_recovery(storage);
LibraWallet rebuiltWallet = await LibraWallet.recover(storage);

A recovered LibraWallet will automatically regenerate the accounts in the wallet.

LibraClient #

The LibraClient class provides the remote interface to the Libra network. It allows the client app to:

  • transferCoins()
  • getAccountState()
  • getAccountTransaction()
  • Mint coins on the test network

A LibraCoin class was added as a convenience wrapper for Libra coin values. Libra coin values in transactions on the network are in micro-libra. The LibraCoin class does the math and makes display easier (e.g. 10.55 instead of the BigInt value of 10550000 )

An example of it all glued together:

LibraClient client = LibraClient(
    ..network =  LibraNetwork.Testnet);

LibraWallet wallet = LibraWallet.create();
Account account1 = await wallet.newAccount();
Account account2 = await wallet.newAccount();

// Mint some coins into account one and wait a bit
await client.mintWithFaucetService(account1Address, 10);
await Future.delayed(Duration(seconds: 5));

// Print amount in account 1
var account1State = await client.getAccountState(account1);

// Transfer some money from account 1 to account 2
var response = await client.transferCoins(account1, account2Address, LibraCoin.fromInt(5));
await Future.delayed(Duration(seconds: 5));

// Now account 2 has money
var account2State = await client.getAccountState(account2);

Features and bugs #

Please file feature requests and bugs at the issue tracker.

License #

MIT except where noted in file headers.

Author: glachac@tethermedia.com

0.1.0 #

  • Initial release

Use this package as a library

1. Depend on it

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

  tether_libra_core: ^0.1.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:tether_libra_core/tether_libra_core.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 25, 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/generated/get_with_proof.pbjson.dart. (-25 points)

Analysis of lib/src/generated/get_with_proof.pbjson.dart reported 64 hints, including:

line 7 col 42: Avoid const keyword.

line 9 col 8: Avoid const keyword.

line 10 col 5: Avoid const keyword.

line 15 col 12: Avoid const keyword.

line 18 col 5: Avoid const keyword.

Fix lib/src/generated/transaction.pbjson.dart. (-25 points)

Analysis of lib/src/generated/transaction.pbjson.dart reported 88 hints, including:

line 7 col 26: Avoid const keyword.

line 9 col 8: Avoid const keyword.

line 10 col 5: Avoid const keyword.

line 11 col 5: Avoid const keyword.

line 15 col 29: Avoid const keyword.

Fix lib/src/generated/vm_errors.pbjson.dart. (-25 points)

Analysis of lib/src/generated/vm_errors.pbjson.dart reported 203 hints, including:

line 7 col 37: Avoid const keyword.

line 9 col 8: Avoid const keyword.

line 10 col 5: Avoid const keyword.

line 11 col 5: Avoid const keyword.

line 12 col 5: Avoid const keyword.

Fix additional 70 files with analysis or formatting issues. (-116.70 points)

Additional issues in the following files:

  • lib/src/generated/mempool.pbjson.dart (43 hints)
  • lib/src/generated/libra_access.pbjson.dart (38 hints)
  • lib/src/generated/proof.pbjson.dart (29 hints)
  • lib/src/generated/google/protobuf/wrappers.pbjson.dart (27 hints)
  • lib/src/generated/admission_control.pbjson.dart (20 hints)
  • lib/src/generated/events.pbjson.dart (20 hints)
  • lib/src/generated/ledger_info.pbjson.dart (19 hints)
  • lib/src/generated/mempool_status.pbjson.dart (12 hints)
  • lib/src/generated/account_state_blob.pbjson.dart (9 hints)
  • lib/src/generated/transaction_info.pbjson.dart (7 hints)
  • lib/src/generated/validator_public_keys.pbjson.dart (6 hints)
  • lib/src/generated/access_path.pbjson.dart (4 hints)
  • lib/src/generated/language_storage.pbjson.dart (4 hints)
  • lib/src/generated/validator_change.pbjson.dart (4 hints)
  • lib/src/generated/validator_set.pbjson.dart (3 hints)
  • lib/src/client/decoder.dart (1 hint)
  • lib/src/client/libra_client.dart (1 hint)
  • lib/src/wallet/key_factory.dart (1 hint)
  • lib/src/client/encoder.dart (Run dartfmt to format lib/src/client/encoder.dart.)
  • lib/src/crypto/hkdf.dart (Run dartfmt to format lib/src/crypto/hkdf.dart.)
  • lib/src/crypto/sha3FixDigest.dart (Run dartfmt to format lib/src/crypto/sha3FixDigest.dart.)
  • lib/src/generated/access_path.pb.dart (Run dartfmt to format lib/src/generated/access_path.pb.dart.)
  • lib/src/generated/access_path.pbenum.dart (Run dartfmt to format lib/src/generated/access_path.pbenum.dart.)
  • lib/src/generated/account_state_blob.pb.dart (Run dartfmt to format lib/src/generated/account_state_blob.pb.dart.)
  • lib/src/generated/account_state_blob.pbenum.dart (Run dartfmt to format lib/src/generated/account_state_blob.pbenum.dart.)
  • lib/src/generated/admission_control.pb.dart (Run dartfmt to format lib/src/generated/admission_control.pb.dart.)
  • lib/src/generated/admission_control.pbenum.dart (Run dartfmt to format lib/src/generated/admission_control.pbenum.dart.)
  • lib/src/generated/events.pb.dart (Run dartfmt to format lib/src/generated/events.pb.dart.)
  • lib/src/generated/events.pbenum.dart (Run dartfmt to format lib/src/generated/events.pbenum.dart.)
  • lib/src/generated/get_with_proof.pb.dart (Run dartfmt to format lib/src/generated/get_with_proof.pb.dart.)
  • lib/src/generated/get_with_proof.pbenum.dart (Run dartfmt to format lib/src/generated/get_with_proof.pbenum.dart.)
  • lib/src/generated/google/protobuf/wrappers.pb.dart (Run dartfmt to format lib/src/generated/google/protobuf/wrappers.pb.dart.)
  • lib/src/generated/google/protobuf/wrappers.pbenum.dart (Run dartfmt to format lib/src/generated/google/protobuf/wrappers.pbenum.dart.)
  • lib/src/generated/language_storage.pb.dart (Run dartfmt to format lib/src/generated/language_storage.pb.dart.)
  • lib/src/generated/language_storage.pbenum.dart (Run dartfmt to format lib/src/generated/language_storage.pbenum.dart.)
  • lib/src/generated/ledger_info.pb.dart (Run dartfmt to format lib/src/generated/ledger_info.pb.dart.)
  • lib/src/generated/ledger_info.pbenum.dart (Run dartfmt to format lib/src/generated/ledger_info.pbenum.dart.)
  • lib/src/generated/libra_access.pb.dart (Run dartfmt to format lib/src/generated/libra_access.pb.dart.)
  • lib/src/generated/libra_access.pbenum.dart (Run dartfmt to format lib/src/generated/libra_access.pbenum.dart.)
  • lib/src/generated/mempool.pb.dart (Run dartfmt to format lib/src/generated/mempool.pb.dart.)
  • lib/src/generated/mempool.pbenum.dart (Run dartfmt to format lib/src/generated/mempool.pbenum.dart.)
  • lib/src/generated/mempool_status.pb.dart (Run dartfmt to format lib/src/generated/mempool_status.pb.dart.)
  • lib/src/generated/mempool_status.pbenum.dart (Run dartfmt to format lib/src/generated/mempool_status.pbenum.dart.)
  • lib/src/generated/proof.pb.dart (Run dartfmt to format lib/src/generated/proof.pb.dart.)
  • lib/src/generated/proof.pbenum.dart (Run dartfmt to format lib/src/generated/proof.pbenum.dart.)
  • lib/src/generated/transaction.pb.dart (Run dartfmt to format lib/src/generated/transaction.pb.dart.)
  • lib/src/generated/transaction.pbenum.dart (Run dartfmt to format lib/src/generated/transaction.pbenum.dart.)
  • lib/src/generated/transaction_info.pb.dart (Run dartfmt to format lib/src/generated/transaction_info.pb.dart.)
  • lib/src/generated/transaction_info.pbenum.dart (Run dartfmt to format lib/src/generated/transaction_info.pbenum.dart.)
  • lib/src/generated/validator_change.pb.dart (Run dartfmt to format lib/src/generated/validator_change.pb.dart.)
  • lib/src/generated/validator_change.pbenum.dart (Run dartfmt to format lib/src/generated/validator_change.pbenum.dart.)
  • lib/src/generated/validator_public_keys.pb.dart (Run dartfmt to format lib/src/generated/validator_public_keys.pb.dart.)
  • lib/src/generated/validator_public_keys.pbenum.dart (Run dartfmt to format lib/src/generated/validator_public_keys.pbenum.dart.)
  • lib/src/generated/validator_set.pb.dart (Run dartfmt to format lib/src/generated/validator_set.pb.dart.)
  • lib/src/generated/validator_set.pbenum.dart (Run dartfmt to format lib/src/generated/validator_set.pbenum.dart.)
  • lib/src/generated/vm_errors.pb.dart (Run dartfmt to format lib/src/generated/vm_errors.pb.dart.)
  • lib/src/generated/vm_errors.pbenum.dart (Run dartfmt to format lib/src/generated/vm_errors.pbenum.dart.)
  • lib/src/io_utils.dart (Run dartfmt to format lib/src/io_utils.dart.)
  • lib/src/transaction/errors.dart (Run dartfmt to format lib/src/transaction/errors.dart.)
  • lib/src/transaction/hashSaltValues.dart (Run dartfmt to format lib/src/transaction/hashSaltValues.dart.)
  • lib/src/transaction/program_base64_codes.dart (Run dartfmt to format lib/src/transaction/program_base64_codes.dart.)
  • lib/src/transaction/transaction.dart (Run dartfmt to format lib/src/transaction/transaction.dart.)
  • lib/src/types/account_state.dart (Run dartfmt to format lib/src/types/account_state.dart.)
  • lib/src/types/libra_coin.dart (Run dartfmt to format lib/src/types/libra_coin.dart.)
  • lib/src/wallet/account.dart (Run dartfmt to format lib/src/wallet/account.dart.)
  • lib/src/wallet/account_address.dart (Run dartfmt to format lib/src/wallet/account_address.dart.)
  • lib/src/wallet/mnemonic.dart (Run dartfmt to format lib/src/wallet/mnemonic.dart.)
  • lib/src/wallet/wallet_library.dart (Run dartfmt to format lib/src/wallet/wallet_library.dart.)
  • lib/src/wallet/wallet_storage.dart (Run dartfmt to format lib/src/wallet/wallet_storage.dart.)
  • lib/tether_libra_core.dart (Run dartfmt to format lib/tether_libra_core.dart.)

Maintenance issues and suggestions

Support latest dependencies. (-40 points)

The version constraint in pubspec.yaml does not support the latest published versions for 4 dependencies (equatable, grpc, intl, protobuf).

The package description is too short. (-13 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

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

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
collection ^1.14.11 1.14.12
equatable ^0.2.6 0.2.6 1.1.0
grpc ^1.0.2 1.0.3 2.1.3
intl ^0.15.8 0.15.8 0.16.1
isolate ^2.0.2 2.0.3
logging ^0.11.3+2 0.11.4
pointycastle ^1.0.1 1.0.2
protobuf ^0.13.11 0.13.16+1 1.0.1
tweetnacl ^0.3.1 0.3.2
Transitive dependencies
async 2.4.0
charcode 1.1.3
convert 2.1.1
crypto 2.1.4
fixnum 0.10.11
googleapis_auth 0.2.11+1
http 0.12.0+4
http2 1.0.0
http_parser 3.1.3
meta 1.1.8
path 1.6.4
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
pedantic ^1.0.0 1.9.0
test ^1.0.0