Skip to content

Commit

Permalink
Merge pull request #8 from EjaraApp/android-validate-address
Browse files Browse the repository at this point in the history
validate address android
  • Loading branch information
baahkusi authored Sep 10, 2021
2 parents c67f50f + 005f584 commit 38becc7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class TrustdartPlugin: FlutterPlugin, MethodCallHandler {
result.error("arguments_null", "$address and $coin cannot be null", null)
}
}
"buildTransaction" -> {
result.notImplemented()
}
else -> result.notImplemented()
}
}
Expand All @@ -83,7 +86,7 @@ class TrustdartPlugin: FlutterPlugin, MethodCallHandler {
"BTC" -> {
val publicKey = privateKey.getPublicKeySecp256k1(true)
val address = BitcoinAddress(publicKey, CoinType.BITCOIN.p2pkhPrefix())
mapOf("legacy" to CoinType.BITCOIN.deriveAddress(privateKey), "segwit" to address.description())
mapOf("legacy" to address.description(), "segwit" to CoinType.BITCOIN.deriveAddress(privateKey))
}
"ETH" -> {
mapOf("legacy" to CoinType.ETHEREUM.deriveAddress(privateKey))
Expand All @@ -98,16 +101,13 @@ class TrustdartPlugin: FlutterPlugin, MethodCallHandler {
private fun validateAddressForCoin(coin: String, address: String): Boolean {
return when(coin) {
"BTC" -> {
// CoinType.BITCOIN.validateAddress(address)
true
CoinType.BITCOIN.validate(address)
}
"ETH" -> {
// CoinType.ETHEREUM.validateAddress(address)
true
CoinType.ETHEREUM.validate(address)
}
"XTZ" -> {
// CoinType.TEZOS.validateAddress(address)
true
CoinType.TEZOS.validate(address)
}
else -> false
}
Expand Down
17 changes: 13 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@ class _MyAppState extends State<MyApp> {
String mnemonic = await Trustdart.createWallet();
print('Here is our mnemonic: \n$mnemonic');
String dondo = "imitate embody law mammal exotic transfer roof hope price swift ordinary uncle";
var wallet = await Trustdart.importWalletFromMnemonic(dondo);
bool wallet = await Trustdart.importWalletFromMnemonic(dondo);
print(wallet);
var btcAddress = await Trustdart.generateAddressForCoin("m/44'/0'/0'/0/0", 'BTC');
var ethAddress = await Trustdart.generateAddressForCoin("m/44'/60'/0'/0/0", 'ETH');
var xtzAddress = await Trustdart.generateAddressForCoin("m/44'/1729'/0'/0'", 'XTZ');
Map btcAddress = await Trustdart.generateAddressForCoin('BTC', "m/44'/0'/0'/0/0");
Map ethAddress = await Trustdart.generateAddressForCoin('ETH', "m/44'/60'/0'/0/0");
Map xtzAddress = await Trustdart.generateAddressForCoin('XTZ', "m/44'/1729'/0'/0'");
print([btcAddress, ethAddress, xtzAddress]);
bool isBtcLegacyValid = await Trustdart.validateAddressForCoin('BTC', btcAddress['legacy']);
bool isBtcSegWitValid = await Trustdart.validateAddressForCoin('BTC', btcAddress['segwit']);
bool isEthValid = await Trustdart.validateAddressForCoin('ETH', ethAddress['legacy']);
bool isXtzValid = await Trustdart.validateAddressForCoin('XTZ', xtzAddress['legacy']);
print([isBtcLegacyValid, isBtcSegWitValid, isEthValid, isXtzValid]);
bool invalidBTC = await Trustdart.validateAddressForCoin('BTC', ethAddress['legacy']);
bool invalidETH = await Trustdart.validateAddressForCoin('ETH', xtzAddress['legacy']);
bool invalidXTZ = await Trustdart.validateAddressForCoin('XTZ', btcAddress['legacy']);
print([invalidBTC, invalidETH, invalidXTZ]);
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
Expand Down
10 changes: 9 additions & 1 deletion lib/trustdart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@ class Trustdart {
return importStatus;
}

static Future<Map> generateAddressForCoin(String path, String coin) async {
static Future<Map> generateAddressForCoin(String coin, String path) async {
final address = await _channel.invokeMethod('generateAddressForCoin', <String, String> {
'coin': coin,
'path': path,
});
return address;
}

static Future<bool> validateAddressForCoin(String coin, String address) async {
final isAddressValid = await _channel.invokeMethod('validateAddressForCoin', <String, String> {
'coin': coin,
'address': address,
});
return isAddressValid;
}
}

0 comments on commit 38becc7

Please sign in to comment.