Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion coinlib/.pubignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/src/
.dart_tool/
build/
/doc/api/
Expand Down
9 changes: 9 additions & 0 deletions coinlib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## Unreleased

The secp256k1 library is now compiled from vendored sources by a build hook
using [native assets](https://dart.dev/tools/hooks), replacing the Docker,
autotools, CMake and MinGW build scripts. Loading a self-provided library,
whether from `build/`, a system location or `LD_LIBRARY_PATH`, is no longer
supported: the hook-built library is always used. This requires Dart 3.10 or
later and a C compiler for the target platform.

## 2.2.0

Add `ECCompressedPublicKey` class that forces compressed public keys.
Expand Down
97 changes: 10 additions & 87 deletions coinlib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ you may add `coinlib` to your project via:
dart pub add coinlib
```

If you are using the library for web, the library is ready to use. If you are
using the library on Linux, macOS, or Windows, then please see
["Building for Linux"](#building-for-linux),
["Building for macOS"](#building-for-macos), or
["Building for Windows"](#building-for-windows) below.
The native secp256k1 library is compiled from source by a
[build hook](https://dart.dev/tools/hooks) when the application is built or
run, so no separate build step is required. A C compiler for the target
platform must be available: Clang or GCC on Linux, Xcode on macOS and iOS,
Visual Studio with the C++ build tools on Windows and the NDK for Android. Web
builds use a pre-compiled WebAssembly module and need no compiler.

The library can be imported via:

Expand All @@ -56,86 +57,6 @@ final signedTx = unsignedTx.sign(inputN: 0, key: privateKey);

An example is found in the `example/` directory.

## Building for Linux

Docker or Podman is required to build the library for Linux.

The linux shared library can be built using `dart run coinlib:build_linux` in
the root directory of your package which will produce a shared library into
`build/libsecp256k1.so`. This can also be run in the `coinlib` root directory
via `dart run bin/build_linux.dart`.

This library can be in the `build` directory under the PWD, installed as a
system library, or within `$LD_LIBRARY_PATH`.

## Building for macOS

Building for macOS requires autotools that may be installed using homebrew:

```
brew install autoconf automake libtool
```

The macOS dynamic library must either be provided as
`$PWD/build/libsecp256k1.dylib` when running dart code, or provided as a system
framework named `secp256k1.framework`.

To build the dynamic library, run `dart run coinlib:build_macos` which will
place the library under a `build` directory.

## Building for Windows

### Native Windows build

**Please note that native windows builds under this section can sometimes freeze
during the build process.** If this happens please use the WSL build process
described in
["Cross-compiling for Windows using WSL"](#cross-compiling-for-windows-using-wsl).

Building on Windows requires CMake as a dependency.

The Windows shared library can be built using `dart run coinlib:build_windows` in
the root directory of your package which will produce a shared library into
`build/libsecp256k1.dll`. This can also be run in the `coinlib` root directory
via `dart run bin/build_windows.dart`.

Windows builds use the Visual Studio 17 2022 generator. Earlier Visual Studio
toolchains may work by editing `bin/build_windows.dart`.

### Cross-compiling for Windows from Linux

Cross-compile a secp256k1 DLL for Windows on an Ubuntu 20.04 host with
`dart run coinlib:build_windows_crosscompile`. This can also be run in the
`coinlib` root directory via `dart run bin/build_windows_crosscompile.dart`.

### Cross-compiling for Windows using WSL

Builds on Windows can be accomplished using WSL2 (Windows Subsystem for Linux).
First, install the following packages to the WSL(2) host:

- `autoconf`
- `libtool`
- `build-essential`
- `git`
- `cmake`
- `mingw-w64`

as in:

```
apt-get update -y
apt-get install -y autoconf libtool build-essential git cmake mingw-w64
```

Then, cross-compile a secp256k1 DLL for Windows on an Ubuntu 20.04 WSL2 instance
on a Windows host with `dart run coinlib:build_wsl` or
`dart run bin/build_wsl.dart` in the `coinlib` root directory, or complete the
above
["Cross-compiling for Windows on Linux"](#cross-compiling-for-windows-from-linux)
after installing Docker or Podman in WSL. The build can also be completed
without installing Flutter to WSL by following
[bitcoin-core/secp256k1's "Cross compiling" guide](https://github.com/bitcoin-core/secp256k1?tab=readme-ov-file#cross-compiling).

## Development

This section is only relevant to developers of the library.
Expand All @@ -146,8 +67,10 @@ 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
`headers/secp256k1.h` file using `dart run ffigen` within the `coinlib` package.
The secp256k1 sources are vendored under `third_party/secp256k1` and compiled by
the build hook in `hook/build.dart`. Bindings for the native libraries
(excluding WebAssembly) are generated from the vendored headers using `dart run
ffigen` within the `coinlib` package.

The WebAssembly module has been pre-built to
`lib/src/secp256k1/secp256k1.wasm.g.dart`. It may be rebuilt using `dart run
Expand Down
55 changes: 0 additions & 55 deletions coinlib/bin/build_linux.dart

This file was deleted.

76 changes: 0 additions & 76 deletions coinlib/bin/build_macos.dart

This file was deleted.

12 changes: 5 additions & 7 deletions coinlib/bin/build_wasm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ final $name = base64Decode("$b64");""";
}

void main() async {

String cmd = await getDockerCmd();
print("Using $cmd to run dockerfile");

Expand All @@ -103,11 +102,11 @@ void main() async {

// Build secp256k1 to wasm and copy wasm file to tempdir
if (!await dockerRun(
cmd,
dockerfile,
"coinlib_build_secp256k1_wasm",
tmpDir,
"cp output/secp256k1.wasm /host/secp256k1.wasm",
cmd,
dockerfile,
"coinlib_build_secp256k1_wasm",
tmpDir,
"cp output/secp256k1.wasm /host/secp256k1.wasm",
)) {
exit(1);
}
Expand All @@ -119,5 +118,4 @@ void main() async {
"secp256k1WasmData",
);
print("Output secp256k1.wasm.g.dart successfully");

}
57 changes: 0 additions & 57 deletions coinlib/bin/build_windows.dart

This file was deleted.

Loading
Loading