Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1020f28
Initial
dev2-nomo Jan 9, 2025
2c9c78c
Initial
dev2-nomo Jan 9, 2025
bcc503a
Migrate to builtIn HDNode insteaf of bip32
dev2-nomo Jan 13, 2025
610a5e6
Fix Lint
dev2-nomo Jan 13, 2025
d65d3de
Fix Pipe
dev2-nomo Jan 13, 2025
e02dc68
Refactor derivation functions to use NetworkNodeInfo and simplify par…
dev2-nomo Jan 13, 2025
b2ad177
Add command framework with Help and Exit commands to CLI Example
dev2-nomo Jan 13, 2025
0659823
Bip39 impl (#141)
dev2-nomo Jan 30, 2025
13540e8
Update http package to version 1.3.0 and SDK constraint to 3.3.0
dev2-nomo Jan 30, 2025
ae830e8
Merge branch 'main' of https://github.com/nomo-app/walletkit-dart int…
dev2-nomo Jan 30, 2025
ae29d9f
Fix Lint
dev2-nomo Jan 30, 2025
dbda488
test: Enhance BIP39 tests to validate extended private key generation
dev2-nomo Jan 30, 2025
3731128
refactor: Comment out mnemonic generation test for word 'arm'
dev2-nomo Jan 30, 2025
353d1f0
feat: Add TODO for future test cases in multiple languages
dev2-nomo Jan 30, 2025
a48eac4
Update sdk
dev2-nomo Mar 20, 2025
806441e
Merge branch 'main' of https://github.com/nomo-app/walletkit-dart int…
dev2-nomo Mar 20, 2025
db65476
Segwit fee fix (#149)
dev2-nomo Mar 20, 2025
4997ead
Initial (#130)
nomo-app Mar 20, 2025
8137b73
format
dev2-nomo Mar 20, 2025
41abf45
Add cursorignore
dev2-nomo Mar 24, 2025
fea2619
Update Readme and add License
dev2-nomo Mar 24, 2025
d94e931
Start Refactor
dev2-nomo Mar 24, 2025
602f9d0
Fix Imports
dev2-nomo Mar 26, 2025
8b8c9b0
Fix Input Output Length Byte
ThomasFercher Sep 26, 2025
b700dbd
Wallet Impl First Try
ThomasFercher Sep 28, 2025
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
2 changes: 2 additions & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ jobs:
"test/ci/sending",
"test/ci/tron",
"test/ci/rlp",
"test/ci/bip39",
"test/ci/bip32",
]
steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

43 changes: 43 additions & 0 deletions example/command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'dart:async';

abstract class Command<T> {
String get name;
String get description;
FutureOr<T> execute(List<String> args);
}

class CommandResult<T> {
final bool success;
final T? data;
final String? error;

CommandResult.success(this.data)
: success = true,
error = null;
CommandResult.failure(this.error)
: success = false,
data = null;

@override
String toString() {
if (success) {
return data?.toString() ?? 'Command completed successfully';
} else {
return 'Error: ${error ?? "Unknown error"}';
}
}
}

class CommandRegistry {
final Map<String, Command> _commands = {};

void register(Command command) {
_commands[command.name.toLowerCase()] = command;
}
Comment on lines +34 to +36
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add duplicate command name validation.

The register method should check for existing commands with the same name (case-insensitive) to prevent overwriting.

  void register(Command command) {
+   ArgumentError.checkNotNull(command, 'command');
+   final normalizedName = command.name.toLowerCase();
+   if (_commands.containsKey(normalizedName)) {
+     throw ArgumentError('Command "${command.name}" is already registered');
+   }
-   _commands[command.name.toLowerCase()] = command;
+   _commands[normalizedName] = command;
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void register(Command command) {
_commands[command.name.toLowerCase()] = command;
}
void register(Command command) {
ArgumentError.checkNotNull(command, 'command');
final normalizedName = command.name.toLowerCase();
if (_commands.containsKey(normalizedName)) {
throw ArgumentError('Command "${command.name}" is already registered');
}
_commands[normalizedName] = command;
}


Command? get(String name) {
return _commands[name.toLowerCase()];
}

List<Command> get commands => _commands.values.toList();
}
38 changes: 38 additions & 0 deletions example/commands.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'dart:io';

import 'command.dart';

class HelpCommand extends Command<String> {
final CommandRegistry registry;

HelpCommand(this.registry);

@override
String get name => 'help';

@override
String get description => 'Show available commands';

@override
String execute(List<String> args) {
final buffer = StringBuffer('Available commands:\n');
for (final command in registry.commands) {
buffer.writeln(' ${command.name.padRight(10)} - ${command.description}');
}
return buffer.toString();
}
}

class ExitCommand extends Command<void> {
@override
String get name => 'exit';

@override
String get description => 'Exit the application';

@override
Future<void> execute(List<String> args) async {
print('Goodbye!');
exit(0);
}
}
Comment on lines +26 to +38
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Implement graceful shutdown.

The ExitCommand uses exit(0) which abruptly terminates the application. Consider implementing a graceful shutdown that allows cleanup of resources.

  @override
  Future<void> execute(List<String> args) async {
    print('Goodbye!');
-   exit(0);
+   // Signal the application to start cleanup
+   return Future.value();
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
class ExitCommand extends Command<void> {
@override
String get name => 'exit';
@override
String get description => 'Exit the application';
@override
Future<void> execute(List<String> args) async {
print('Goodbye!');
exit(0);
}
}
class ExitCommand extends Command<void> {
@override
String get name => 'exit';
@override
String get description => 'Exit the application';
@override
Future<void> execute(List<String> args) async {
print('Goodbye!');
// Signal the application to start cleanup
return Future.value();
}
}

1 change: 0 additions & 1 deletion example/web3_kit_example.dart

This file was deleted.

105 changes: 105 additions & 0 deletions example/wkdart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import 'dart:convert';
import 'dart:io';

Comment on lines +2 to +3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add necessary wallet-related imports and error handling.

As this is a wallet interface implementation, the file should import the necessary wallet-related modules and implement proper error handling for I/O operations.

Consider adding:

 import 'dart:io';
+import 'package:walletkit_dart/walletkit_dart.dart';
+import 'dart:async';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import 'dart:io';
import 'dart:io';
import 'package:walletkit_dart/walletkit_dart.dart';
import 'dart:async';

import 'command.dart';
import 'commands.dart';

class WalletCLI {
final CommandRegistry registry = CommandRegistry();
final String prompt = 'wk> ';

WalletCLI() {
registry.register(ExitCommand());
registry.register(HelpCommand(registry));
}

// Custom print function that adds the prompt
void printWithPrompt(String message, {bool withPrompt = true}) {
// Split message into lines and add prompt to each line
final lines = message.split('\n');
for (final line in lines) {
if (withPrompt) {
stdout.writeln('$prompt$line');
} else {
stdout.writeln(line);
}
}
}

void showPrompt() {
stdout.write(prompt);
}

Future<void> run() async {
printWithPrompt('Welcome to WalletkitDart CLI');
printWithPrompt('Type "help" for available commands');
printWithPrompt('Enter commands:');
showPrompt();

final inputStream = stdin
.transform(utf8.decoder)
.transform(const LineSplitter())
.asBroadcastStream();

Comment on lines +39 to +43
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Implement stream subscription cleanup.

The broadcast stream subscription should be stored and cleaned up when the CLI is terminated.

+ StreamSubscription<String>? _inputSubscription;
+
  Future<void> run() async {
    // ... existing code ...
-   inputStream.listen(
+   _inputSubscription = inputStream.listen(
      // ... existing code ...
    );
  }

+ Future<void> cleanup() async {
+   await _inputSubscription?.cancel();
+   _inputSubscription = null;
+ }

Committable suggestion skipped: line range outside the PR's diff.

inputStream.listen(
(String line) async {
await handleInput(line.trim());
},
onError: (error) {
printWithPrompt('Error reading input: $error');
showPrompt();
},
onDone: () {
printWithPrompt('Input stream closed');
exit(0);
},
);

startPeriodicTask();

await Future.delayed(Duration.zero);
}

Future<void> handleInput(String input) async {
if (input.isEmpty) {
showPrompt();
return;
}

final parts = input.split(' ');
final commandName = parts[0].toLowerCase();
final args = parts.skip(1).toList();

final command = registry.get(commandName);
if (command == null) {
printWithPrompt('Unknown command: $commandName');
printWithPrompt('Type "help" for available commands');
showPrompt();
return;
}

try {
final result = await command.execute(args);
if (result != null) {
printWithPrompt(result.toString());
}
showPrompt();
} catch (e) {
printWithPrompt('Error executing command: $e');
showPrompt();
}
}

void startPeriodicTask() {
/// TODO: Start Wallet sync based on args
}

void registerCommand(Command command) {
registry.register(command);
}
}

void main() async {
final app = WalletCLI();
await app.run();
}
Comment on lines +102 to +105
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add signal handling for graceful shutdown.

Implement signal handling to ensure proper cleanup when the application is terminated.

 void main() async {
   final app = WalletCLI();
+  ProcessSignal.sigint.watch().listen((_) async {
+    print('\nReceived SIGINT, shutting down...');
+    await app.cleanup();
+    exit(0);
+  });
   await app.run();
 }

Committable suggestion skipped: line range outside the PR's diff.

1 change: 0 additions & 1 deletion lib/src/crypto/evm/repositories/rpc/evm_rpc_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:typed_data';
import 'package:walletkit_dart/src/common/logger.dart';
import 'package:walletkit_dart/src/crypto/evm/entities/block_number.dart';
import 'package:walletkit_dart/src/crypto/evm/repositories/rpc/queued_rpc_interface.dart';
import 'package:walletkit_dart/src/domain/exceptions.dart';
import 'package:walletkit_dart/src/utils/int.dart';
import 'package:walletkit_dart/walletkit_dart.dart';

Expand Down
1 change: 0 additions & 1 deletion lib/src/crypto/evm/utils/signing.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:convert';
import 'dart:typed_data';
import 'package:hex/hex.dart';
import 'package:walletkit_dart/src/domain/exceptions.dart';
import 'package:walletkit_dart/src/utils/keccak.dart';
import 'package:walletkit_dart/walletkit_dart.dart';

Expand Down
Loading
Loading