diff --git a/lib/common/helper.dart b/lib/common/helper.dart index e8b44ab..e11e51e 100644 --- a/lib/common/helper.dart +++ b/lib/common/helper.dart @@ -1,3 +1,4 @@ +import 'dart:convert'; import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -9,6 +10,7 @@ import 'package:xdag/widget/button.dart'; import 'dart:typed_data'; import 'package:bip32/bip32.dart' as bip32; import 'package:bip39/bip39.dart' as bip39; +import 'package:fast_base58/fast_base58.dart'; class Helper { static final GlobalKey scaffoldMessengerKey = GlobalKey(); @@ -170,22 +172,8 @@ class Helper { } static List base58Decode(String input) { - var alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'; - var base58 = input.split('').reversed.join(); - var value = BigInt.zero; - for (var i = 0; i < base58.length; i++) { - var index = alphabet.indexOf(base58[i]); - value += BigInt.from(index) * BigInt.from(58).pow(i); - } - var hex = value.toRadixString(16).padLeft(2, '0'); - var bytes = []; - for (var i = 0; i < hex.length; i += 2) { - bytes.add(int.parse(hex.substring(i, i + 2), radix: 16)); - } - for (var i = 0; i < input.length && input[i] == alphabet[0]; i++) { - bytes.add(0); - } - return bytes.reversed.toList(); + var decodedRaw = Base58Decode(input); + return decodedRaw.reversed.toList(); } static String getAddressByWallet(bip32.BIP32 hdWallet) { diff --git a/lib/common/transaction.dart b/lib/common/transaction.dart index f47f3a3..f7b5efe 100644 --- a/lib/common/transaction.dart +++ b/lib/common/transaction.dart @@ -114,6 +114,7 @@ class TransactionHelper { static bool checkAddress(String address) { try { var addrBytes = Helper.base58Decode(address).reversed.toList(); + Helper.base58Decode('4AzP6NX68y854ztnSMuBYLj8KHHAtX5HK').reversed.toList(); if (addrBytes.length != 24) { return false; } @@ -129,6 +130,7 @@ class TransactionHelper { } return true; } catch (e) { + print(e); return false; } } diff --git a/pubspec.yaml b/pubspec.yaml index 1a69637..fa32ea3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.6+7 +version: 1.0.7+8 environment: sdk: '>=2.19.2 <3.0.0'