add methode to import Cs account
This commit is contained in:
parent
8a30ba70d7
commit
6af9199a76
|
@ -1,3 +1,4 @@
|
||||||
|
import 'dart:typed_data';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:gecko/globals.dart';
|
import 'package:gecko/globals.dart';
|
||||||
|
@ -13,7 +14,8 @@ import 'package:polkawallet_sdk/storage/keyring.dart';
|
||||||
import 'package:polkawallet_sdk/storage/types/keyPairData.dart';
|
import 'package:polkawallet_sdk/storage/types/keyPairData.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:truncate/truncate.dart';
|
import 'package:truncate/truncate.dart';
|
||||||
// import 'package:web_socket_channel/io.dart';
|
import 'package:pointycastle/pointycastle.dart' as pc;
|
||||||
|
import "package:hex/hex.dart";
|
||||||
|
|
||||||
class SubstrateSdk with ChangeNotifier {
|
class SubstrateSdk with ChangeNotifier {
|
||||||
final WalletSDK sdk = WalletSDK();
|
final WalletSDK sdk = WalletSDK();
|
||||||
|
@ -368,6 +370,52 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
return nodeParams;
|
return nodeParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future csToV2(String salt, String password) async {
|
||||||
|
final scrypt = pc.KeyDerivator('scrypt');
|
||||||
|
|
||||||
|
scrypt.init(
|
||||||
|
pc.ScryptParameters(
|
||||||
|
4096,
|
||||||
|
16,
|
||||||
|
1,
|
||||||
|
32,
|
||||||
|
Uint8List.fromList(salt.codeUnits),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final rawSeed = scrypt.process(Uint8List.fromList(password.codeUnits));
|
||||||
|
final rawSeedHex = '0x${HEX.encode(rawSeed)}';
|
||||||
|
|
||||||
|
// final newAddress1 = await sdk.api.keyring.addressFromRawSeed(ss58,
|
||||||
|
// cryptoType: CryptoType.ed25519, rawSeed: '0x$rawSeedString');
|
||||||
|
|
||||||
|
// log.d('csconvert address: ${newAddress1.address}');
|
||||||
|
|
||||||
|
final json = await sdk.api.keyring
|
||||||
|
.importAccount(keyring,
|
||||||
|
keyType: KeyType.rawSeed,
|
||||||
|
key: rawSeedHex,
|
||||||
|
name: 'test',
|
||||||
|
password: 'password',
|
||||||
|
derivePath: '',
|
||||||
|
cryptoType: CryptoType.ed25519)
|
||||||
|
.catchError((e) {
|
||||||
|
importIsLoading = false;
|
||||||
|
notifyListeners();
|
||||||
|
});
|
||||||
|
|
||||||
|
final keypair = await sdk.api.keyring.addAccount(
|
||||||
|
keyring,
|
||||||
|
keyType: KeyType.rawSeed,
|
||||||
|
acc: json!,
|
||||||
|
password: password,
|
||||||
|
);
|
||||||
|
await sdk.api.keyring.deleteAccount(keyring, keypair);
|
||||||
|
|
||||||
|
// final keypair2 = KeyPairData.fromJson(json as Map<String, dynamic>);
|
||||||
|
|
||||||
|
log.d(keypair.address);
|
||||||
|
}
|
||||||
|
|
||||||
Future<String> importAccount(
|
Future<String> importAccount(
|
||||||
{String mnemonic = '',
|
{String mnemonic = '',
|
||||||
String derivePath = '',
|
String derivePath = '',
|
||||||
|
|
|
@ -39,6 +39,8 @@ class HomeScreen extends StatelessWidget {
|
||||||
|
|
||||||
final bool isWalletsExists = myWalletProvider.checkIfWalletExist();
|
final bool isWalletsExists = myWalletProvider.checkIfWalletExist();
|
||||||
|
|
||||||
|
// sub.csToV2('test', 'test');
|
||||||
|
|
||||||
isTall = false;
|
isTall = false;
|
||||||
ratio = 1;
|
ratio = 1;
|
||||||
if (MediaQuery.of(context).size.height >= 930) {
|
if (MediaQuery.of(context).size.height >= 930) {
|
||||||
|
|
|
@ -557,7 +557,7 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0"
|
version: "2.1.0"
|
||||||
hex:
|
hex:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: hex
|
name: hex
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
|
@ -1052,7 +1052,7 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.2"
|
version: "2.1.2"
|
||||||
pointycastle:
|
pointycastle:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: pointycastle
|
name: pointycastle
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
|
|
|
@ -71,6 +71,8 @@ dependencies:
|
||||||
easy_localization: ^3.0.1
|
easy_localization: ^3.0.1
|
||||||
flutter_markdown: ^0.6.10+2
|
flutter_markdown: ^0.6.10+2
|
||||||
dropdown_button2: ^1.6.3
|
dropdown_button2: ^1.6.3
|
||||||
|
pointycastle: ^3.6.1
|
||||||
|
hex: ^0.2.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
# flutter_launcher_icons: ^0.9.2
|
# flutter_launcher_icons: ^0.9.2
|
||||||
|
|
Loading…
Reference in New Issue