Skip to content

Commit

Permalink
fix address check
Browse files Browse the repository at this point in the history
  • Loading branch information
amazingCoding committed Apr 12, 2023
1 parent 470920b commit bd96cd5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
20 changes: 4 additions & 16 deletions lib/common/helper.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
Expand All @@ -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<ScaffoldMessengerState> scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
Expand Down Expand Up @@ -170,22 +172,8 @@ class Helper {
}

static List<int> 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 = <int>[];
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) {
Expand Down
2 changes: 2 additions & 0 deletions lib/common/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -129,6 +130,7 @@ class TransactionHelper {
}
return true;
} catch (e) {
print(e);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit bd96cd5

Please sign in to comment.