WIP: Work about derivation: Can't get seed from stored keypair
This commit is contained in:
parent
90c0765c91
commit
981094ab0e
|
@ -1,4 +1,7 @@
|
|||
// ignore_for_file: avoid_print
|
||||
|
||||
import 'dart:convert';
|
||||
import "package:hex/hex.dart";
|
||||
import 'dart:io';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:fast_base58/fast_base58.dart';
|
||||
|
@ -9,7 +12,12 @@ import 'package:polkawallet_sdk/api/types/networkParams.dart';
|
|||
import 'package:polkawallet_sdk/api/types/txInfoData.dart';
|
||||
import 'package:polkawallet_sdk/polkawallet_sdk.dart';
|
||||
import 'package:polkawallet_sdk/storage/keyring.dart';
|
||||
import 'package:polkawallet_sdk/storage/localStorage.dart';
|
||||
import 'package:polkawallet_sdk/utils/index.dart';
|
||||
import 'package:polkawallet_sdk/utils/localStorage.dart';
|
||||
import 'package:truncate/truncate.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
import 'package:aes_ecb_pkcs5_flutter/aes_ecb_pkcs5_flutter.dart';
|
||||
|
||||
class SubstrateSdk with ChangeNotifier {
|
||||
final List subNode = ['127.0.0.1:9944', '192.168.1.85:9944'];
|
||||
|
@ -65,7 +73,8 @@ class SubstrateSdk with ChangeNotifier {
|
|||
});
|
||||
}
|
||||
|
||||
Future<bool> importAccount({bool fromMnemonic = false}) async {
|
||||
Future<bool> importAccount(
|
||||
{bool fromMnemonic = false, String derivePath = ''}) async {
|
||||
final KeyType keytype;
|
||||
final String keyToImport;
|
||||
if (fromMnemonic) {
|
||||
|
@ -80,19 +89,19 @@ class SubstrateSdk with ChangeNotifier {
|
|||
notifyListeners();
|
||||
final clipboardData = await Clipboard.getData(Clipboard.kTextPlain);
|
||||
if (clipboardData?.text != null) jsonKeystore.text = clipboardData!.text!;
|
||||
final json = await sdk.api.keyring
|
||||
.importAccount(
|
||||
keyring,
|
||||
keyType: keytype,
|
||||
key: keyToImport,
|
||||
name: 'testKey',
|
||||
password: keystorePassword.text,
|
||||
)
|
||||
var json = await sdk.api.keyring
|
||||
.importAccount(keyring,
|
||||
keyType: keytype,
|
||||
key: keyToImport,
|
||||
name: 'testKey',
|
||||
password: keystorePassword.text,
|
||||
derivePath: derivePath)
|
||||
.catchError((e) {
|
||||
importIsLoading = false;
|
||||
notifyListeners();
|
||||
});
|
||||
if (json == null) return false;
|
||||
print(json);
|
||||
try {
|
||||
final acc = await sdk.api.keyring.addAccount(
|
||||
keyring,
|
||||
|
@ -178,6 +187,46 @@ class SubstrateSdk with ChangeNotifier {
|
|||
print(err.toString());
|
||||
}
|
||||
}
|
||||
|
||||
derive(BuildContext context, String address, double amount,
|
||||
String password) async {
|
||||
final keypair =
|
||||
keyring.keyPairs.firstWhere((element) => element.address == address);
|
||||
|
||||
// KeyringStorage _storage = KeyringStorage();
|
||||
// print(_storage.encryptedMnemonics.val);
|
||||
|
||||
// final keyPairs = [].val('keyPairs', getBox: _storage);
|
||||
// final encryptedRawSeeds = {}.val('encryptedRawSeeds', getBox: _storage);
|
||||
|
||||
print(await sdk.api.keyring.getDecryptedSeed(keyring, password));
|
||||
print(await keyring.store.getDecryptedSeed(keypair.pubKey, password));
|
||||
print(
|
||||
await keyring.store.checkSeedExist(KeyType.keystore, keypair.pubKey!));
|
||||
|
||||
print(
|
||||
await keyring.store.checkSeedExist(KeyType.mnemonic, keypair.pubKey!));
|
||||
|
||||
_storage() => GetStorage(sdk_storage_key);
|
||||
final encryptedMnemonics = {}.val('encryptedMnemonics', getBox: _storage);
|
||||
|
||||
// await keyring.store.updateEncryptedSeed(keypair.pubKey, password, '012');
|
||||
final enc = encryptedMnemonics.val[keypair.pubKey!];
|
||||
// final key = Encrypt.passwordToEncryptKey(password);
|
||||
// const enc =
|
||||
// '69E16A6F8CD15799FC036B3D71FC3C53EFCEDB6A2D4F2A743555809DC5B48D6FC25E96E5CFF8E7DF4FCE1AE9AFC61A0D85CDCAD945C5371F11DEBA1BF362B8124A4C8D264A05AC1D72F5A9566D0D3B35';
|
||||
|
||||
final LocalStorage _storageOld = LocalStorage();
|
||||
|
||||
print(enc);
|
||||
print(await _storageOld.getAccountList());
|
||||
print(await _storageOld.getSeeds('keystore'));
|
||||
// print(await FlutterAesEcbPkcs5.decryptString(enc, key));
|
||||
|
||||
// generatedMnemonic = keypair.encoded;
|
||||
|
||||
// importAccount();
|
||||
}
|
||||
}
|
||||
|
||||
void snack(BuildContext context, String message, {int duration = 2}) {
|
||||
|
|
|
@ -32,11 +32,9 @@ class SubstrateSandBox extends StatelessWidget {
|
|||
children: <Widget>[
|
||||
Text('js-api chargé ?: ${_sub.sdkReady}'),
|
||||
InkWell(
|
||||
onTap: !_sub.nodeConnected
|
||||
? () async {
|
||||
onTap: () async {
|
||||
await _sub.connectNode();
|
||||
}
|
||||
: null,
|
||||
},
|
||||
child: Text(
|
||||
'Noeud connecté ?: ${_sub.nodeConnected} (${_sub.subNode})')),
|
||||
if (_sub.nodeConnected)
|
||||
|
@ -63,29 +61,39 @@ class SubstrateSandBox extends StatelessWidget {
|
|||
builder: (BuildContext context,
|
||||
AsyncSnapshot<List<AddressInfo>> _data) {
|
||||
return Column(children: [
|
||||
for (final AddressInfo e in _data.data!)
|
||||
Row(children: [
|
||||
InkWell(
|
||||
onTap: () => _sub.keyring.setCurrent(_sub
|
||||
.keyring.keyPairs
|
||||
.firstWhere((element) =>
|
||||
element.address == e.address!)),
|
||||
child: Text(
|
||||
getShortPubkey(e.address!),
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Monospace'),
|
||||
if (_data.data != null)
|
||||
for (final AddressInfo e in _data.data!)
|
||||
Row(children: [
|
||||
InkWell(
|
||||
onTap: () => _sub.keyring.setCurrent(_sub
|
||||
.keyring.keyPairs
|
||||
.firstWhere((element) =>
|
||||
element.address == e.address!)),
|
||||
child: Text(
|
||||
getShortPubkey(e.address!),
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Monospace'),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
InkWell(
|
||||
onTap: () async => await _sub.pay(
|
||||
context,
|
||||
e.address!,
|
||||
10,
|
||||
_sub.keystorePassword.text),
|
||||
child: Text("${e.balance.toString()} ğdev"),
|
||||
)
|
||||
])
|
||||
const SizedBox(width: 20),
|
||||
InkWell(
|
||||
onTap: () async => await _sub.pay(
|
||||
context,
|
||||
e.address!,
|
||||
10,
|
||||
_sub.keystorePassword.text),
|
||||
child: Text("${e.balance.toString()} ğdev"),
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
InkWell(
|
||||
onTap: () async => await _sub.derive(
|
||||
context,
|
||||
e.address!,
|
||||
3,
|
||||
_sub.keystorePassword.text),
|
||||
child: const Text("Dériver"),
|
||||
)
|
||||
])
|
||||
]);
|
||||
}),
|
||||
const SizedBox(height: 20),
|
||||
|
|
Loading…
Reference in New Issue