mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-02-02 03:06:29 +00:00
Merge pull request #217 from cypherstack/cryptonote/validation
Use native address validation for cryptonote coins
This commit is contained in:
commit
939e241f61
5 changed files with 41 additions and 19 deletions
|
@ -1 +1 @@
|
|||
Subproject commit b9bc2dcc56e13f235a6c5b0fc02c0e543eb87758
|
||||
Subproject commit 2da77438527732dfaa5398aa391eab5253dabe19
|
|
@ -1353,10 +1353,8 @@ class MoneroWallet extends CoinServiceAPI {
|
|||
Future<List<UtxoObject>> get unspentOutputs => throw UnimplementedError();
|
||||
|
||||
@override
|
||||
// TODO: implement validateAddress
|
||||
bool validateAddress(String address) {
|
||||
bool valid = RegExp("[a-zA-Z0-9]{95}").hasMatch(address) ||
|
||||
RegExp("[a-zA-Z0-9]{106}").hasMatch(address);
|
||||
bool valid = walletBase!.validateAddress(address);
|
||||
return valid;
|
||||
}
|
||||
|
||||
|
|
|
@ -1378,10 +1378,8 @@ class WowneroWallet extends CoinServiceAPI {
|
|||
Future<List<UtxoObject>> get unspentOutputs => throw UnimplementedError();
|
||||
|
||||
@override
|
||||
// TODO: implement validateAddress
|
||||
bool validateAddress(String address) {
|
||||
bool valid = RegExp("[a-zA-Z0-9]{95}").hasMatch(address) ||
|
||||
RegExp("[a-zA-Z0-9]{106}").hasMatch(address);
|
||||
bool valid = walletBase!.validateAddress(address);
|
||||
return valid;
|
||||
}
|
||||
|
||||
|
|
|
@ -90,12 +90,12 @@ void main() async {
|
|||
final dirPath = await pathForWalletDir(name: name, type: type);
|
||||
path = await pathForWallet(name: name, type: type);
|
||||
credentials =
|
||||
// // creating a new wallet
|
||||
// monero.createMoneroNewWalletCredentials(
|
||||
// name: name, language: "English");
|
||||
// restoring a previous wallet
|
||||
monero.createMoneroRestoreWalletFromSeedCredentials(
|
||||
name: name, height: 2580000, mnemonic: testMnemonic);
|
||||
// // creating a new wallet
|
||||
// monero.createMoneroNewWalletCredentials(
|
||||
// name: name, language: "English");
|
||||
// restoring a previous wallet
|
||||
monero.createMoneroRestoreWalletFromSeedCredentials(
|
||||
name: name, height: 2580000, mnemonic: testMnemonic);
|
||||
|
||||
walletInfo = WalletInfo.external(
|
||||
id: WalletBase.idFor(name, type),
|
||||
|
@ -124,8 +124,8 @@ void main() async {
|
|||
|
||||
test("Test mainnet address generation from seed", () async {
|
||||
final wallet = await
|
||||
// _walletCreationService.create(credentials);
|
||||
_walletCreationService.restoreFromSeed(credentials);
|
||||
// _walletCreationService.create(credentials);
|
||||
_walletCreationService.restoreFromSeed(credentials);
|
||||
walletInfo.address = wallet.walletAddresses.address;
|
||||
//print(walletInfo.address);
|
||||
|
||||
|
@ -134,6 +134,9 @@ void main() async {
|
|||
walletBase = wallet as MoneroWalletBase;
|
||||
//print("${walletBase?.seed}");
|
||||
|
||||
expect(
|
||||
await walletBase!.validateAddress(walletInfo.address ?? ''), true);
|
||||
|
||||
// print(walletBase);
|
||||
// loggerPrint(walletBase.toString());
|
||||
// loggerPrint("name: ${walletBase!.name} seed: ${walletBase!.seed} id: "
|
||||
|
@ -153,6 +156,21 @@ void main() async {
|
|||
await walletBase!.getTransactionAddress(1, 1), mainnetTestData[1][1]);
|
||||
expect(
|
||||
await walletBase!.getTransactionAddress(1, 2), mainnetTestData[1][2]);
|
||||
|
||||
expect(
|
||||
await walletBase!.validateAddress(''), false);
|
||||
expect(
|
||||
await walletBase!.validateAddress('4AeRgkWZsMJhAWKMeCZ3h4ZSPnAcW5VBtRFyLd6gBEf6GgJU2FHXDA6i1DnQTd6h8R3VU5AkbGcWSNhtSwNNPgaD48gp4nn'), true);
|
||||
expect(
|
||||
await walletBase!.validateAddress('4asdfkWZsMJhAWKMeCZ3h4ZSPnAcW5VBtRFyLd6gBEf6GgJU2FHXDA6i1DnQTd6h8R3VU5AkbGcWSNhtSwNNPgaD48gpjkl'), false);
|
||||
expect(
|
||||
await walletBase!.validateAddress('8AeRgkWZsMJhAWKMeCZ3h4ZSPnAcW5VBtRFyLd6gBEf6GgJU2FHXDA6i1DnQTd6h8R3VU5AkbGcWSNhtSwNNPgaD48gp4nn'), false);
|
||||
expect(
|
||||
await walletBase!.validateAddress('84kYPuZ1eaVKGQhf26QPNWbSLQG16BywXdLYYShVrPNMLAUAWce5vcpRc78FxwRphrG6Cda7faCKdUMr8fUCH3peHPenvHy'), true);
|
||||
expect(
|
||||
await walletBase!.validateAddress('8asdfuZ1eaVKGQhf26QPNWbSLQG16BywXdLYYShVrPNMLAUAWce5vcpRc78FxwRphrG6Cda7faCKdUMr8fUCH3peHPenjkl'), false);
|
||||
expect(
|
||||
await walletBase!.validateAddress('44kYPuZ1eaVKGQhf26QPNWbSLQG16BywXdLYYShVrPNMLAUAWce5vcpRc78FxwRphrG6Cda7faCKdUMr8fUCH3peHPenvHy'), false);
|
||||
});
|
||||
});
|
||||
/*
|
||||
|
@ -211,6 +229,6 @@ Future<String> pathForWalletDir(
|
|||
}
|
||||
|
||||
Future<String> pathForWallet(
|
||||
{required String name, required WalletType type}) async =>
|
||||
{required String name, required WalletType type}) async =>
|
||||
await pathForWalletDir(name: name, type: type)
|
||||
.then((path) => path + '/$name');
|
||||
|
|
|
@ -126,13 +126,21 @@ void main() async {
|
|||
walletBase?.close();
|
||||
walletBase = wallet as WowneroWalletBase;
|
||||
|
||||
// TODO validate
|
||||
//expect(walletInfo.address, mainnetTestData14[0][0]);
|
||||
expect(
|
||||
await walletBase!.validateAddress(wallet.walletAddresses.address ?? ''), true);
|
||||
} catch (_) {
|
||||
hasThrown = true;
|
||||
}
|
||||
expect(hasThrown, false);
|
||||
|
||||
// Address validation
|
||||
expect(
|
||||
await walletBase!.validateAddress(''), false);
|
||||
expect(
|
||||
await walletBase!.validateAddress('Wo3jmHvTMLwE6h29fpgcb8PbJSpaKuqM7XTXVfiiu8bLCZsJvrQCbQSJR48Vo3BWNQKsMsXZ4VixndXTH25QtorC27NCjmsEi'), true);
|
||||
expect(
|
||||
await walletBase!.validateAddress('WasdfHvTMLwE6h29fpgcb8PbJSpaKuqM7XTXVfiiu8bLCZsJvrQCbQSJR48Vo3BWNQKsMsXZ4VixndXTH25QtorC27NCjmjkl'), false);
|
||||
|
||||
walletBase?.close();
|
||||
walletBase = wallet as WowneroWalletBase;
|
||||
});
|
||||
|
@ -359,6 +367,6 @@ Future<String> pathForWalletDir(
|
|||
}
|
||||
|
||||
Future<String> pathForWallet(
|
||||
{required String name, required WalletType type}) async =>
|
||||
{required String name, required WalletType type}) async =>
|
||||
await pathForWalletDir(name: name, type: type)
|
||||
.then((path) => path + '/$name');
|
||||
|
|
Loading…
Reference in a new issue