coinlib 6.0.1
coinlib: ^6.0.1 copied to clipboard
A straight-forward, modular library for Peercoin and other Satoshi-based UTXO blockchains
Coinlib #
Coinlib is a straight-forward and modular library for Peercoin and other similar cryptocoins including Taproot support. This library allows for the construction and signing of transactions and management of BIP32 wallets.
Installation and Usage #
Add coinlib to a Dart or Flutter project via:
dart pub add coinlib
The native secp256k1 library is compiled and bundled automatically on Android, iOS, Linux, macOS, and Windows using Dart Code Assets. Web uses the bundled WebAssembly module.
The library can be imported via:
import 'package:coinlib/coinlib.dart';
The library must be asynchronously loaded by awaiting the loadCoinlib()
function before any part of the library is used. In Flutter, do this before
calling runApp():
Future<void> main() async {
await loadCoinlib();
runApp(const MyApp());
}
The library uses a functional-style of OOP. With some exceptions, objects are immutable. New modified objects are returned from methods. For example, signing a transaction returns a new signed transaction object:
final signedTx = unsignedTx.signLegacy(inputN: 0, key: privateKey);
An example is found in the example/ directory.
For a native CLI release bundle, use the Code Assets-aware build command:
dart build cli --target bin/your_app.dart
The Dart 3.13 link hook records reachable FFI bindings and removes unused native symbols from the bundled library. A platform C toolchain is required.
Development #
This section is only relevant to developers of the library.
Bindings and WebAssembly #
The WebAssembly (WASM) module is pre-compiled and ready to use. FFI bindings are pre-generated. These only need to be updated when the underlying secp256k1 library is changed.
Bindings for the native libraries (excluding WebAssembly) are generated from
the vendored headers using dart run tool/ffigen.dart within the coinlib
package. The command also regenerates the mapping used by the native link hook.
The WebAssembly module has been pre-built to
lib/src/secp256k1/secp256k1.wasm.g.dart. It may be rebuilt using dart run bin/build_wasm.dart in the coinlib root directory.