Browse Source

Merge branch 'master' of http://git.lcpcp.cc/root/bab-icon

DESKTOP-70VPDLK\Administrator 2 months ago
parent
commit
e21cc25ff4

+ 3 - 0
app/Console/Commands/TestCommand.php

@@ -5,6 +5,7 @@ namespace App\Console\Commands;
 use App\Models\Contract;
 use App\Models\MemberClan;
 use App\Servers\ContractServer;
+use App\Servers\Icon\BanRPC;
 use BitWasp\Bitcoin\Bitcoin;
 use BitWasp\Bitcoin\Address\PayToPubKeyHashAddress;
 use BitWasp\Bitcoin\Crypto\Random\Random;
@@ -49,6 +50,8 @@ class TestCommand extends Command
      */
     public function handle()
     {
+        $bnb_block = BanRPC::creatServer()->sendBlockNumber();
+        dd($bnb_block);
         $random = new Random();
         // 生成随机数(initial entropy)
         $entropy = $random->bytes(Bip39Mnemonic::MIN_ENTROPY_BYTE_LEN);

+ 36 - 4
app/Http/Controllers/Api/CommonController.php

@@ -21,9 +21,16 @@ use App\Servers\SmsServer;
 use App\Servers\TronAnalyzeServer;
 use App\Servers\TxMapServer;
 use App\Servers\WeixinServer;
+use BitWasp\Bitcoin\Address\PayToPubKeyHashAddress;
+use BitWasp\Bitcoin\Crypto\Random\Random;
+use BitWasp\Bitcoin\Key\Factory\HierarchicalKeyFactory;
+use BitWasp\Bitcoin\Mnemonic\Bip39\Bip39Mnemonic;
+use BitWasp\Bitcoin\Mnemonic\Bip39\Bip39SeedGenerator;
+use BitWasp\Bitcoin\Mnemonic\MnemonicFactory;
 use Illuminate\Contracts\Routing\ResponseFactory;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Storage;
+use Web3p\EthereumUtil\Util;
 
 class CommonController extends FrontController
 {
@@ -36,10 +43,35 @@ class CommonController extends FrontController
 
     function index()
     {
-        $contract=Contract::where('id',1)->first();
-        $memberTeam=MemberClan::where('m_id',$contract->{'m_id'})->select(['id','m_id','p_ids','one_m_id','two_m_id'])->first();
-        $pIds=array_reverse(array_filter(explode(',',$memberTeam->{'p_ids'})));
-        ContractServer::creatServer()->teamProportion($contract,$pIds);
+        $bnb_block = BanRPC::creatServer()->sendBlockNumber();
+        dd($bnb_block);
+        $random = new Random();
+        // 生成随机数(initial entropy)
+        $entropy = $random->bytes(Bip39Mnemonic::MIN_ENTROPY_BYTE_LEN);
+        $bip39 = MnemonicFactory::bip39();
+        // 通过随机数生成助记词
+        $mnemonic = $bip39->entropyToMnemonic($entropy);
+        dump($mnemonic);
+
+        $seedGenerator = new Bip39SeedGenerator();
+        // 通过助记词生成种子,传入可选加密串'hello'
+        $seed = $seedGenerator->getSeed($mnemonic);
+        dump( "seed: " .$seed->getHex());
+        $hdFactory = new HierarchicalKeyFactory();
+        $master = $hdFactory->fromEntropy($seed);
+
+        $hardened = $master->derivePath("44'/60'/0'/0/0");
+        dump( 'WIF: ' . $hardened->getPrivateKey()->toWif());
+        $address = new PayToPubKeyHashAddress($hardened->getPublicKey()->getPubKeyHash());
+        dump( 'address: ' . $address->getAddress());
+        dump( " public key: " . $hardened->getPublicKey()->getHex());
+        dump( " private key: " . $hardened->getPrivateKey()->getHex());
+        $util = new Util();
+        dump( " address: " . $util->publicKeyToAddress($util->privateKeyToPublicKey($hardened->getPrivateKey()->getHex())));
+//        $contract=Contract::where('id',1)->first();
+//        $memberTeam=MemberClan::where('m_id',$contract->{'m_id'})->select(['id','m_id','p_ids','one_m_id','two_m_id'])->first();
+//        $pIds=array_reverse(array_filter(explode(',',$memberTeam->{'p_ids'})));
+//        ContractServer::creatServer()->teamProportion($contract,$pIds);
         dd(1221);
 //        $data=Address::generate();
 //        $key='1212';