Skip to content

Commit

Permalink
feat: remove lightning_message packages because of too many inconsist…
Browse files Browse the repository at this point in the history
…encies on signer key derivation between implementations (#7)
  • Loading branch information
kumulynja authored Sep 7, 2023
1 parent f60f4a6 commit 75d08ec
Show file tree
Hide file tree
Showing 198 changed files with 27 additions and 6,992 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ jobs:
- name: Check Rust format in bip39
working-directory: ./packages/bip39/native/src
run: rustfmt --check lib.rs
- name: Check Rust format in lightning_message
working-directory: ./packages/lightning_message/native/src
run: rustfmt --check lib.rs
- name: Rust code analysis
run: cargo clippy -- -D warnings
- name: Run Rust tests
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = ["packages/lightning_message/native", "packages/bip39/native"]
members = ["packages/bip39/native"]
resolver = "2"

[profile.release]
lto = true
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ We mainly use the [Lightning Development Kit](https://www.lightningdevkit.org) a
## Packages

- [x] `bip39`: package to generate and/or restore mnemonics and derive other keys and seeds from them.
- [x] `lightning_message`: package to sign and verify Lightning messages. Useful for proving ownership of a node, which in turn is useful for login mechanisms to get rid of username and passwords in apps, amongst other things.
- [ ] `unified_wallet`: package to derive different seeds from the same mnemonic for different wallet types. For example, have a Bitcoin on-chain wallet, a Bitcoin on-chain wallet with passphrase and a Lightning node wallet, all derived from and unified by just one mnemonic to safely store.
- [ ] `breez_sdk`: package to set up a Lightning node, based on Breez SDK, that is compatible with the other packages in this repo.
- [ ] `ldk`: package to set up a Lightning node, based on LDK, in a Flutter app.
Expand Down
3 changes: 1 addition & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,14 @@ linter:
- implementation_imports
- implicit_reopen
- invalid_case_patterns
- iterable_contains_unrelated_type
- collection_methods_unrelated_type
- join_return_with_assignment
- leading_newlines_in_multiline_strings
- library_annotations
- library_names
- library_prefixes
- library_private_types_in_public_api
- lines_longer_than_80_chars
- list_remove_unrelated_type
- literal_only_boolean_expressions
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
Expand Down
2 changes: 2 additions & 0 deletions packages/bip39/lib/bip39.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// Support for bip39.
///
/// Document the library here.
library;

Expand Down
23 changes: 4 additions & 19 deletions packages/bip39/lib/src/bridge_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import 'package:meta/meta.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart';
import 'package:uuid/uuid.dart';

import 'package:collection/collection.dart';

import 'dart:convert';
import 'dart:async';
import 'package:meta/meta.dart';
Expand Down Expand Up @@ -46,7 +44,7 @@ abstract class Bip39 {

FlutterRustBridgeTaskConstMeta get kParseInStaticMethodMnemonicConstMeta;

Future<U8Array64> toSeedMethodMnemonic({required Mnemonic that, required String passphrase, dynamic hint});
Future<Uint8List> toSeedMethodMnemonic({required Mnemonic that, required String passphrase, dynamic hint});

FlutterRustBridgeTaskConstMeta get kToSeedMethodMnemonicConstMeta;
}
Expand Down Expand Up @@ -77,21 +75,12 @@ class Mnemonic {

static Future<Mnemonic> parseIn({required Bip39 bridge, required Language language, required List<String> words, dynamic hint}) => bridge.parseInStaticMethodMnemonic(language: language, words: words, hint: hint);

Future<U8Array64> toSeed({required String passphrase, dynamic hint}) => bridge.toSeedMethodMnemonic(
Future<Uint8List> toSeed({required String passphrase, dynamic hint}) => bridge.toSeedMethodMnemonic(
that: this,
passphrase: passphrase,
);
}

class U8Array64 extends NonGrowableListView<int> {
static const arraySize = 64;
U8Array64(Uint8List inner)
: assert(inner.length == arraySize),
super(inner);
U8Array64.unchecked(Uint8List inner) : super(inner);
U8Array64.init() : super(Uint8List(arraySize));
}

/// Type describing entropy length (aka word count) in the mnemonic
enum WordCount {
/// 12 words mnemonic (128 bits entropy)
Expand Down Expand Up @@ -264,12 +253,12 @@ class Bip39Impl implements Bip39 {
],
);

Future<U8Array64> toSeedMethodMnemonic({required Mnemonic that, required String passphrase, dynamic hint}) {
Future<Uint8List> toSeedMethodMnemonic({required Mnemonic that, required String passphrase, dynamic hint}) {
var arg0 = _platform.api2wire_box_autoadd_mnemonic(that);
var arg1 = _platform.api2wire_String(passphrase);
return _platform.executeNormal(FlutterRustBridgeTask(
callFfi: (port_) => _platform.inner.wire_to_seed__method__Mnemonic(port_, arg0, arg1),
parseSuccessData: _wire2api_u8_array_64,
parseSuccessData: _wire2api_uint_8_list,
constMeta: kToSeedMethodMnemonicConstMeta,
argValues: [
that,
Expand Down Expand Up @@ -326,10 +315,6 @@ class Bip39Impl implements Bip39 {
return raw as int;
}

U8Array64 _wire2api_u8_array_64(dynamic raw) {
return U8Array64(_wire2api_uint_8_list(raw));
}

Uint8List _wire2api_uint_8_list(dynamic raw) {
return raw as Uint8List;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/bip39/native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ edition = "2021"
crate-type = ["staticlib", "cdylib"]

[build-dependencies]
flutter_rust_bridge_codegen = "1.80.1"
flutter_rust_bridge_codegen = "1.75.2"

[dependencies]
flutter_rust_bridge = "1.80.1"
flutter_rust_bridge = "1.75.2"
bip39 = { version = "2.0.0", features = ["spanish", "rand"] }
hex = "0.4.3"
4 changes: 2 additions & 2 deletions packages/bip39/native/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ impl Mnemonic {
.into()
}

pub fn to_seed(&self, passphrase: String) -> [u8; 64] {
pub fn to_seed(&self, passphrase: String) -> Vec<u8> {
let bip39_mnemonic: bip39::Mnemonic = self.into();
bip39_mnemonic.to_seed(passphrase.as_str())
bip39_mnemonic.to_seed(passphrase.as_str()).to_vec()
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/bip39/native/src/bridge_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn wire_to_seed__method__Mnemonic_impl(
that: impl Wire2Api<Mnemonic> + UnwindSafe,
passphrase: impl Wire2Api<String> + UnwindSafe,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, [u8; 64]>(
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, Vec<u8>>(
WrapInfo {
debug_name: "to_seed__method__Mnemonic",
port: Some(port_),
Expand Down
2 changes: 1 addition & 1 deletion packages/bip39/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ environment:
# Add regular dependencies here.
dependencies:
ffi: ^2.0.2
flutter_rust_bridge: ^1.80.1
flutter_rust_bridge: ^1.75.2
# path: ^1.8.0

dev_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion packages/bip39/test/bip39_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void main() {
'absorb',
'abstract',
'absurd',
'abuse'
'abuse',
],
);
});
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter_bip39/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ android {
path "CMakeLists.txt"
}
}

namespace "dev.kumuly.flutter_bip39"
}

File renamed without changes.
3 changes: 0 additions & 3 deletions packages/flutter_bip39/ios/Classes/flutter_bip39.c

This file was deleted.

Binary file modified packages/flutter_bip39/ios/Frameworks/bip39-v0.0.1.zip
Binary file not shown.
File renamed without changes.
3 changes: 0 additions & 3 deletions packages/flutter_bip39/macos/Classes/flutter_bip39.c

This file was deleted.

Binary file modified packages/flutter_bip39/macos/Frameworks/bip39-v0.0.1.zip
Binary file not shown.
3 changes: 2 additions & 1 deletion packages/flutter_bip39/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ environment:
flutter: ">=3.3.0"

dependencies:
bip39: ^0.0.1
bip39:
path: ../bip39
flutter:
sdk: flutter
plugin_platform_interface: ^2.0.2
Expand Down
30 changes: 0 additions & 30 deletions packages/flutter_lightning_message/.gitignore

This file was deleted.

42 changes: 0 additions & 42 deletions packages/flutter_lightning_message/.metadata

This file was deleted.

3 changes: 0 additions & 3 deletions packages/flutter_lightning_message/CHANGELOG.md

This file was deleted.

1 change: 0 additions & 1 deletion packages/flutter_lightning_message/LICENSE

This file was deleted.

92 changes: 0 additions & 92 deletions packages/flutter_lightning_message/README.md

This file was deleted.

13 changes: 0 additions & 13 deletions packages/flutter_lightning_message/android/.gitignore

This file was deleted.

Loading

0 comments on commit 75d08ec

Please sign in to comment.