|
|
@@ -22,7 +22,12 @@ use BitWasp\Bitcoin\Address\AddressCreator;
|
|
|
use BitWasp\Bitcoin\Address\PayToPubKeyHashAddress;
|
|
|
use BitWasp\Bitcoin\Bitcoin;
|
|
|
use BitWasp\Bitcoin\Crypto\Random\Random;
|
|
|
+use BitWasp\Bitcoin\Key\Factory\HierarchicalKeyFactory;
|
|
|
use BitWasp\Bitcoin\Key\Factory\PrivateKeyFactory;
|
|
|
+use BitWasp\Bitcoin\Mnemonic\Bip39\Bip39Mnemonic;
|
|
|
+use BitWasp\Bitcoin\Mnemonic\Bip39\Bip39SeedGenerator;
|
|
|
+use BitWasp\Bitcoin\Mnemonic\MnemonicFactory;
|
|
|
+use BitWasp\Bitcoin\Network\NetworkFactory;
|
|
|
use BitWasp\Bitcoin\Script\WitnessProgram;
|
|
|
use etherscan\api\Etherscan;
|
|
|
use GuzzleHttp\Client;
|
|
|
@@ -904,20 +909,54 @@ class UsdtWalletService extends BaseService
|
|
|
*/
|
|
|
public function getErcAddress()
|
|
|
{
|
|
|
+
|
|
|
$random = new Random();
|
|
|
- $network = Bitcoin::getNetwork();
|
|
|
+ // 生成随机数(initial entropy)
|
|
|
+ $entropy = $random->bytes(Bip39Mnemonic::MIN_ENTROPY_BYTE_LEN);
|
|
|
+ $bip39 = MnemonicFactory::bip39();
|
|
|
+
|
|
|
+ // 通过随机数生成助记词
|
|
|
+ $mnemonic = $bip39->entropyToMnemonic($entropy);
|
|
|
+ echo "mnemonic: " . $mnemonic.PHP_EOL.PHP_EOL;// 助记词
|
|
|
+
|
|
|
+ $seedGenerator = new Bip39SeedGenerator();
|
|
|
+ // 通过助记词生成种子,传入可选加密串'hello'
|
|
|
+ $seed = $seedGenerator->getSeed($mnemonic);
|
|
|
+ echo "seed: " . $seed->getHex() . PHP_EOL;
|
|
|
+
|
|
|
+ $hdFactory = new HierarchicalKeyFactory();
|
|
|
+ $master = $hdFactory->fromEntropy($seed);
|
|
|
+
|
|
|
+ $util = new Util();
|
|
|
+ // 设置路径account
|
|
|
+ $hardened = $master->derivePath("44'/60'/0'/0/0");
|
|
|
+ $publicKey = $hardened->getPublicKey()->getHex();
|
|
|
+ $privateKey = $hardened->getPrivateKey()->getHex();
|
|
|
+ $address = $util->publicKeyToAddress($util->privateKeyToPublicKey($hardened->getPrivateKey()->getHex()));
|
|
|
+
|
|
|
+ return ['public_key' => $publicKey, 'hexAddress' => $address, 'address' => $address, 'wif'=> $privateKey];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取ERC2.0钱包地址
|
|
|
+ * @param string $type
|
|
|
+ * @throws \BitWasp\Bitcoin\Exceptions\RandomBytesFailure
|
|
|
+ */
|
|
|
+ public function getErcHexPrivate($wif)
|
|
|
+ {
|
|
|
$privateKeyFactory = new PrivateKeyFactory();
|
|
|
- $privateKey = $privateKeyFactory->generateCompressed($random);
|
|
|
+ $privateKey = $privateKeyFactory->fromWif($wif);
|
|
|
$publicKey = $privateKey->getPublicKey();
|
|
|
+ $publicKey = $privateKey->getSecret();
|
|
|
|
|
|
// p2pkh 格式的地址
|
|
|
$addressService = new PayToPubKeyHashAddress($publicKey->getPubKeyHash());
|
|
|
|
|
|
// 将生成的钱包保存到数据库中
|
|
|
- $wif = $privateKey->toWif($network);
|
|
|
+ $hex = $privateKey->getHex();
|
|
|
$address = $addressService->getAddress();
|
|
|
|
|
|
- return ['wif' => $wif, 'hexAddress' => $this->getHexAddress($address), 'address' => $address];
|
|
|
+ return ['wif' => $wif, 'hexAddress' => $this->getHexAddress($address), 'address' => $address,'hex_private'=>$hex];
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1769,11 +1808,12 @@ class UsdtWalletService extends BaseService
|
|
|
try {
|
|
|
// 获取子钱包TRC-USDT余额
|
|
|
$userId = isset($v['id']) ? $v['id'] : 0;
|
|
|
- $address = isset($v['trc_address']) ? $v['trc_address'] : '';
|
|
|
- $triggerAddress = isset($v['trc_hexaddress']) ? $v['trc_hexaddress'] : '';
|
|
|
- $addressPrivate = isset($v['trc_wif']) ? $v['trc_wif'] : '';
|
|
|
+ $address = isset($v['erc_address']) ? $v['erc_address'] : '';
|
|
|
+ $triggerAddress = isset($v['erc_hexaddress']) ? $v['erc_hexaddress'] : '';
|
|
|
+ $addressPrivate = isset($v['erc_wif']) ? $v['erc_wif'] : '';
|
|
|
// 可归集的USDT余额
|
|
|
- $result = $api->tokenBalance($triggerAddress);
|
|
|
+ $result = $api->balance($triggerAddress);
|
|
|
+// $result = $api->tokenBalance($triggerAddress);
|
|
|
$triggerUsdt = isset($result['result']) ? floatval($result['result']) : 0.00;
|
|
|
$triggerUsdt = $triggerUsdt ? floatval($triggerUsdt / pow(10, 6)) : '0.00';
|
|
|
|