Skip to content

Commit

Permalink
feat: seed detail (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Egor Komarov <[email protected]>
  • Loading branch information
Odrin and Egor Komarov authored Jun 27, 2023
1 parent 048b0bf commit 323aa01
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
13 changes: 13 additions & 0 deletions lib/src/models/key_account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ class KeyAccount extends Equatable {
/// Flag that allows identify if this account is hidden.
final bool isHidden;

/// Proxy getter of name of account
String get name => account.name;

/// Proxy getter of address of account
String get address => account.address;

/// Proxy getter of workchain of account
int get workchain => account.workchain;

/// Proxy getter of additional assets of account
Map<String, AdditionalAssets> get additionalAssets =>
account.additionalAssets;

/// Show this account in wallet page.
Future<void> show() => GetIt.instance<NekotonRepository>()
.storageRepository
Expand Down
12 changes: 11 additions & 1 deletion lib/src/models/seed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ class Seed extends Equatable {
SeedKey? findKeyByPublicKey(String publicKey) =>
allKeys.firstWhereOrNull((key) => key.publicKey == publicKey);

/// Returns list of public keys that can be used in [deriveKeys] from
/// seed with [masterKey] and [password].
/// Returns list of up to 100 public keys, that could be displayed by pages.
/// !!! Seed should not be legacy.
Future<List<String>> getKeysToDerive(String password) =>
GetIt.instance<SeedKeyRepository>().getKeysToDerive(
masterKey: masterKey.publicKey,
password: password,
);

/// Derive keys from [masterKey] this call adds list of sub keys to
/// [subKeys].
/// This method returns list of public keys that allows add additional logic
Expand Down Expand Up @@ -67,7 +77,7 @@ class Seed extends Equatable {
/// Return seeds phrase of this seed.
/// Do not works for ledger key.
Future<List<String>> export(String password) =>
GetIt.instance<SeedKeyRepository>().exportKey(
GetIt.instance<SeedKeyRepository>().exportSeed(
masterKey: masterKey.publicKey,
password: password,
isLegacy: masterKey.isLegacy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import 'package:nekoton_repository/nekoton_repository.dart';
/// This repository can be used as <SeedKeyRepositoryImpl> or you can add
/// custom logic.
abstract class SeedKeyRepository {
/// Returns list of public keys that can be used in [deriveKeys] from
/// seed with [masterKey] and [password].
/// Returns list of up to 100 public keys, that could be displayed by pages.
/// !!! Seed should not be legacy.
Future<List<String>> getKeysToDerive({
required String masterKey,
required String password,
});

/// Derive keys from [masterKey] which is key of seed.
/// !!! This method won't work for legacy keys.
/// This method returns list of public keys that allows add additional logic
Expand Down Expand Up @@ -42,7 +51,7 @@ abstract class SeedKeyRepository {

/// Return seeds phrase of [masterKey].
/// Do not works for ledger key.
Future<List<String>> exportKey({
Future<List<String>> exportSeed({
required String masterKey,
required String password,
required bool isLegacy,
Expand Down
24 changes: 23 additions & 1 deletion lib/src/repositories/seed_repository/seed_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'dart:async';
import 'package:get_it/get_it.dart';
import 'package:nekoton_repository/nekoton_repository.dart';

const _maxDeriveKeys = 100;

/// Implementation of SeedRepository.
/// Usage
/// ```
Expand All @@ -14,6 +16,26 @@ mixin SeedKeyRepositoryImpl on TransportRepository

NekotonStorageRepository get storageRepository;

@override
Future<List<String>> getKeysToDerive({
required String masterKey,
required String password,
}) {
return keyStore.getPublicKeys(
DerivedKeyGetPublicKeys(
masterKey: masterKey,
offset: 0,
limit: _maxDeriveKeys,
password: Password.explicit(
PasswordExplicit(
password: password,
cacheBehavior: const PasswordCacheBehavior.nop(),
),
),
),
);
}

@override
Future<List<String>> deriveKeys({
required List<int> accountIds,
Expand Down Expand Up @@ -209,7 +231,7 @@ mixin SeedKeyRepositoryImpl on TransportRepository
}

@override
Future<List<String>> exportKey({
Future<List<String>> exportSeed({
required String masterKey,
required String password,
required bool isLegacy,
Expand Down

0 comments on commit 323aa01

Please sign in to comment.