From 719a9ff89d489eae13e6d0df0a6953a2a6ef2d6c Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 1 Nov 2022 13:28:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Api/Controllers/AuthController.php | 19 +- app/Api/Controllers/UserController.php | 13 + app/Api/Resources/AuthResource.php | 4 +- app/Api/Routes/user.php | 1 + app/Models/User.php | 12 +- composer.json | 1 + composer.lock | 536 +++++++++++++++++- .../2014_10_12_000000_create_users_table.php | 4 +- 8 files changed, 583 insertions(+), 7 deletions(-) diff --git a/app/Api/Controllers/AuthController.php b/app/Api/Controllers/AuthController.php index 993feb1..3ff4724 100644 --- a/app/Api/Controllers/AuthController.php +++ b/app/Api/Controllers/AuthController.php @@ -4,15 +4,30 @@ namespace App\Api\Controllers; use App\Api\Resources\AuthResource; use App\Models\User; +use BitWasp\Bitcoin\Address\PayToPubKeyHashAddress; +use BitWasp\Bitcoin\Key\Factory\HierarchicalKeyFactory; +use BitWasp\Bitcoin\Mnemonic\Bip39\Bip39SeedGenerator; use Illuminate\Http\Request; class AuthController extends Controller { public function login(Request $request) { - $address = $request->address; + $address = $request->address; $mnemonic = $request->mnemonic; - $address = '12dUut3dG5xWi6JPDMjSSK6s2JPcfeKYL1'; + // $address = '12dUut3dG5xWi6JPDMjSSK6s2JPcfeKYL1'; + + $seedGenerator = new Bip39SeedGenerator(); + $seed = $seedGenerator->getSeed($mnemonic); + $hdFactory = new HierarchicalKeyFactory(); + $master = $hdFactory->fromEntropy($seed); + $hardened = $master->derivePath("44'/13107'/0'/0/0"); + $pubKey = new PayToPubKeyHashAddress($hardened->getPublicKey()->getPubKeyHash()); + $verifyAddress = $pubKey->getAddress(); + + if ($verifyAddress != $address) { + return $this->failed('非法操作'); + } $user = User::where('username', $address)->first(); diff --git a/app/Api/Controllers/UserController.php b/app/Api/Controllers/UserController.php index 11cbe8e..8d8a5d5 100644 --- a/app/Api/Controllers/UserController.php +++ b/app/Api/Controllers/UserController.php @@ -46,4 +46,17 @@ class UserController extends Controller return $this->success($user->privacy); } + + public function download(): JsonResponse + { + return $this->success('https://www.uzchain.tech?invite='.Api::user()->username); + } + + public function email() + { + } + + public function mobile() + { + } } \ No newline at end of file diff --git a/app/Api/Resources/AuthResource.php b/app/Api/Resources/AuthResource.php index 70f137a..d549ba7 100644 --- a/app/Api/Resources/AuthResource.php +++ b/app/Api/Resources/AuthResource.php @@ -15,7 +15,9 @@ class AuthResource extends JsonResource 'user_info' => [ 'user_id' => $this->id, 'username' => $this->username, - 'privacy' => $this->privacy, + 'mobile' => $this->mobile, + 'email' => $this->email, + 'privacy' => $this->privacy ?? true, 'nickname' => $this->info->nickname, 'avatar' => $this->info->avatar, 'address' => $this->username, diff --git a/app/Api/Routes/user.php b/app/Api/Routes/user.php index 8da7057..e2201a3 100644 --- a/app/Api/Routes/user.php +++ b/app/Api/Routes/user.php @@ -10,4 +10,5 @@ Route::group([ $router->get('search', 'UserController@search'); $router->put('setting/{field}', 'UserController@setting'); $router->put('privacy', 'UserController@privacy'); + $router->get('download', 'UserController@download'); }); \ No newline at end of file diff --git a/app/Models/User.php b/app/Models/User.php index 9b5a167..de8918c 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,7 +2,6 @@ namespace App\Models; -use App\Jobs\SyncUserInfo; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; @@ -11,6 +10,7 @@ use Illuminate\Notifications\Notifiable; use Jason\Api\Api; use Laravel\Sanctum\HasApiTokens; use Tencent\TLSSigAPIv2; +use Illuminate\Support\Facades\Crypt; class User extends Authenticatable { @@ -54,6 +54,16 @@ class User extends Authenticatable return Api::login($this); } + public function setPasswordAttribute($value): void + { + $this->attributes['password'] = bcrypt($value); + } + + public function setMnemonicAttribute($value): void + { + $this->attributes['mnemonic'] = Crypt::encrypt($value); + } + public function info(): HasOne { return $this->hasOne(UserInfo::class); diff --git a/composer.json b/composer.json index 251a863..6fd5296 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "require": { "php": "^7.4|^8.0", "alibabacloud/sts": "^1.8", + "bitwasp/bitcoin": "^1.0", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^7.0.1", "hedeqiang/ten-im": "^1.1", diff --git a/composer.lock b/composer.lock index 2036238..f14e3b9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "140bda4c9f804ba96aef213653efa240", + "content-hash": "7855730e25a112fd12d46eb09796ef2b", "packages": [ { "name": "adbario/php-dot-notation", @@ -327,6 +327,181 @@ }, "time": "2022-01-18T09:12:03+00:00" }, + { + "name": "bitwasp/bech32", + "version": "v0.0.1", + "source": { + "type": "git", + "url": "https://github.com/Bit-Wasp/bech32.git", + "reference": "e1ea58c848a4ec59d81b697b3dfe9cc99968d0e7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Bit-Wasp/bech32/zipball/e1ea58c848a4ec59d81b697b3dfe9cc99968d0e7", + "reference": "e1ea58c848a4ec59d81b697b3dfe9cc99968d0e7", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require-dev": { + "phpunit/phpunit": "^5.4.0", + "squizlabs/php_codesniffer": "^2.0.0" + }, + "type": "library", + "autoload": { + "files": [ + "src/bech32.php" + ], + "psr-4": { + "BitWasp\\Bech32\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Unlicense" + ], + "authors": [ + { + "name": "Thomas Kerin", + "homepage": "https://thomaskerin.io", + "role": "Author" + } + ], + "description": "Pure (no dependencies) implementation of bech32", + "homepage": "https://github.com/bit-wasp/bech32", + "support": { + "issues": "https://github.com/Bit-Wasp/bech32/issues", + "source": "https://github.com/Bit-Wasp/bech32/tree/more-tests" + }, + "time": "2018-02-05T22:23:47+00:00" + }, + { + "name": "bitwasp/bitcoin", + "version": "v1.0.4", + "source": { + "type": "git", + "url": "https://github.com/Bit-Wasp/bitcoin-php.git", + "reference": "65ff8384a15e805effcf600fb08cef3a0fc63824" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Bit-Wasp/bitcoin-php/zipball/65ff8384a15e805effcf600fb08cef3a0fc63824", + "reference": "65ff8384a15e805effcf600fb08cef3a0fc63824", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "bitwasp/bech32": "^0.0.1", + "bitwasp/buffertools": "^0.5.0", + "composer/semver": "^1.4.0", + "lastguest/murmurhash": "v2.0.0", + "mdanter/ecc": "^0.5.0", + "php-64bit": ">=7.0", + "pleonasm/merkle-tree": "1.0.0" + }, + "require-dev": { + "bitwasp/bitcoinconsensus": "v3.0.0", + "bitwasp/secp256k1-php": "^v0.2.0", + "ext-json": "*", + "nbobtc/bitcoind-php": "v2.0.2", + "phpunit/phpunit": "^5.4.0", + "squizlabs/php_codesniffer": "^2.0.0" + }, + "suggest": { + "ext-bitcoinconsensus": "The bitcoinconsensus library for safest possible script verification", + "ext-secp256k1": "The secp256k1 library for fast and safe elliptic curve operations" + }, + "type": "library", + "autoload": { + "files": [ + "src/Script/functions.php" + ], + "psr-4": { + "BitWasp\\Bitcoin\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Unlicense" + ], + "authors": [ + { + "name": "Thomas Kerin", + "homepage": "https://thomaskerin.io", + "role": "Author" + } + ], + "description": "PHP Bitcoin library with functions for transactions, signatures, serialization, Random/Deterministic ECDSA keys, blocks, RPC bindings", + "homepage": "https://github.com/bit-wasp/bitcoin-php", + "support": { + "issues": "https://github.com/Bit-Wasp/bitcoin-php/issues", + "source": "https://github.com/Bit-Wasp/bitcoin-php/tree/v1.0.4" + }, + "time": "2019-12-10T23:28:26+00:00" + }, + { + "name": "bitwasp/buffertools", + "version": "v0.5.7", + "source": { + "type": "git", + "url": "https://github.com/Bit-Wasp/buffertools-php.git", + "reference": "133746d0b514e0016d8479b54aa97475405a9f1f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Bit-Wasp/buffertools-php/zipball/133746d0b514e0016d8479b54aa97475405a9f1f", + "reference": "133746d0b514e0016d8479b54aa97475405a9f1f", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php-64bit": ">=7.0.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0", + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "BitWasp\\Buffertools\\": "src/Buffertools/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Thomas Kerin", + "homepage": "https://thomaskerin.io" + }, + { + "name": "Ruben de Vries", + "email": "ruben@rubensayshi.com" + } + ], + "description": "Toolbox for working with binary and hex data. Similar to NodeJS Buffer.", + "support": { + "issues": "https://github.com/Bit-Wasp/buffertools-php/issues", + "source": "https://github.com/Bit-Wasp/buffertools-php/tree/v0.5.7" + }, + "time": "2020-01-17T21:31:49+00:00" + }, { "name": "brick/math", "version": "0.10.1", @@ -447,6 +622,92 @@ }, "time": "2021-05-18T17:55:57+00:00" }, + { + "name": "composer/semver", + "version": "1.7.2", + "source": { + "type": "git", + "url": "https://github.com/composer/semver.git", + "reference": "647490bbcaf7fc4891c58f47b825eb99d19c377a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/semver/zipball/647490bbcaf7fc4891c58f47b825eb99d19c377a", + "reference": "647490bbcaf7fc4891c58f47b825eb99d19c377a", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^5.3.2 || ^7.0 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.5 || ^5.0.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Semver\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nils Adermann", + "email": "naderman@naderman.de", + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + }, + { + "name": "Rob Bast", + "email": "rob.bast@gmail.com", + "homepage": "http://robbast.nl" + } + ], + "description": "Semver library that offers utilities, version constraint parsing and validation.", + "keywords": [ + "semantic", + "semver", + "validation", + "versioning" + ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/semver/issues", + "source": "https://github.com/composer/semver/tree/1.7.2" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2020-12-03T15:47:16+00:00" + }, { "name": "danielstjules/stringy", "version": "3.1.0", @@ -914,6 +1175,87 @@ ], "time": "2020-12-29T14:50:06+00:00" }, + { + "name": "fgrosse/phpasn1", + "version": "v2.4.0", + "source": { + "type": "git", + "url": "https://github.com/fgrosse/PHPASN1.git", + "reference": "eef488991d53e58e60c9554b09b1201ca5ba9296" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fgrosse/PHPASN1/zipball/eef488991d53e58e60c9554b09b1201ca5ba9296", + "reference": "eef488991d53e58e60c9554b09b1201ca5ba9296", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.0.0 || ~8.1.0" + }, + "require-dev": { + "php-coveralls/php-coveralls": "~2.0", + "phpunit/phpunit": "^6.3 || ^7.0 || ^8.0" + }, + "suggest": { + "ext-bcmath": "BCmath is the fallback extension for big integer calculations", + "ext-curl": "For loading OID information from the web if they have not bee defined statically", + "ext-gmp": "GMP is the preferred extension for big integer calculations", + "phpseclib/bcmath_compat": "BCmath polyfill for servers where neither GMP nor BCmath is available" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "FG\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Friedrich Große", + "email": "friedrich.grosse@gmail.com", + "homepage": "https://github.com/FGrosse", + "role": "Author" + }, + { + "name": "All contributors", + "homepage": "https://github.com/FGrosse/PHPASN1/contributors" + } + ], + "description": "A PHP Framework that allows you to encode and decode arbitrary ASN.1 structures using the ITU-T X.690 Encoding Rules.", + "homepage": "https://github.com/FGrosse/PHPASN1", + "keywords": [ + "DER", + "asn.1", + "asn1", + "ber", + "binary", + "decoding", + "encoding", + "x.509", + "x.690", + "x509", + "x690" + ], + "support": { + "issues": "https://github.com/fgrosse/PHPASN1/issues", + "source": "https://github.com/fgrosse/PHPASN1/tree/v2.4.0" + }, + "time": "2021-12-11T12:41:06+00:00" + }, { "name": "fruitcake/laravel-cors", "version": "v2.2.0", @@ -2054,6 +2396,63 @@ }, "time": "2022-03-23T12:38:24+00:00" }, + { + "name": "lastguest/murmurhash", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/lastguest/murmurhash-php.git", + "reference": "4fb7516f67e695e5d7fa129d1bbb925ec0ebe408" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/lastguest/murmurhash-php/zipball/4fb7516f67e695e5d7fa129d1bbb925ec0ebe408", + "reference": "4fb7516f67e695e5d7fa129d1bbb925ec0ebe408", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7" + }, + "require-dev": { + "phpstan/phpstan": "^0.6.3", + "phpunit/phpunit": "^5" + }, + "type": "library", + "autoload": { + "psr-4": { + "lastguest\\": "src/lastguest/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Stefano Azzolini", + "email": "lastguest@gmail.com", + "homepage": "https://github.com/lastguest/murmurhash-php" + } + ], + "description": "MurmurHash3 Hash", + "homepage": "https://github.com/lastguest/murmurhash-php", + "keywords": [ + "hash", + "hashing", + "murmur" + ], + "support": { + "issues": "https://github.com/lastguest/murmurhash-php/issues", + "source": "https://github.com/lastguest/murmurhash-php/tree/master" + }, + "time": "2017-10-10T15:16:12+00:00" + }, { "name": "league/commonmark", "version": "2.3.4", @@ -2416,6 +2815,88 @@ ], "time": "2022-04-17T13:12:02+00:00" }, + { + "name": "mdanter/ecc", + "version": "v0.5.2", + "source": { + "type": "git", + "url": "https://github.com/phpecc/phpecc.git", + "reference": "b95f25cc1bacc83a9f0ccd375900b7cfd343029e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpecc/phpecc/zipball/b95f25cc1bacc83a9f0ccd375900b7cfd343029e", + "reference": "b95f25cc1bacc83a9f0ccd375900b7cfd343029e", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-gmp": "*", + "fgrosse/phpasn1": "^2.0", + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0", + "squizlabs/php_codesniffer": "^2.0", + "symfony/yaml": "^2.6|^3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Mdanter\\Ecc\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Matyas Danter", + "homepage": "http://matejdanter.com/", + "role": "Author" + }, + { + "name": "Thibaud Fabre", + "email": "thibaud@aztech.io", + "homepage": "http://aztech.io", + "role": "Maintainer" + }, + { + "name": "Thomas Kerin", + "email": "afk11@users.noreply.github.com", + "role": "Maintainer" + } + ], + "description": "PHP Elliptic Curve Cryptography library", + "homepage": "https://github.com/phpecc/phpecc", + "keywords": [ + "Diffie", + "ECDSA", + "Hellman", + "curve", + "ecdh", + "elliptic", + "nistp192", + "nistp224", + "nistp256", + "nistp384", + "nistp521", + "phpecc", + "secp256k1", + "secp256r1" + ], + "support": { + "issues": "https://github.com/phpecc/phpecc/issues", + "source": "https://github.com/phpecc/phpecc/tree/master" + }, + "time": "2018-12-03T18:17:01+00:00" + }, { "name": "monolog/monolog", "version": "2.8.0", @@ -3068,6 +3549,59 @@ ], "time": "2021-12-04T23:24:31+00:00" }, + { + "name": "pleonasm/merkle-tree", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/pleonasm/merkle-tree.git", + "reference": "9ddc9d0a0e396750fada378f3aa90f6c02dd56a1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pleonasm/merkle-tree/zipball/9ddc9d0a0e396750fada378f3aa90f6c02dd56a1", + "reference": "9ddc9d0a0e396750fada378f3aa90f6c02dd56a1", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "ext-xdebug": ">=2.2.0", + "phpunit/php-invoker": ">=1.0.0,<1.2.0", + "phpunit/phpunit": "3.7.19", + "satooshi/php-coveralls": "*@dev", + "squizlabs/php_codesniffer": "*" + }, + "type": "library", + "autoload": { + "psr-0": { + "Pleo": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Matthew Nagi", + "email": "matthew.nagi@base-2.net" + } + ], + "description": "An implementation of a Merkle Tree in PHP", + "support": { + "issues": "https://github.com/pleonasm/merkle-tree/issues", + "source": "https://github.com/pleonasm/merkle-tree/tree/master" + }, + "time": "2013-05-22T20:46:20+00:00" + }, { "name": "psr/container", "version": "1.1.2", diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 7047c12..203458f 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -17,8 +17,8 @@ class CreateUsersTable extends Migration $table->id(); $table->string('username', 64)->unique(); $table->string('password')->nullable(); - $table->string('phone')->nullable(); - $table->string('email')->nullable(); + $table->string('mobile')->index()->nullable(); + $table->string('email')->index()->nullable(); $table->string('mnemonic')->nullable(); $table->boolean('privacy')->default(1)->index(); $table->rememberToken();