Generic fixes (#1427)
* fix for private key solana * Fix Solana wallet open
Omar Hatem committed
May 4, 2024 at 15:35 UTC
043d7d7c8bcfa2e85ea9ad6b0c6bfef9bca40a00
1 file changed
+10
-5
cw_solana/lib/solana_wallet.dart
+10
-5
@@ -145,12 +145,17 @@ abstract class SolanaWalletBase
145
Future<Wallet> getWalletPair({String? mnemonic, String? privateKey}) async {
146
assert(mnemonic != null || privateKey != null);
147
148
- if (privateKey != null) {
149
- final privateKeyBytes = base58decode(privateKey);
150
- return await Wallet.fromPrivateKeyBytes(privateKey: privateKeyBytes.take(32).toList());
148
+ if (mnemonic != null) {
149
+ return Wallet.fromMnemonic(mnemonic, account: 0, change: 0);
150
}
151
153
- return Wallet.fromMnemonic(mnemonic!, account: 0, change: 0);
152
+ try {
153
+ final privateKeyBytes = base58decode(privateKey!);
154
+ return await Wallet.fromPrivateKeyBytes(privateKey: privateKeyBytes.take(32).toList());
155
+ } catch (_) {
156
+ final privateKeyBytes = HEX.decode(privateKey!);
157
+ return await Wallet.fromPrivateKeyBytes(privateKey: privateKeyBytes);
158
+ }
159
}
160
161
@override
@@ -360,7 +365,7 @@ abstract class SolanaWalletBase
365
366
String toJSON() => json.encode({
367
'mnemonic': _mnemonic,
363
- 'private_key': privateKey,
368
+ 'private_key': _hexPrivateKey,
369
'balance': balance[currency]!.toJSON(),
370
});
371