tether_libra_core 0.1.0

  • Readme
  • Changelog
  • Installing
  • 52

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(
  LibraLibConfig()
    ..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);
print(account1State.balance);

// 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);
print(account2State.balance);

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:


dependencies:
  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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
30
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
37
Overall:
Weighted score of the above. [more]
52
Learn more about scoring.

We analyzed this package on Oct 9, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:tether_libra_core/tether_libra_core.dart with components: io, isolate.

Health suggestions

Fix lib/src/client/decoder.dart. (-0.50 points)

Analysis of lib/src/client/decoder.dart reported 1 hint:

line 4 col 73: Use lowercase_with_underscores when specifying a library prefix.

Fix lib/src/client/libra_client.dart. (-0.50 points)

Analysis of lib/src/client/libra_client.dart reported 1 hint:

line 17 col 46: Use lowercase_with_underscores when specifying a library prefix.

Fix lib/src/wallet/key_factory.dart. (-0.50 points)

Analysis of lib/src/wallet/key_factory.dart reported 1 hint:

line 44 col 15: The value of the field '_child_number' isn't used.

Fix additional 70 files with analysis or formatting issues.

Additional issues in the following files:

  • 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/access_path.pbjson.dart (Run dartfmt to format lib/src/generated/access_path.pbjson.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/account_state_blob.pbjson.dart (Run dartfmt to format lib/src/generated/account_state_blob.pbjson.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/admission_control.pbjson.dart (Run dartfmt to format lib/src/generated/admission_control.pbjson.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/events.pbjson.dart (Run dartfmt to format lib/src/generated/events.pbjson.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/get_with_proof.pbjson.dart (Run dartfmt to format lib/src/generated/get_with_proof.pbjson.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/google/protobuf/wrappers.pbjson.dart (Run dartfmt to format lib/src/generated/google/protobuf/wrappers.pbjson.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/language_storage.pbjson.dart (Run dartfmt to format lib/src/generated/language_storage.pbjson.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/ledger_info.pbjson.dart (Run dartfmt to format lib/src/generated/ledger_info.pbjson.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/libra_access.pbjson.dart (Run dartfmt to format lib/src/generated/libra_access.pbjson.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.pbjson.dart (Run dartfmt to format lib/src/generated/mempool.pbjson.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/mempool_status.pbjson.dart (Run dartfmt to format lib/src/generated/mempool_status.pbjson.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/proof.pbjson.dart (Run dartfmt to format lib/src/generated/proof.pbjson.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.pbjson.dart (Run dartfmt to format lib/src/generated/transaction.pbjson.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/transaction_info.pbjson.dart (Run dartfmt to format lib/src/generated/transaction_info.pbjson.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_change.pbjson.dart (Run dartfmt to format lib/src/generated/validator_change.pbjson.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_public_keys.pbjson.dart (Run dartfmt to format lib/src/generated/validator_public_keys.pbjson.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/validator_set.pbjson.dart (Run dartfmt to format lib/src/generated/validator_set.pbjson.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/generated/vm_errors.pbjson.dart (Run dartfmt to format lib/src/generated/vm_errors.pbjson.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.

Dependencies

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 0.6.1
grpc ^1.0.2 1.0.3 2.1.2
intl ^0.15.8 0.15.8 0.16.0
isolate ^2.0.2 2.0.2
logging ^0.11.3+2 0.11.3+2
pointycastle ^1.0.1 1.0.1
protobuf ^0.13.11 0.13.16+1 1.0.0
tweetnacl ^0.3.1 0.3.2
Transitive dependencies
async 2.4.0
charcode 1.1.2
convert 2.1.1
crypto 2.1.3
fixnum 0.10.9
googleapis_auth 0.2.10
http 0.12.0+2
http2 1.0.0
http_parser 3.1.3
meta 1.1.7
path 1.6.4
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
pedantic ^1.0.0 1.8.0+1
test ^1.0.0