cake_wallet/lib/nano/nano.dart

123 lines
4.5 KiB
Dart
Raw Permalink Normal View History

2023-11-20 16:50:54 +00:00
import 'package:cw_core/cake_hive.dart';
2023-08-10 22:34:20 +00:00
import 'package:cw_core/nano_account.dart';
2023-08-04 18:11:09 +00:00
import 'package:cw_core/account.dart';
2023-11-20 16:50:54 +00:00
import 'package:cw_core/node.dart';
2023-07-24 18:09:28 +00:00
import 'package:cw_core/wallet_credentials.dart';
import 'package:cw_core/wallet_info.dart';
2023-11-20 16:50:54 +00:00
import 'package:cw_core/transaction_info.dart';
2023-07-24 20:23:09 +00:00
import 'package:cw_core/transaction_history.dart';
2023-07-24 18:09:28 +00:00
import 'package:cw_core/wallet_service.dart';
2023-08-02 17:16:43 +00:00
import 'package:cw_core/output_info.dart';
2023-11-20 16:50:54 +00:00
import 'package:cw_core/nano_account_info_response.dart';
import 'package:mobx/mobx.dart';
2023-07-24 18:09:28 +00:00
import 'package:hive/hive.dart';
2023-11-20 16:50:54 +00:00
import 'package:cake_wallet/view_model/send/output.dart';
import 'package:cw_nano/nano_client.dart';
import 'package:cw_nano/nano_mnemonic.dart';
import 'package:cw_nano/nano_wallet.dart';
import 'package:cw_nano/nano_wallet_service.dart';
import 'package:cw_nano/nano_transaction_info.dart';
2023-07-31 13:10:33 +00:00
import 'package:cw_nano/nano_transaction_credentials.dart';
2023-09-06 14:12:36 +00:00
import 'package:cw_nano/nano_wallet_creation_credentials.dart';
2023-11-20 16:50:54 +00:00
// needed for nano_util:
import 'dart:convert';
import 'dart:typed_data';
import 'package:convert/convert.dart';
import "package:ed25519_hd_key/ed25519_hd_key.dart";
import 'package:libcrypto/libcrypto.dart';
import 'package:nanodart/nanodart.dart' as ND;
import 'package:decimal/decimal.dart';
2023-07-24 18:09:28 +00:00
part 'cw_nano.dart';
Nano? nano = CWNano();
2023-11-20 16:50:54 +00:00
NanoUtil? nanoUtil = CWNanoUtil();
2023-07-24 18:09:28 +00:00
abstract class Nano {
2023-08-10 22:34:20 +00:00
NanoAccountList getAccountList(Object wallet);
Account getCurrentAccount(Object wallet);
void setCurrentAccount(Object wallet, int id, String label, String? balance);
2023-07-24 20:23:09 +00:00
2023-07-24 18:09:28 +00:00
WalletService createNanoWalletService(Box<WalletInfo> walletInfoSource);
2023-07-24 20:23:09 +00:00
WalletCredentials createNanoNewWalletCredentials({
required String name,
String password,
2023-07-24 18:09:28 +00:00
});
2023-08-14 22:02:12 +00:00
2023-07-25 20:31:52 +00:00
WalletCredentials createNanoRestoreWalletFromSeedCredentials({
required String name,
required String password,
2023-07-31 13:10:33 +00:00
required String mnemonic,
DerivationType? derivationType,
2023-07-25 20:31:52 +00:00
});
WalletCredentials createNanoRestoreWalletFromKeysCredentials({
required String name,
required String password,
required String seedKey,
DerivationType? derivationType,
});
2023-07-24 20:23:09 +00:00
List<String> getNanoWordList(String language);
2023-07-31 15:39:22 +00:00
Map<String, String> getKeys(Object wallet);
2023-07-31 13:10:33 +00:00
Object createNanoTransactionCredentials(List<Output> outputs);
2023-11-20 16:50:54 +00:00
Future<void> changeRep(Object wallet, String address);
Future<void> updateTransactions(Object wallet);
BigInt getTransactionAmountRaw(TransactionInfo transactionInfo);
String getRepresentative(Object wallet);
2023-07-24 20:23:09 +00:00
}
abstract class NanoAccountList {
2023-08-10 22:34:20 +00:00
ObservableList<NanoAccount> get accounts;
2023-07-24 20:23:09 +00:00
void update(Object wallet);
void refresh(Object wallet);
2023-08-10 22:34:20 +00:00
Future<List<NanoAccount>> getAll(Object wallet);
2023-07-24 20:23:09 +00:00
Future<void> addAccount(Object wallet, {required String label});
Future<void> setLabelAccount(Object wallet, {required int accountIndex, required String label});
2023-07-24 18:09:28 +00:00
}
2023-11-20 16:50:54 +00:00
abstract class NanoUtil {
String seedToPrivate(String seed, int index);
String seedToAddress(String seed, int index);
String seedToMnemonic(String seed);
Future<String> mnemonicToSeed(String mnemonic);
String privateKeyToPublic(String privateKey);
String addressToPublicKey(String publicAddress);
String privateKeyToAddress(String privateKey);
String publicKeyToAddress(String publicKey);
bool isValidSeed(String seed);
Future<String> hdMnemonicListToSeed(List<String> words);
Future<String> hdSeedToPrivate(String seed, int index);
Future<String> hdSeedToAddress(String seed, int index);
Future<String> uniSeedToAddress(String seed, int index, String type);
Future<String> uniSeedToPrivate(String seed, int index, String type);
bool isValidBip39Seed(String seed);
static const int maxDecimalDigits = 6; // Max digits after decimal
BigInt rawPerNano = BigInt.parse("1000000000000000000000000000000");
BigInt rawPerNyano = BigInt.parse("1000000000000000000000000");
BigInt rawPerBanano = BigInt.parse("100000000000000000000000000000");
BigInt rawPerXMR = BigInt.parse("1000000000000");
BigInt convertXMRtoNano = BigInt.parse("1000000000000000000");
String getRawAsDecimalString(String? raw, BigInt? rawPerCur);
String getRawAsUsableString(String? raw, BigInt rawPerCur);
String getRawAccuracy(String? raw, BigInt rawPerCur);
String getAmountAsRaw(String amount, BigInt rawPerCur);
// derivationInfo:
Future<AccountInfoResponse?> getInfoFromSeedOrMnemonic(
DerivationType derivationType, {
String? seedKey,
String? mnemonic,
required Node node,
});
Future<List<DerivationType>> compareDerivationMethods({
String? mnemonic,
String? privateKey,
required Node node,
});
}
2023-08-14 22:02:12 +00:00