Ver3.0 ๐ ๋ผ๋ผ๋ฒจ์์ ENS(์ด๋๋ฆฌ์ ๋ค์์๋น์ค) ๋ก๊ทธ์ธ ๊ธฐ๋ฅ ๊ตฌํํ๊ธฐ - Web3 ์๋์ ์๋ก์ด ์ธ์ฆ ๋ฐฉ์

๐ ๋ผ๋ผ๋ฒจ์์ ENS(์ด๋๋ฆฌ์ ๋ค์์๋น์ค) ๋ก๊ทธ์ธ ๊ธฐ๋ฅ ๊ตฌํํ๊ธฐ - Web3 ์๋์ ์๋ก์ด ์ธ์ฆ ๋ฐฉ์
๋ธ๋ก์ฒด์ธ ๊ธฐ์ ๊ณผ ์ ํต์ ์ธ ์น ํ๋ ์์ํฌ์ ๋ง๋จ
์์ฆ Web3 ํธ๋ ๋ ์ง์ง ํซํ์ฃ ? ใ
ใ
ใ
ํนํ ENS(Ethereum Name Service)๋ ๋ณต์กํ ์ด๋๋ฆฌ์ ์ฃผ์๋ฅผ 'yourname.eth' ๊ฐ์ ๊ฐ๋จํ ์ด๋ฆ์ผ๋ก ๋ฐ๊ฟ์ฃผ๋ ํ์ ์ ์ธ ์๋น์ค์ธ๋ฐ์ ๐
์ค๋์ ์ฐ๋ฆฌ๊ฐ ์ต์ํ ๋ผ๋ผ๋ฒจ ํ๋ ์์ํฌ์์ ENS ๋ก๊ทธ์ธ ๊ธฐ๋ฅ์ ์ด๋ป๊ฒ ๊ตฌํํ๋์ง ์์ ๋ํ
์ผํ๊ฒ ํํค์ณ๋ณผ๊ฒ์! ์ ํต์ ์ธ ์ด๋ฉ์ผ/๋น๋ฐ๋ฒํธ ๋ฐฉ์์์ ๋ฒ์ด๋ ์ง๊ฐ ์ฃผ์์ ENS๋ก ๋ก๊ทธ์ธํ๋ ๋ฐฉ์, ์๊ฐ๋ง ํด๋ ๋ฉ์ง์ง ์๋์? ๐
๐ฏ ENS ๋ก๊ทธ์ธ์ด ๋ญ๊ธธ๋?
๋จผ์ ๊ธฐ๋ณธ ๊ฐ๋
๋ถํฐ ์ก๊ณ ๊ฐ์ผ๊ฒ ์ฃ ใ
ใ
ENS ๋ก๊ทธ์ธ์ ๊ธฐ์กด์ ์ค์ํ๋ ์ธ์ฆ ๋ฐฉ์๊ณผ๋ ์์ ํ ๋ค๋ฅธ ์ ๊ทผ๋ฒ์ด์์.
์ฌ์ฉ์๊ฐ ์์ ์ ์ด๋๋ฆฌ์ ์ง๊ฐ(๋ฉํ๋ง์คํฌ ๊ฐ์)์ผ๋ก ์๋ช
์ ํ๋ฉด, ์๋ฒ์์ ๊ทธ ์๋ช
์ ๊ฒ์ฆํด์ ๋ก๊ทธ์ธ์ ์ฒ๋ฆฌํ๋ ๋ฐฉ์์ด์ฃ . ๋น๋ฐ๋ฒํธ ์์ด๋ ์์ ํ๊ฒ ์ธ์ฆํ ์ ์๋ค๋ ๊ฒ ํต์ฌ ํฌ์ธํธ! ๐
๐ก ENS ๋ก๊ทธ์ธ์ ์ฅ์
โ
๋น๋ฐ๋ฒํธ ๊ด๋ฆฌ ๋ถํ์ - ๋ ์ด์ ๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ ๊ธฐ๋ฅ ๋ง๋ค ํ์ ์์ ใ
ใ
ใ
โ
ํ์ค์ํ๋ ์ ์ ํ์ธ - ๋ธ๋ก์ฒด์ธ ๊ธฐ๋ฐ์ ๊ฒ์ฆ ๊ฐ๋ฅํ ์ ์
โ
์ฌ์ฉ์ ๊ฒฝํ ๊ฐ์ - ๋ณต์กํ ์ฃผ์ ๋์ ๊ฐ๋จํ ENS ์ด๋ฆ ์ฌ์ฉ
โ
ํฌ๋ก์ค ํ๋ซํผ ํธํ์ฑ - ํ๋์ ์ง๊ฐ์ผ๋ก ์ฌ๋ฌ ์๋น์ค ์ด์ฉ
โ
๋ณด์์ฑ ํฅ์ - ๊ฐ์ธํค ๊ธฐ๋ฐ์ ์ํธํ์ ์๋ช
๐ ๏ธ ๊ฐ๋ฐ ํ๊ฒฝ ์ค๋นํ๊ธฐ
๋ณธ๊ฒฉ์ ์ผ๋ก ์ฝ๋ฉ ๋ค์ด๊ฐ๊ธฐ ์ ์ ํ์ํ ๊ฒ๋ค๋ถํฐ ์ธํ ํด์ผ์ฃ ! ๋ผ๋ผ๋ฒจ ํ๋ก์ ํธ๊ฐ ์ด๋ฏธ ์๋ค๋ ๊ฐ์ ํ์ ์งํํ ๊ฒ์ ใ ใ
๐ฆ ํ์ ํจํค์ง ์ค์น
ENS์ ์ด๋๋ฆฌ์ ๊ด๋ จ ์์ ์ ํ๋ ค๋ฉด PHP์์ ๋ธ๋ก์ฒด์ธ๊ณผ ํต์ ํ ์ ์๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ํ์ํด์. ๊ฐ์ฅ ๋ง์ด ์ฐ์ด๋ ๊ฑด web3.php์ ethereum-php ํจํค์ง์ ๋๋ค!
# Composer๋ก ํ์ํ ํจํค์ง ์ค์น
composer require web3p/web3.php
composer require kornrunner/keccak
# ENS ๊ด๋ จ ์ถ๊ฐ ํจํค์ง
composer require simplito/elliptic-php
๐ก Tip: web3.php๋ ์ด๋๋ฆฌ์ ๋ ธ๋์ ํต์ ํ๊ธฐ ์ํ ํต์ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์. Infura๋ Alchemy ๊ฐ์ ๋ ธ๋ ํ๋ก๋ฐ์ด๋ API ํค๋ ๋ฏธ๋ฆฌ ์ค๋นํด๋์ธ์! ๋ฌด๋ฃ ํ๋์ผ๋ก๋ ์ถฉ๋ถํ ํ ์คํธ ๊ฐ๋ฅํฉ๋๋ค ใ ใ
๊ทธ๋ฆฌ๊ณ ํ๋ก ํธ์๋์์๋ Web3.js๋ Ethers.js๋ฅผ ์ฌ์ฉํ ๊ฑฐ์์. ์ ๋ ๊ฐ์ธ์ ์ผ๋ก Ethers.js๋ฅผ ์ ํธํ๋๋ฐ, ๋ฌธ์ํ๋ ์ ๋์ด์๊ณ ์ฌ์ฉํ๊ธฐ ํธํด์์!
// package.json์ ์ถ๊ฐ
npm install ethers
// ๋๋
yarn add ethers
๐ง ๋ผ๋ผ๋ฒจ ๋ฐฑ์๋ ๊ตฌ์กฐ ์ค๊ณ
์, ์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก ๋ผ๋ผ๋ฒจ ์ชฝ ์ฝ๋๋ฅผ ์์ฑํด๋ณผ๊น์? ๋จผ์ ์ ์ฒด์ ์ธ ๊ตฌ์กฐ๋ฅผ ์ก๋ ๊ฒ ์ค์ํด์. ์ ๋ ๋ณดํต ์ด๋ ๊ฒ ๊ตฌ์ฑํฉ๋๋ค:
๐ ๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ
app/Services/Web3Service.php - Web3 ๊ด๋ จ ๋ก์ง ์ฒ๋ฆฌ
app/Services/ENSService.php - ENS ์กฐํ ๋ฐ ๊ฒ์ฆ
app/Http/Controllers/Auth/Web3AuthController.php - ์ธ์ฆ ์ปจํธ๋กค๋ฌ
app/Models/User.php - ์ฌ์ฉ์ ๋ชจ๋ธ (wallet_address, ens_name ํ๋ ์ถ๊ฐ)
database/migrations/xxxx_add_web3_fields_to_users.php - ๋ง์ด๊ทธ๋ ์ด์
๐ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง์ด๊ทธ๋ ์ด์
๋จผ์ users ํ ์ด๋ธ์ ์ง๊ฐ ์ฃผ์์ ENS ์ด๋ฆ์ ์ ์ฅํ ์ปฌ๋ผ์ ์ถ๊ฐํด์ผ๊ฒ ์ฃ ?
php artisan make:migration add_web3_fields_to_users_table --table=users
์์ฑ๋ ๋ง์ด๊ทธ๋ ์ด์ ํ์ผ์ ์ด๋ ๊ฒ ์์ฑํด์ฃผ์ธ์:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('wallet_address', 42)->unique()->nullable();
$table->string('ens_name')->nullable();
$table->timestamp('last_login_at')->nullable();
$table->string('nonce')->nullable(); // ์ฌ์ ๊ณต๊ฒฉ ๋ฐฉ์ง์ฉ
});
}
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn(['wallet_address', 'ens_name', 'last_login_at', 'nonce']);
});
}
};
โ ๏ธ ์ฃผ์: wallet_address๋ ๋ฐ๋์ unique ์ ์ฝ์กฐ๊ฑด์ ๊ฑธ์ด์ผ ํด์! ํ ์ง๊ฐ ์ฃผ์๋ก ์ฌ๋ฌ ๊ณ์ ์ด ์์ฑ๋๋ ๊ฑธ ๋ฐฉ์งํ๊ธฐ ์ํด์์ฃ . nonce ํ๋๋ ๋ณด์์ ์ํด ๊ผญ ํ์ํ๋ฐ, ๋์ค์ ์์ธํ ์ค๋ช ํ ๊ฒ์ ใ ใ
php artisan migrate
๐จ Web3Service ํด๋์ค ๊ตฌํ
์ด์ ํต์ฌ ๋ก์ง์ ๋ด๋นํ Web3Service๋ฅผ ๋ง๋ค์ด๋ณผ๊ฒ์! ์ด ํด๋์ค์์ ์ด๋๋ฆฌ์ ๋ ธ๋์ ํต์ ํ๊ณ , ์๋ช ์ ๊ฒ์ฆํ๋ ๋ชจ๋ ์์ ์ ์ฒ๋ฆฌํฉ๋๋ค ๐
<?php
namespace App\Services;
use Web3\Web3;
use Web3\Contract;
use Web3\Utils;
use kornrunner\Keccak;
class Web3Service
{
protected $web3;
protected $infuraUrl;
public function __construct()
{
// Infura ๋๋ Alchemy URL ์ค์
$this->infuraUrl = 'https://mainnet.infura.io/v3/' . env('INFURA_PROJECT_ID');
$this->web3 = new Web3($this->infuraUrl);
}
/**
* ๋ฉ์์ง ์๋ช
๊ฒ์ฆ
*
* @param string $message ์๋ณธ ๋ฉ์์ง
* @param string $signature ์๋ช
๊ฐ
* @param string $address ์ง๊ฐ ์ฃผ์
* @return bool
*/
public function verifySignature($message, $signature, $address)
{
try {
// ์ด๋๋ฆฌ์ ์๋ช
๋ฉ์์ง ํ์์ผ๋ก ๋ณํ
$hash = $this->hashMessage($message);
// ์๋ช
์์ r, s, v ๊ฐ ์ถ์ถ
$r = substr($signature, 0, 66);
$s = '0x' . substr($signature, 66, 64);
$v = hexdec(substr($signature, 130, 2));
// v ๊ฐ ์กฐ์ (27 ๋๋ 28์ด์ด์ผ ํจ)
if ($v < 27) {
$v += 27;
}
// ๊ณต๊ฐํค ๋ณต๊ตฌ
$recoveredAddress = $this->recoverAddress($hash, $r, $s, $v);
// ์ฃผ์ ๋น๊ต (๋์๋ฌธ์ ๊ตฌ๋ถ ์์ด)
return strtolower($recoveredAddress) === strtolower($address);
} catch (\Exception $e) {
\Log::error('Signature verification failed: ' . $e->getMessage());
return false;
}
}
/**
* ์ด๋๋ฆฌ์ ๋ฉ์์ง ํด์ ์์ฑ
*/
protected function hashMessage($message)
{
$prefix = "\x19Ethereum Signed Message:\n" . strlen($message);
$prefixedMessage = $prefix . $message;
return '0x' . Keccak::hash($prefixedMessage, 256);
}
/**
* ์๋ช
์์ ์ฃผ์ ๋ณต๊ตฌ
*/
protected function recoverAddress($hash, $r, $s, $v)
{
// elliptic-php ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ
$ec = new \Elliptic\EC('secp256k1');
// ์๋ช
๋ณต๊ตฌ ๋ก์ง
// ... (๋ณต์กํ ์ํธํ ์ฐ์ฐ)
return $recoveredAddress;
}
/**
* ๋๋ค nonce ์์ฑ
*/
public function generateNonce()
{
return bin2hex(random_bytes(16));
}
}
๐ก ์๋ช ๊ฒ์ฆ ์๋ฆฌ: ์ฌ์ฉ์๊ฐ ๋ฉํ๋ง์คํฌ์์ ๋ฉ์์ง์ ์๋ช ํ๋ฉด, ๊ทธ ์๋ช ๊ฐ์ผ๋ก๋ถํฐ ์๋ ์๋ช ํ ์ฌ๋์ ์ฃผ์๋ฅผ ๋ณต๊ตฌํ ์ ์์ด์. ์ด๊ฒ ๋ฐ๋ก ๊ณต๊ฐํค ์ํธํ์ ๋ง๋ฒ์ด์ฃ ! ใ ใ ใ ๋ณต๊ตฌ๋ ์ฃผ์๊ฐ ์ฌ์ฉ์๊ฐ ์ฃผ์ฅํ๋ ์ฃผ์์ ์ผ์นํ๋ฉด ์ธ์ฆ ์ฑ๊ณต์ ๋๋ค ๐
๐ท๏ธ ENSService ํด๋์ค ๊ตฌํ
ENS ๊ด๋ จ ๊ธฐ๋ฅ์ ๋ณ๋ ์๋น์ค๋ก ๋ถ๋ฆฌํ๋ฉด ์ฝ๋ ๊ด๋ฆฌ๊ฐ ํจ์ฌ ๊น๋ํด์ ธ์! ENS ์ด๋ฆ์ผ๋ก ์ฃผ์๋ฅผ ์ฐพ๊ฑฐ๋, ๋ฐ๋๋ก ์ฃผ์๋ก ENS ์ด๋ฆ์ ์ฐพ๋ ๊ธฐ๋ฅ์ ๊ตฌํํด๋ด ์๋ค ๐
<?php
namespace App\Services;
use Web3\Web3;
use Web3\Contract;
class ENSService
{
protected $web3;
protected $ensRegistryAddress = '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e';
protected $publicResolverAddress;
public function __construct()
{
$infuraUrl = 'https://mainnet.infura.io/v3/' . env('INFURA_PROJECT_ID');
$this->web3 = new Web3($infuraUrl);
}
/**
* ENS ์ด๋ฆ์ผ๋ก ์ด๋๋ฆฌ์ ์ฃผ์ ์กฐํ
*
* @param string $ensName (์: 'vitalik.eth')
* @return string|null
*/
public function resolveENSToAddress($ensName)
{
try {
// ENS ์ด๋ฆ์ namehash๋ก ๋ณํ
$node = $this->namehash($ensName);
// ENS Registry ์ปจํธ๋ํธ ABI
$registryAbi = $this->getRegistryAbi();
$contract = new Contract($this->web3->provider, $registryAbi);
$contract->at($this->ensRegistryAddress);
// Resolver ์ฃผ์ ๊ฐ์ ธ์ค๊ธฐ
$resolverAddress = null;
$contract->call('resolver', $node, function ($err, $result) use (&$resolverAddress) {
if (!$err && $result) {
$resolverAddress = $result[0];
}
});
if (!$resolverAddress || $resolverAddress === '0x0000000000000000000000000000000000000000') {
return null;
}
// Resolver์์ ์ฃผ์ ์กฐํ
$resolverAbi = $this->getResolverAbi();
$resolverContract = new Contract($this->web3->provider, $resolverAbi);
$resolverContract->at($resolverAddress);
$address = null;
$resolverContract->call('addr', $node, function ($err, $result) use (&$address) {
if (!$err && $result) {
$address = $result[0];
}
});
return $address;
} catch (\Exception $e) {
\Log::error('ENS resolution failed: ' . $e->getMessage());
return null;
}
}
/**
* ์ด๋๋ฆฌ์ ์ฃผ์๋ก ENS ์ด๋ฆ ์กฐํ (Reverse Resolution)
*
* @param string $address
* @return string|null
*/
public function resolveAddressToENS($address)
{
try {
// ์ฃผ์๋ฅผ ์๋ฌธ์๋ก ๋ณํํ๊ณ 0x ์ ๊ฑฐ
$address = strtolower(str_replace('0x', '', $address));
// Reverse record ํ์: {address}.addr.reverse
$reverseNode = $address . '.addr.reverse';
$node = $this->namehash($reverseNode);
// Reverse Resolver ์ฃผ์
$reverseResolverAddress = '0x084b1c3C81545d370f3634392De611CaaBFf8148';
$resolverAbi = $this->getResolverAbi();
$contract = new Contract($this->web3->provider, $resolverAbi);
$contract->at($reverseResolverAddress);
$ensName = null;
$contract->call('name', $node, function ($err, $result) use (&$ensName) {
if (!$err && $result) {
$ensName = $result[0];
}
});
return $ensName;
} catch (\Exception $e) {
\Log::error('Reverse ENS resolution failed: ' . $e->getMessage());
return null;
}
}
/**
* ENS ์ด๋ฆ์ namehash๋ก ๋ณํ
*/
protected function namehash($name)
{
$node = str_repeat('0', 64);
if (!empty($name)) {
$labels = array_reverse(explode('.', $name));
foreach ($labels as $label) {
$labelHash = Keccak::hash($label, 256);
$node = Keccak::hash(hex2bin($node . $labelHash), 256);
}
}
return '0x' . $node;
}
/**
* ENS Registry ABI
*/
protected function getRegistryAbi()
{
return '[{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"resolver","outputs":[{"name":"","type":"address"}],"type":"function"}]';
}
/**
* ENS Resolver ABI
*/
protected function getResolverAbi()
{
return '[{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"addr","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"name","outputs":[{"name":"","type":"string"}],"type":"function"}]';
}
}
โ ๏ธ ์ฑ๋ฅ ์ต์ ํ ํ: ENS ์กฐํ๋ ๋ธ๋ก์ฒด์ธ ๋คํธ์ํฌ ํธ์ถ์ด ํ์ํด์ ์๊ฐ์ด ์ข ๊ฑธ๋ ค์. ์ค์ ํ๋ก๋์ ์์๋ Redis๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์บ์ฑํ๋ ๊ฒ ์ข์ต๋๋ค! ํนํ ์์ฃผ ์กฐํ๋๋ ENS ์ด๋ฆ์ ์บ์ TTL์ ๊ธธ๊ฒ ์ค์ ํ๋ฉด ์ฑ๋ฅ์ด ํ ์ข์์ ธ์ ใ ใ
๐ฎ Web3AuthController ๊ตฌํ
์ด์ ์ค์ ์ธ์ฆ ๋ก์ง์ ์ฒ๋ฆฌํ ์ปจํธ๋กค๋ฌ๋ฅผ ๋ง๋ค์ด๋ณผ๊ฒ์! ํ๋ก ํธ์๋์์ ํธ์ถํ API ์๋ํฌ์ธํธ๋ค์ ์ฌ๊ธฐ์ ์ ์ํฉ๋๋ค ๐ฏ
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Services\Web3Service;
use App\Services\ENSService;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
class Web3AuthController extends Controller
{
protected $web3Service;
protected $ensService;
public function __construct(Web3Service $web3Service, ENSService $ensService)
{
$this->web3Service = $web3Service;
$this->ensService = $ensService;
}
/**
* Nonce ์์ฒญ (Step 1)
* ํ๋ก ํธ์๋์์ ์๋ช
ํ ๋ฉ์์ง๋ฅผ ์์ฑํ๊ธฐ ์ํ nonce ๋ฐ๊ธ
*/
public function getNonce(Request $request)
{
$validator = Validator::make($request->all(), [
'wallet_address' => 'required|string|size:42|regex:/^0x[a-fA-F0-9]{40}$/'
]);
if ($validator->fails()) {
return response()->json([
'success' => false,
'message' => '์ ํจํ์ง ์์ ์ง๊ฐ ์ฃผ์์
๋๋ค.',
'errors' => $validator->errors()
], 400);
}
$walletAddress = strtolower($request->wallet_address);
// ๊ธฐ์กด ์ฌ์ฉ์ ํ์ธ ๋๋ ์์ nonce ์์ฑ
$user = User::where('wallet_address', $walletAddress)->first();
if (!$user) {
// ์ ๊ท ์ฌ์ฉ์์ ๊ฒฝ์ฐ ์์๋ก ์ธ์
์ nonce ์ ์ฅ
$nonce = $this->web3Service->generateNonce();
session(['temp_nonce_' . $walletAddress => $nonce]);
} else {
// ๊ธฐ์กด ์ฌ์ฉ์์ ๊ฒฝ์ฐ ์๋ก์ด nonce ์์ฑ ๋ฐ ์ ์ฅ
$nonce = $this->web3Service->generateNonce();
$user->nonce = $nonce;
$user->save();
}
$message = "์ฌ๋ฅ๋ท ๋ก๊ทธ์ธ์ ์ํด ์๋ช
ํด์ฃผ์ธ์.\n\nNonce: {$nonce}\nTimestamp: " . now()->toIso8601String();
return response()->json([
'success' => true,
'nonce' => $nonce,
'message' => $message
]);
}
/**
* ์๋ช
๊ฒ์ฆ ๋ฐ ๋ก๊ทธ์ธ ์ฒ๋ฆฌ (Step 2)
*/
public function verifySignature(Request $request)
{
$validator = Validator::make($request->all(), [
'wallet_address' => 'required|string|size:42',
'signature' => 'required|string',
'message' => 'required|string'
]);
if ($validator->fails()) {
return response()->json([
'success' => false,
'message' => 'ํ์ ํ๋ผ๋ฏธํฐ๊ฐ ๋๋ฝ๋์์ต๋๋ค.',
'errors' => $validator->errors()
], 400);
}
$walletAddress = strtolower($request->wallet_address);
$signature = $request->signature;
$message = $request->message;
// ์๋ช
๊ฒ์ฆ
$isValid = $this->web3Service->verifySignature($message, $signature, $walletAddress);
if (!$isValid) {
return response()->json([
'success' => false,
'message' => '์๋ช
๊ฒ์ฆ์ ์คํจํ์ต๋๋ค.'
], 401);
}
// Nonce ๊ฒ์ฆ (์ฌ์ ๊ณต๊ฒฉ ๋ฐฉ์ง)
$user = User::where('wallet_address', $walletAddress)->first();
$expectedNonce = $user ? $user->nonce : session('temp_nonce_' . $walletAddress);
if (!str_contains($message, $expectedNonce)) {
return response()->json([
'success' => false,
'message' => 'Nonce๊ฐ ์ผ์นํ์ง ์์ต๋๋ค.'
], 401);
}
// ENS ์ด๋ฆ ์กฐํ
$ensName = $this->ensService->resolveAddressToENS($walletAddress);
// ์ฌ์ฉ์ ์์ฑ ๋๋ ์
๋ฐ์ดํธ
if (!$user) {
$user = User::create([
'wallet_address' => $walletAddress,
'ens_name' => $ensName,
'name' => $ensName ?: substr($walletAddress, 0, 8) . '...',
'nonce' => $this->web3Service->generateNonce(),
'last_login_at' => now()
]);
} else {
$user->update([
'ens_name' => $ensName,
'nonce' => $this->web3Service->generateNonce(), // ๋ค์ ๋ก๊ทธ์ธ์ ์ํ ์ nonce
'last_login_at' => now()
]);
}
// ์ธ์
์ ๋ฆฌ
session()->forget('temp_nonce_' . $walletAddress);
// ๋ก๊ทธ์ธ ์ฒ๋ฆฌ
Auth::login($user, true);
return response()->json([
'success' => true,
'message' => '๋ก๊ทธ์ธ ์ฑ๊ณต!',
'user' => [
'id' => $user->id,
'wallet_address' => $user->wallet_address,
'ens_name' => $user->ens_name,
'name' => $user->name
]
]);
}
/**
* ๋ก๊ทธ์์
*/
public function logout(Request $request)
{
Auth::logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return response()->json([
'success' => true,
'message' => '๋ก๊ทธ์์๋์์ต๋๋ค.'
]);
}
/**
* ํ์ฌ ๋ก๊ทธ์ธ ์ฌ์ฉ์ ์ ๋ณด
*/
public function me(Request $request)
{
if (!Auth::check()) {
return response()->json([
'success' => false,
'message' => '๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค.'
], 401);
}
$user = Auth::user();
return response()->json([
'success' => true,
'user' => [
'id' => $user->id,
'wallet_address' => $user->wallet_address,
'ens_name' => $user->ens_name,
'name' => $user->name,
'last_login_at' => $user->last_login_at
]
]);
}
}
๐ ๋ณด์ ํฌ์ธํธ: Nonce๋ ์ฌ์ ๊ณต๊ฒฉ(Replay Attack)์ ๋ง๊ธฐ ์ํ ํต์ฌ ์์์์! ํ ๋ฒ ์ฌ์ฉ๋ ์๋ช ์ ๋ค์ ์ฌ์ฉํ ์ ์๋๋ก ๋งค๋ฒ ์๋ก์ด nonce๋ฅผ ์์ฑํ๊ณ ๊ฒ์ฆํด์ผ ํฉ๋๋ค. ํ์์คํฌํ๋ ํจ๊ป ์ฒดํฌํ๋ฉด ๋์ฑ ์์ ํ์ฃ ใ ใ
๐ฃ๏ธ ๋ผ์ฐํธ ์ค์
์ปจํธ๋กค๋ฌ๋ฅผ ๋ง๋ค์์ผ๋ ์ด์ ๋ผ์ฐํธ๋ฅผ ๋ฑ๋กํด์ผ๊ฒ ์ฃ ? routes/api.php ํ์ผ์ ๋ค์๊ณผ ๊ฐ์ด ์ถ๊ฐํด์ฃผ์ธ์:
<?php
use App\Http\Controllers\Auth\Web3AuthController;
use Illuminate\Support\Facades\Route;
// Web3 ์ธ์ฆ ๊ด๋ จ ๋ผ์ฐํธ
Route::prefix('auth/web3')->group(function () {
// ๊ณต๊ฐ ์๋ํฌ์ธํธ
Route::post('/nonce', [Web3AuthController::class, 'getNonce']);
Route::post('/verify', [Web3AuthController::class, 'verifySignature']);
// ์ธ์ฆ ํ์ ์๋ํฌ์ธํธ
Route::middleware('auth:sanctum')->group(function () {
Route::post('/logout', [Web3AuthController::class, 'logout']);
Route::get('/me', [Web3AuthController::class, 'me']);
});
});
๐ API ์๋ํฌ์ธํธ ์ ๋ฆฌ
| ๋ฉ์๋ | ๊ฒฝ๋ก | ์ค๋ช | ์ธ์ฆ |
|---|---|---|---|
| POST | /api/auth/web3/nonce | Nonce ๋ฐ๊ธ | ๋ถํ์ |
| POST | /api/auth/web3/verify | ์๋ช ๊ฒ์ฆ ๋ฐ ๋ก๊ทธ์ธ | ๋ถํ์ |
| POST | /api/auth/web3/logout | ๋ก๊ทธ์์ | ํ์ |
| GET | /api/auth/web3/me | ์ฌ์ฉ์ ์ ๋ณด ์กฐํ | ํ์ |
๐ป ํ๋ก ํธ์๋ ๊ตฌํ (Vue.js ์์ )
๋ฐฑ์๋ ์ค๋น๊ฐ ๋๋ฌ์ผ๋ ์ด์ ํ๋ก ํธ์๋๋ฅผ ๋ง๋ค์ด๋ณผ๊น์? Vue.js๋ก ์์ ๋ฅผ ์์ฑํ ๊ฑด๋ฐ, React๋ ๋ค๋ฅธ ํ๋ ์์ํฌ๋ ๋ก์ง์ ๊ฑฐ์ ๋น์ทํด์! ใ ใ
๐ Web3 ์ฐ๊ฒฐ ์ปดํฌ๋ํธ
<template>
<div class="web3-login">
<div v-if="!isConnected" class="connect-section">
<h2>๐ Web3 ๋ก๊ทธ์ธ</h2>
<p>๋ฉํ๋ง์คํฌ ์ง๊ฐ์ผ๋ก ๊ฐํธํ๊ฒ ๋ก๊ทธ์ธํ์ธ์!</p>
<button @click="connectWallet" :disabled="isLoading" class="connect-btn">
<span v-if="!isLoading">๐ฆ ๋ฉํ๋ง์คํฌ ์ฐ๊ฒฐ</span>
<span v-else>์ฐ๊ฒฐ ์ค...</span>
</button>
<p v-if="error" class="error-message">{{ error }}</p>
</div>
<div v-else class="user-info">
<h3>โ
๋ก๊ทธ์ธ ์๋ฃ</h3>
<div class="info-card">
<p><strong>ENS:</strong> {{ user.ens_name || '์์' }}</p>
<p><strong>์ฃผ์:</strong> {{ formatAddress(user.wallet_address) }}</p>
</div>
<button @click="logout" class="logout-btn">๋ก๊ทธ์์</button>
</div>
</div>
</template>
<script>
import { ethers } from 'ethers';
import axios from 'axios';
export default {
name: 'Web3Login',
data() {
return {
isConnected: false,
isLoading: false,
error: null,
user: null,
provider: null,
signer: null
};
},
mounted() {
this.checkConnection();
},
methods: {
/**
* ๋ฉํ๋ง์คํฌ ์ฐ๊ฒฐ ํ์ธ
*/
async checkConnection() {
try {
const response = await axios.get('/api/auth/web3/me');
if (response.data.success) {
this.isConnected = true;
this.user = response.data.user;
}
} catch (error) {
// ๋ก๊ทธ์ธ๋์ง ์์ ์ํ
this.isConnected = false;
}
},
/**
* ์ง๊ฐ ์ฐ๊ฒฐ ๋ฐ ๋ก๊ทธ์ธ
*/
async connectWallet() {
this.isLoading = true;
this.error = null;
try {
// ๋ฉํ๋ง์คํฌ ์ค์น ํ์ธ
if (!window.ethereum) {
throw new Error('๋ฉํ๋ง์คํฌ๊ฐ ์ค์น๋์ด ์์ง ์์ต๋๋ค. ๋จผ์ ์ค์นํด์ฃผ์ธ์!');
}
// Provider ๋ฐ Signer ์ด๊ธฐํ
this.provider = new ethers.BrowserProvider(window.ethereum);
// ๊ณ์ ์ฐ๊ฒฐ ์์ฒญ
const accounts = await this.provider.send('eth_requestAccounts', []);
const walletAddress = accounts[0];
this.signer = await this.provider.getSigner();
// Step 1: Nonce ์์ฒญ
const nonceResponse = await axios.post('/api/auth/web3/nonce', {
wallet_address: walletAddress
});
if (!nonceResponse.data.success) {
throw new Error('Nonce ๋ฐ๊ธ์ ์คํจํ์ต๋๋ค.');
}
const { message } = nonceResponse.data;
// Step 2: ๋ฉ์์ง ์๋ช
const signature = await this.signer.signMessage(message);
// Step 3: ์๋ช
๊ฒ์ฆ ๋ฐ ๋ก๊ทธ์ธ
const verifyResponse = await axios.post('/api/auth/web3/verify', {
wallet_address: walletAddress,
signature: signature,
message: message
});
if (verifyResponse.data.success) {
this.isConnected = true;
this.user = verifyResponse.data.user;
// ์ฑ๊ณต ์๋ฆผ
this.$toast.success('๋ก๊ทธ์ธ ์ฑ๊ณต! ํ์ํฉ๋๋ค ๐');
} else {
throw new Error(verifyResponse.data.message || '๋ก๊ทธ์ธ์ ์คํจํ์ต๋๋ค.');
}
} catch (error) {
console.error('Connection error:', error);
if (error.code === 4001) {
this.error = '์ฌ์ฉ์๊ฐ ์ฐ๊ฒฐ์ ๊ฑฐ๋ถํ์ต๋๋ค.';
} else if (error.code === -32002) {
this.error = '๋ฉํ๋ง์คํฌ์์ ์ด๋ฏธ ์ฐ๊ฒฐ ์์ฒญ์ด ๋๊ธฐ ์ค์
๋๋ค.';
} else {
this.error = error.message || '์ฐ๊ฒฐ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.';
}
} finally {
this.isLoading = false;
}
},
/**
* ๋ก๊ทธ์์
*/
async logout() {
try {
await axios.post('/api/auth/web3/logout');
this.isConnected = false;
this.user = null;
this.$toast.success('๋ก๊ทธ์์๋์์ต๋๋ค.');
} catch (error) {
console.error('Logout error:', error);
}
},
/**
* ์ฃผ์ ํฌ๋งทํ
(0x1234...5678)
*/
formatAddress(address) {
if (!address) return '';
return `${address.slice(0, 6)}...${address.slice(-4)}`;
}
}
};
</script>
<style scoped>
.web3-login {
max-width: 500px;
margin: 50px auto;
padding: 30px;
background: #ffffff;
border-radius: 16px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}
.connect-section {
text-align: center;
}
.connect-btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 15px 40px;
font-size: 16px;
font-weight: 600;
border-radius: 12px;
cursor: pointer;
transition: transform 0.2s;
margin-top: 20px;
}
.connect-btn:hover:not(:disabled) {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}
.connect-btn:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.error-message {
color: #ef4444;
margin-top: 15px;
font-size: 14px;
}
.user-info {
text-align: center;
}
.info-card {
background: #f8f9fa;
padding: 20px;
border-radius: 12px;
margin: 20px 0;
text-align: left;
}
.info-card p {
margin: 10px 0;
font-size: 14px;
}
.logout-btn {
background: #ef4444;
color: white;
border: none;
padding: 12px 30px;
border-radius: 8px;
cursor: pointer;
font-weight: 600;
}
.logout-btn:hover {
background: #dc2626;
}
</style>
๐ก UX ๊ฐ์ ํ: ๋ฉํ๋ง์คํฌ ์ฐ๊ฒฐ ์ ์ฌ์ฉ์๊ฐ ๊ฑฐ๋ถํ๊ฑฐ๋ ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ ์์ผ๋ ์๋ฌ ํธ๋ค๋ง์ ๊ผผ๊ผผํ๊ฒ ํด์ฃผ์ธ์! ํนํ error.code๋ฅผ ์ฒดํฌํด์ ์ํฉ๋ณ๋ก ์ ์ ํ ๋ฉ์์ง๋ฅผ ๋ณด์ฌ์ฃผ๋ฉด ์ฌ์ฉ์ ๊ฒฝํ์ด ํจ์ฌ ์ข์์ง๋๋ค ใ ใ
๐จ ์์ JavaScript ๋ฒ์
Vue.js ๋ง๊ณ ๋ฐ๋๋ผ JavaScript๋ก๋ ๊ตฌํํ ์ ์์ด์! ํ๋ ์์ํฌ ์์ด ๊ฐ๋จํ๊ฒ ์ฌ์ฉํ๊ณ ์ถ์ ๋ ์ ์ฉํ์ฃ ๐
// web3-auth.js
class Web3Auth {
constructor(apiBaseUrl = '/api/auth/web3') {
this.apiBaseUrl = apiBaseUrl;
this.provider = null;
this.signer = null;
this.currentUser = null;
}
/**
* ๋ฉํ๋ง์คํฌ ์ค์น ํ์ธ
*/
isMetaMaskInstalled() {
return typeof window.ethereum !== 'undefined';
}
/**
* ์ง๊ฐ ์ฐ๊ฒฐ ๋ฐ ๋ก๊ทธ์ธ
*/
async connect() {
if (!this.isMetaMaskInstalled()) {
throw new Error('๋ฉํ๋ง์คํฌ๋ฅผ ์ค์นํด์ฃผ์ธ์!');
}
try {
// Ethers.js Provider ์ด๊ธฐํ
this.provider = new ethers.BrowserProvider(window.ethereum);
// ๊ณ์ ์ฐ๊ฒฐ
const accounts = await this.provider.send('eth_requestAccounts', []);
const walletAddress = accounts[0];
this.signer = await this.provider.getSigner();
// Nonce ์์ฒญ
const nonceData = await this.fetchNonce(walletAddress);
// ๋ฉ์์ง ์๋ช
const signature = await this.signer.signMessage(nonceData.message);
// ์๋ช
๊ฒ์ฆ ๋ฐ ๋ก๊ทธ์ธ
const userData = await this.verifySignature(
walletAddress,
signature,
nonceData.message
);
this.currentUser = userData;
// ๊ณ์ ๋ณ๊ฒฝ ๊ฐ์ง
this.setupAccountChangeListener();
return userData;
} catch (error) {
console.error('Connection failed:', error);
throw error;
}
}
/**
* Nonce ์์ฒญ
*/
async fetchNonce(walletAddress) {
const response = await fetch(`${this.apiBaseUrl}/nonce`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({ wallet_address: walletAddress })
});
const data = await response.json();
if (!data.success) {
throw new Error(data.message || 'Nonce ๋ฐ๊ธ ์คํจ');
}
return data;
}
/**
* ์๋ช
๊ฒ์ฆ
*/
async verifySignature(walletAddress, signature, message) {
const response = await fetch(`${this.apiBaseUrl}/verify`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
credentials: 'include', // ์ฟ ํค ํฌํจ
body: JSON.stringify({
wallet_address: walletAddress,
signature: signature,
message: message
})
});
const data = await response.json();
if (!data.success) {
throw new Error(data.message || '๋ก๊ทธ์ธ ์คํจ');
}
return data.user;
}
/**
* ๋ก๊ทธ์์
*/
async logout() {
const response = await fetch(`${this.apiBaseUrl}/logout`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
credentials: 'include'
});
const data = await response.json();
if (data.success) {
this.currentUser = null;
this.provider = null;
this.signer = null;
}
return data;
}
/**
* ํ์ฌ ์ฌ์ฉ์ ์ ๋ณด ์กฐํ
*/
async getCurrentUser() {
const response = await fetch(`${this.apiBaseUrl}/me`, {
method: 'GET',
headers: {
'Accept': 'application/json'
},
credentials: 'include'
});
const data = await response.json();
if (data.success) {
this.currentUser = data.user;
return data.user;
}
return null;
}
/**
* ๊ณ์ ๋ณ๊ฒฝ ๊ฐ์ง
*/
setupAccountChangeListener() {
if (window.ethereum) {
window.ethereum.on('accountsChanged', (accounts) => {
if (accounts.length === 0) {
// ์ฐ๊ฒฐ ํด์ ๋จ
console.log('๋ฉํ๋ง์คํฌ ์ฐ๊ฒฐ์ด ํด์ ๋์์ต๋๋ค.');
this.logout();
} else {
// ๊ณ์ ๋ณ๊ฒฝ๋จ
console.log('๊ณ์ ์ด ๋ณ๊ฒฝ๋์์ต๋๋ค. ๋ค์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.');
window.location.reload();
}
});
window.ethereum.on('chainChanged', (chainId) => {
// ๋คํธ์ํฌ ๋ณ๊ฒฝ๋จ
console.log('๋คํธ์ํฌ๊ฐ ๋ณ๊ฒฝ๋์์ต๋๋ค.');
window.location.reload();
});
}
}
}
// ์ฌ์ฉ ์์
const web3Auth = new Web3Auth();
document.getElementById('connectBtn').addEventListener('click', async () => {
try {
const user = await web3Auth.connect();
console.log('๋ก๊ทธ์ธ ์ฑ๊ณต:', user);
// UI ์
๋ฐ์ดํธ
document.getElementById('userInfo').innerHTML = `
<p>ENS: ${user.ens_name || '์์'}</p>
<p>์ฃผ์: ${user.wallet_address}</p>
`;
} catch (error) {
console.error('๋ก๊ทธ์ธ ์คํจ:', error);
alert(error.message);
}
});
๐ ๋ณด์ ๊ณ ๋ ค์ฌํญ
Web3 ๋ก๊ทธ์ธ์ ๊ตฌํํ ๋ ๋ณด์์ ์ ๋ง ์ค์ํด์! ๋ช ๊ฐ์ง ํต์ฌ ํฌ์ธํธ๋ฅผ ์ง๊ณ ๋์ด๊ฐ์ผ ํ ๊ฒ ๊ฐ์์ ๐ก๏ธ
โ ๏ธ ์ฌ์ ๊ณต๊ฒฉ ๋ฐฉ์ง: Nonce๋ ๋ฐ๋์ ํ ๋ฒ๋ง ์ฌ์ฉ๋์ด์ผ ํด์! ์๋ช ๊ฒ์ฆ ํ์๋ ์ฆ์ ์๋ก์ด nonce๋ก ์ ๋ฐ์ดํธํ๊ณ , ์ด์ nonce๋ ์ ๋ ์ฌ์ฌ์ฉํ๋ฉด ์ ๋ฉ๋๋ค. ํ์์คํฌํ๋ ํจ๊ป ์ฒดํฌํด์ ์ค๋๋ ์๋ช ์ ๊ฑฐ๋ถํ๋ ๊ฒ ์ข์์ (์: 5๋ถ ์ด๋ด๋ง ์ ํจ)
๐ ์ถ๊ฐ ๋ณด์ ๊ฐํ ๋ฐฉ๋ฒ
1. EIP-712 ์๋ช
์ฌ์ฉ
๊ตฌ์กฐํ๋ ๋ฐ์ดํฐ ์๋ช
๋ฐฉ์์ผ๋ก, ์ฌ์ฉ์๊ฐ ์๋ช
ํ๋ ๋ด์ฉ์ ๋ช
ํํ๊ฒ ๋ณผ ์ ์์ด์. ๋จ์ ํ
์คํธ ์๋ช
๋ณด๋ค ํจ์ฌ ์์ ํฉ๋๋ค!
2. Rate Limiting
๋์ผ IP๋ ์ง๊ฐ ์ฃผ์์์ ์งง์ ์๊ฐ์ ๋๋ฌด ๋ง์ ์์ฒญ์ด ์ค๋ฉด ์ฐจ๋จํด์ผ ํด์. Laravel์ throttle ๋ฏธ๋ค์จ์ด๋ฅผ ํ์ฉํ๋ฉด ์ฝ๊ฒ ๊ตฌํ ๊ฐ๋ฅ!
3. CORS ์ค์
ํ์ฉ๋ ๋๋ฉ์ธ์์๋ง API๋ฅผ ํธ์ถํ ์ ์๋๋ก CORS๋ฅผ ์๊ฒฉํ๊ฒ ์ค์ ํ์ธ์.
4. ๋ก๊ทธ ๋ฐ ๋ชจ๋ํฐ๋ง
์์ฌ์ค๋ฌ์ด ๋ก๊ทธ์ธ ์๋๋ ์คํจํ ์๋ช
๊ฒ์ฆ์ ๋ก๊น
ํ๊ณ ๋ชจ๋ํฐ๋งํด์ผ ํด์. ์ด์ ํจํด์ด ๊ฐ์ง๋๋ฉด ์ฆ์ ์๋ฆผ!
๐ก๏ธ EIP-712 ์๋ช ๊ตฌํ ์์
์ข ๋ ์์ ํ ๋ฐฉ์์ธ EIP-712 ์๋ช ์ ๊ตฌํํด๋ณผ๊ฒ์. ์ด ๋ฐฉ์์ ๋ฉํ๋ง์คํฌ์์ ์๋ช ๋ด์ฉ์ ๊ตฌ์กฐํ๋ ํํ๋ก ๋ณด์ฌ์ค์ ์ฌ์ฉ์๊ฐ ๋ญ ์๋ช ํ๋์ง ๋ช ํํ๊ฒ ์ ์ ์์ด์ ใ ใ
// ํ๋ก ํธ์๋ - EIP-712 ์๋ช
async function signTypedData(walletAddress, nonce) {
const domain = {
name: '์ฌ๋ฅ๋ท',
version: '1',
chainId: await this.provider.getNetwork().then(n => n.chainId),
verifyingContract: '0x0000000000000000000000000000000000000000' // ์ค์ ๋ก๋ ์ปจํธ๋ํธ ์ฃผ์
};
const types = {
Login: [
{ name: 'wallet', type: 'address' },
{ name: 'nonce', type: 'string' },
{ name: 'timestamp', type: 'uint256' }
]
};
const value = {
wallet: walletAddress,
nonce: nonce,
timestamp: Math.floor(Date.now() / 1000)
};
const signature = await this.signer.signTypedData(domain, types, value);
return { signature, value };
}
// ๋ฐฑ์๋ - EIP-712 ์๋ช
๊ฒ์ฆ (Web3Service.php์ ์ถ๊ฐ)
public function verifyTypedSignature($domain, $types, $value, $signature, $address)
{
try {
// EIP-712 ํด์ ์์ฑ
$domainSeparator = $this->hashDomain($domain);
$structHash = $this->hashStruct($types, $value);
$digest = Keccak::hash(
hex2bin('1901') .
hex2bin(substr($domainSeparator, 2)) .
hex2bin(substr($structHash, 2)),
256
);
// ์๋ช
๊ฒ์ฆ
$recoveredAddress = $this->recoverAddress('0x' . $digest, $signature);
return strtolower($recoveredAddress) === strtolower($address);
} catch (\Exception $e) {
\Log::error('EIP-712 verification failed: ' . $e->getMessage());
return false;
}
}
protected function hashDomain($domain)
{
// EIP-712 ๋๋ฉ์ธ ํด์ ๊ณ์ฐ
// ... ๊ตฌํ ์๋ต
}
protected function hashStruct($types, $value)
{
// EIP-712 ๊ตฌ์กฐ์ฒด ํด์ ๊ณ์ฐ
// ... ๊ตฌํ ์๋ต
}
๐งช ํ ์คํธ ๋ฐ ๋๋ฒ๊น
๊ฐ๋ฐ์ด ๋๋ฌ๋ค๊ณ ๋ฐ๋ก ๋ฐฐํฌํ๋ฉด ์ ๋๊ฒ ์ฃ ? ใ ใ ใ ์ฒ ์ ํ ํ ์คํธ๊ฐ ํ์ํด์! ํนํ ๋ธ๋ก์ฒด์ธ ๊ด๋ จ ๊ธฐ๋ฅ์ ์ค์ ๋ฉ์ธ๋ท์์ ํ ์คํธํ๊ธฐ ์ ์ ํ ์คํธ๋ท์์ ์ถฉ๋ถํ ๊ฒ์ฆํด์ผ ํฉ๋๋ค ๐งช
๐ ํ ์คํธ ์ฒดํฌ๋ฆฌ์คํธ
โ
๋ฉํ๋ง์คํฌ ๋ฏธ์ค์น ์ํ ์ฒ๋ฆฌ
โ
์ฌ์ฉ์๊ฐ ์ฐ๊ฒฐ ๊ฑฐ๋ถํ์ ๋
โ
์๋ชป๋ ๋คํธ์ํฌ ์ฐ๊ฒฐ ์ (๋ฉ์ธ๋ท vs ํ
์คํธ๋ท)
โ
์๋ช
์ค ์ทจ์ํ์ ๋
โ
์ ํจํ์ง ์์ ์๋ช
์ ์ถ
โ
๋ง๋ฃ๋ nonce ์ฌ์ฉ
โ
ENS๊ฐ ์๋ ์ฃผ์ ์ฒ๋ฆฌ
โ
๊ณ์ ๋ณ๊ฒฝ ๊ฐ์ง
โ
๋คํธ์ํฌ ๋ณ๊ฒฝ ๊ฐ์ง
โ
๋์ ๋ค์ค ๋ก๊ทธ์ธ ์๋
๐งช PHPUnit ํ ์คํธ ์์
<?php
namespace Tests\Feature;
use Tests\TestCase;
use App\Models\User;
use App\Services\Web3Service;
use Illuminate\Foundation\Testing\RefreshDatabase;
class Web3AuthTest extends TestCase
{
use RefreshDatabase;
protected $web3Service;
protected function setUp(): void
{
parent::setUp();
$this->web3Service = new Web3Service();
}
/** @test */
public function it_can_generate_nonce()
{
$nonce = $this->web3Service->generateNonce();
$this->assertIsString($nonce);
$this->assertEquals(32, strlen($nonce)); // 16 bytes = 32 hex chars
}
/** @test */
public function it_can_request_nonce_for_new_wallet()
{
$walletAddress = '0x1234567890123456789012345678901234567890';
$response = $this->postJson('/api/auth/web3/nonce', [
'wallet_address' => $walletAddress
]);
$response->assertStatus(200)
->assertJsonStructure([
'success',
'nonce',
'message'
]);
}
/** @test */
public function it_rejects_invalid_wallet_address()
{
$response = $this->postJson('/api/auth/web3/nonce', [
'wallet_address' => 'invalid_address'
]);
$response->assertStatus(400)
->assertJson([
'success' => false
]);
}
/** @test */
public function it_can_verify_valid_signature()
{
// ํ
์คํธ์ฉ ์ง๊ฐ ์ฃผ์์ ์๋ช
(์ค์ ๋ก๋ ํ
์คํธ๋ท์์ ์์ฑ)
$walletAddress = '0xtest...';
$message = 'Test message';
$signature = '0xtest_signature...';
// Mock ์๋ช
๊ฒ์ฆ
$isValid = $this->web3Service->verifySignature($message, $signature, $walletAddress);
// ์ค์ ํ
์คํธ์์๋ ์ ํจํ ์๋ช
์ ์ฌ์ฉํด์ผ ํจ
$this->assertTrue(true); // Placeholder
}
/** @test */
public function it_creates_user_on_first_login()
{
$this->assertEquals(0, User::count());
// ๋ก๊ทธ์ธ ์๋ฎฌ๋ ์ด์
// ... (์ค์ ์๋ช
์์ฑ ๋ฐ ๊ฒ์ฆ ๊ณผ์ )
// ์ฌ์ฉ์๊ฐ ์์ฑ๋์๋์ง ํ์ธ
// $this->assertEquals(1, User::count());
}
/** @test */
public function it_updates_existing_user_on_login()
{
$walletAddress = '0x1234567890123456789012345678901234567890';
// ๊ธฐ์กด ์ฌ์ฉ์ ์์ฑ
$user = User::create([
'wallet_address' => $walletAddress,
'name' => 'Test User',
'nonce' => 'old_nonce'
]);
$oldNonce = $user->nonce;
// ๋ก๊ทธ์ธ ์๋ฎฌ๋ ์ด์
ํ nonce๊ฐ ๋ณ๊ฒฝ๋์๋์ง ํ์ธ
// ...
$user->refresh();
$this->assertNotEquals($oldNonce, $user->nonce);
}
}
๐ก ํ ์คํธ ํ: ์ค์ ๋ธ๋ก์ฒด์ธ ํธ์ถ์ด ํ์ํ ํ ์คํธ๋ Mock์ ์ฌ์ฉํ๊ฑฐ๋ ํ ์คํธ๋ท(Goerli, Sepolia)์ ํ์ฉํ์ธ์! ๋ฉ์ธ๋ท์์ ํ ์คํธํ๋ฉด ๊ฐ์ค๋น๊ฐ ๋๊ฐ๋๊น์ ใ ใ ใ ๊ทธ๋ฆฌ๊ณ CI/CD ํ์ดํ๋ผ์ธ์ ํ ์คํธ๋ฅผ ํตํฉํ๋ฉด ์๋์ผ๋ก ๊ฒ์ฆํ ์ ์์ด์ ํธํด์!
โก ์ฑ๋ฅ ์ต์ ํ
๋ธ๋ก์ฒด์ธ ํธ์ถ์ ์๊ฐ์ด ์ข ๊ฑธ๋ฆฌ๊ธฐ ๋๋ฌธ์ ์ฑ๋ฅ ์ต์ ํ๊ฐ ์ค์ํด์! ์ฌ์ฉ์๊ฐ ๊ธฐ๋ค๋ฆฌ๋ ์๊ฐ์ ์ต์ํํด์ผ ์ดํ๋ฅ ์ ์ค์ผ ์ ์์ฃ ๐
โก ์ต์ ํ ์ ๋ต
1. ENS ์กฐํ ๊ฒฐ๊ณผ ์บ์ฑ
Redis๋ Memcached๋ฅผ ์ฌ์ฉํด์ ENS ์กฐํ ๊ฒฐ๊ณผ๋ฅผ ์บ์ฑํ์ธ์. TTL์ 1์๊ฐ ์ ๋๊ฐ ์ ๋นํด์.
2. ๋น๋๊ธฐ ์ฒ๋ฆฌ
ENS ์กฐํ ๊ฐ์ ๋ฌด๊ฑฐ์ด ์์
์ ํ(Queue)๋ก ๋น๋๊ธฐ ์ฒ๋ฆฌํ๋ฉด ์๋ต ์๋๊ฐ ๋นจ๋ผ์ ธ์.
3. ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ธ๋ฑ์ค
wallet_address ์ปฌ๋ผ์ ์ธ๋ฑ์ค๋ฅผ ๊ฑธ์ด์ ์กฐํ ์๋๋ฅผ ๋์ด์ธ์.
4. CDN ํ์ฉ
Web3.js๋ Ethers.js ๊ฐ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ CDN์์ ๋ก๋ํ๋ฉด ๋น ๋ฅด๊ณ ์บ์ฑ๋ ์ ๋ผ์.
๐ฆ Redis ์บ์ฑ ๊ตฌํ
<?php
namespace App\Services;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Cache;
class ENSService
{
// ... ๊ธฐ์กด ์ฝ๋ ...
/**
* ENS ์กฐํ (์บ์ฑ ์ ์ฉ)
*/
public function resolveENSToAddressWithCache($ensName)
{
$cacheKey = 'ens:name:' . $ensName;
// ์บ์์์ ๋จผ์ ํ์ธ
$cachedAddress = Cache::get($cacheKey);
if ($cachedAddress !== null) {
\Log::info("ENS cache hit: {$ensName}");
return $cachedAddress;
}
// ์บ์ ๋ฏธ์ค - ๋ธ๋ก์ฒด์ธ์์ ์กฐํ
$address = $this->resolveENSToAddress($ensName);
// ๊ฒฐ๊ณผ ์บ์ฑ (1์๊ฐ)
if ($address) {
Cache::put($cacheKey, $address, 3600);
}
return $address;
}
/**
* ์ฃผ์๋ก ENS ์กฐํ (์บ์ฑ ์ ์ฉ)
*/
public function resolveAddressToENSWithCache($address)
{
$cacheKey = 'ens:address:' . strtolower($address);
$cachedName = Cache::get($cacheKey);
if ($cachedName !== null) {
\Log::info("Reverse ENS cache hit: {$address}");
return $cachedName;
}
$ensName = $this->resolveAddressToENS($address);
if ($ensName) {
Cache::put($cacheKey, $ensName, 3600);
}
return $ensName;
}
/**
* ์บ์ ๋ฌดํจํ
*/
public function invalidateCache($ensName = null, $address = null)
{
if ($ensName) {
Cache::forget('ens:name:' . $ensName);
}
if ($address) {
Cache::forget('ens:address:' . strtolower($address));
}
}
}
โ๏ธ ํ๋ฅผ ํ์ฉํ ๋น๋๊ธฐ ์ฒ๋ฆฌ
<?php
namespace App\Jobs;
use App\Models\User;
use App\Services\ENSService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class UpdateUserENSJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $userId;
public function __construct($userId)
{
$this->userId = $userId;
}
public function handle(ENSService $ensService)
{
$user = User::find($this->userId);
if (!$user || !$user->wallet_address) {
return;
}
// ENS ์ด๋ฆ ์กฐํ
$ensName = $ensService->resolveAddressToENSWithCache($user->wallet_address);
if ($ensName && $ensName !== $user->ens_name) {
$user->update(['ens_name' => $ensName]);
\Log::info("Updated ENS for user {$user->id}: {$ensName}");
}
}
}
// ์ปจํธ๋กค๋ฌ์์ ์ฌ์ฉ
// ๋ก๊ทธ์ธ ์ฑ๊ณต ํ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ENS ์
๋ฐ์ดํธ
UpdateUserENSJob::dispatch($user->id);
๐ ์ค์ ํ์ฉ ์ฌ๋ก
์ด๋ก ๋ง ์๋ฉด ๋ญํด์, ์ค์ ๋ก ์ด๋ป๊ฒ ํ์ฉํ๋์ง ๋ด์ผ์ฃ ! ใ ใ ใ ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ENS ๋ก๊ทธ์ธ์ ์ด๋ป๊ฒ ํ์ฉํ ์ ์๋์ง ์ดํด๋ณผ๊ฒ์ ๐จ
๐ผ ์ฌ๋ฅ๋ท์์์ ํ์ฉ ์์
1. ํฌ๋ฆฌ์์ดํฐ ํ๋กํ
์ฌ๋ฅ์ ํ๋งคํ๋ ํฌ๋ฆฌ์์ดํฐ๋ค์ด ์์ ์ ENS ์ด๋ฆ์ ํ๋กํ์ ํ์ํ ์ ์์ด์. 'creator.eth' ๊ฐ์ ๋ฉ์ง ์ด๋ฆ์ผ๋ก ๋ธ๋๋ฉํ๋ฉด ์ ๋ขฐ๋๊ฐ ์ฌ๋ผ๊ฐ์ฃ !
2. NFT ํฌํธํด๋ฆฌ์ค ์ฐ๋
์ง๊ฐ ์ฃผ์๋ก ๋ก๊ทธ์ธํ๋ฉด ํด๋น ์ฃผ์๊ฐ ๋ณด์ ํ NFT๋ฅผ ์๋์ผ๋ก ํฌํธํด๋ฆฌ์ค์ ํ์ํ ์ ์์ด์. ๋์์ด๋๋ ์ํฐ์คํธ์๊ฒ ์ ์ฉํ๊ฒ ์ฃ ?
3. ์ํธํํ ๊ฒฐ์
์ฌ๋ฅ ๊ฑฐ๋ ์ ์ํธํํ๋ก ๊ฒฐ์ ํ ์ ์๊ณ , ENS ์ด๋ฆ์ผ๋ก ๊ฐํธํ๊ฒ ์ก๊ธํ ์ ์์ด์.
4. ํ์ค์ํ ๋ฆฌ๋ทฐ ์์คํ
๋ธ๋ก์ฒด์ธ์ ๋ฆฌ๋ทฐ๋ฅผ ๊ธฐ๋กํ๋ฉด ์กฐ์์ด ๋ถ๊ฐ๋ฅํ ํฌ๋ช
ํ ํํ ์์คํ
์ ๋ง๋ค ์ ์์ด์!
5. DAO ๊ฑฐ๋ฒ๋์ค
ํ๋ซํผ ์ด์์ ๋ํ ์์ฌ๊ฒฐ์ ์ ํ ํฐ ํ๋๋ค์ด ํฌํ๋ก ๊ฒฐ์ ํ๋ DAO ์์คํ
๊ตฌ์ถ ๊ฐ๋ฅ!
๐จ ํ๋กํ ํ์ด์ง ์์
<template>
<div class="creator-profile">
<div class="profile-header">
<div class="avatar">
<img :src="avatarUrl" alt="Profile" />
</div>
<div class="profile-info">
<h1>{{ user.ens_name || formatAddress(user.wallet_address) }}</h1>
<div class="wallet-badge">
<span class="icon">๐</span>
<span class="address">{{ formatAddress(user.wallet_address) }}</span>
<button @click="copyAddress" class="copy-btn">๐</button>
</div>
<div class="stats">
<div class="stat-item">
<span class="label">๋ณด์ NFT</span>
<span class="value">{{ nftCount }}</span>
</div>
<div class="stat-item">
<span class="label">๊ฑฐ๋ ์๋ฃ</span>
<span class="value">{{ completedDeals }}</span>
</div>
<div class="stat-item">
<span class="label">ํ์ </span>
<span class="value">โญ {{ rating }}</span>
</div>
</div>
</div>
</div>
<div class="nft-gallery">
<h2>๐จ NFT ํฌํธํด๋ฆฌ์ค</h2>
<div class="nft-grid">
<div v-for="nft in nfts" :key="nft.id" class="nft-card">
<img :src="nft.image" :alt="nft.name" />
<p>{{ nft.name }}</p>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
user: {},
nfts: [],
nftCount: 0,
completedDeals: 0,
rating: 0
};
},
computed: {
avatarUrl() {
// ENS ์๋ฐํ ๋๋ ๊ธฐ๋ณธ ์ด๋ฏธ์ง
return this.user.ens_avatar || `https://api.dicebear.com/7.x/identicon/svg?seed=${this.user.wallet_address}`;
}
},
async mounted() {
await this.loadUserProfile();
await this.loadNFTs();
},
methods: {
async loadUserProfile() {
// ์ฌ์ฉ์ ์ ๋ณด ๋ก๋
const response = await axios.get('/api/user/profile');
this.user = response.data.user;
this.completedDeals = response.data.stats.completed_deals;
this.rating = response.data.stats.rating;
},
async loadNFTs() {
// Alchemy๋ Moralis API๋ก NFT ์กฐํ
const response = await axios.get(`/api/nfts/${this.user.wallet_address}`);
this.nfts = response.data.nfts;
this.nftCount = this.nfts.length;
},
formatAddress(address) {
return `${address.slice(0, 6)}...${address.slice(-4)}`;
},
copyAddress() {
navigator.clipboard.writeText(this.user.wallet_address);
this.$toast.success('์ฃผ์๊ฐ ๋ณต์ฌ๋์์ต๋๋ค!');
}
}
};
</script>
๐ ๋ฐฐํฌ ๋ฐ ์ด์
๊ฐ๋ฐ์ด ๋๋ฌ์ผ๋ฉด ์ด์ ์ค์ ์๋น์ค์ ๋ฐฐํฌํด์ผ๊ฒ ์ฃ ? ๋ฐฐํฌ ์ ์ ์ฒดํฌํด์ผ ํ ๊ฒ๋ค์ ์ ๋ฆฌํด๋ณผ๊ฒ์! ๐ฏ
โ ๋ฐฐํฌ ์ ์ฒดํฌ๋ฆฌ์คํธ
1๏ธโฃ ํ๊ฒฝ ๋ณ์ ์ค์
.env ํ์ผ์ Infura/Alchemy API ํค, Redis ์ค์ ๋ฑ ํ์ธ
2๏ธโฃ HTTPS ์ค์
๋ฉํ๋ง์คํฌ๋ HTTPS์์๋ง ์๋ํด์! Let's Encrypt๋ก SSL ์ธ์ฆ์ ๋ฐ๊ธ
3๏ธโฃ CORS ์ค์
ํ์ฉํ ๋๋ฉ์ธ๋ง ์ ํํ๊ฒ ์ค์
4๏ธโฃ Rate Limiting
API ์๋ํฌ์ธํธ์ ์ ์ ํ ์ ํ ์ค์
5๏ธโฃ ๋ก๊ทธ ๋ชจ๋ํฐ๋ง
Sentry๋ Bugsnag ๊ฐ์ ์๋ฌ ํธ๋ํน ๋๊ตฌ ์ฐ๋
6๏ธโฃ ๋ฐฑ์
์์คํ
๋ฐ์ดํฐ๋ฒ ์ด์ค ์๋ ๋ฐฑ์
์ค์
7๏ธโฃ ์ฑ๋ฅ ๋ชจ๋ํฐ๋ง
New Relic์ด๋ Laravel Telescope๋ก ์ฑ๋ฅ ์ถ์
โ๏ธ ํ๊ฒฝ ๋ณ์ ์ค์ (.env)
# Web3 ๊ด๋ จ ์ค์
INFURA_PROJECT_ID=your_infura_project_id
INFURA_PROJECT_SECRET=your_infura_secret
ALCHEMY_API_KEY=your_alchemy_api_key
# ENS ์ค์
ENS_REGISTRY_ADDRESS=0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e
ENS_REVERSE_RESOLVER=0x084b1c3C81545d370f3634392De611CaaBFf8148
# ์บ์ ์ค์
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
CACHE_DRIVER=redis
# ์ธ์
์ค์
SESSION_DRIVER=redis
SESSION_LIFETIME=120
SESSION_SECURE_COOKIE=true
SESSION_HTTP_ONLY=true
SESSION_SAME_SITE=lax
# ๋ณด์ ์ค์
WEB3_NONCE_EXPIRY=300 # 5๋ถ
WEB3_SIGNATURE_EXPIRY=300 # 5๋ถ
๐ง Nginx ์ค์ ์์
server {
listen 443 ssl http2;
server_name your-domain.com;
ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
root /var/www/your-app/public;
index index.php;
# Rate Limiting
limit_req_zone $binary_remote_addr zone=web3_auth:10m rate=10r/m;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /api/auth/web3 {
limit_req zone=web3_auth burst=5 nodelay;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
# ๋ณด์ ํค๋
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
}
โ ๏ธ ์ฃผ์์ฌํญ: ํ๋ก๋์ ํ๊ฒฝ์์๋ ๋ฐ๋์ HTTPS๋ฅผ ์ฌ์ฉํด์ผ ํด์! ๋ฉํ๋ง์คํฌ๋ ๋ณด์์์ ์ด์ ๋ก HTTP์์๋ ์๋ํ์ง ์์ต๋๋ค. ๋ํ API ํค๋ ์ํฌ๋ฆฟ์ ์ ๋ ์ฝ๋์ ํ๋์ฝ๋ฉํ์ง ๋ง๊ณ ํ๊ฒฝ ๋ณ์๋ก ๊ด๋ฆฌํ์ธ์!
๐ ํธ๋ฌ๋ธ์ํ ๊ฐ์ด๋
๊ฐ๋ฐํ๋ค ๋ณด๋ฉด ์ฌ๋ฌ ๊ฐ์ง ๋ฌธ์ ๊ฐ ์๊ธฐ๊ธฐ ๋ง๋ จ์ด์ฃ ใ ใ ใ ์์ฃผ ๋ฐ์ํ๋ ์ด์๋ค๊ณผ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ ๋ฆฌํด๋ดค์ด์! ๐ง
โ ์์ฃผ ๋ฐ์ํ๋ ๋ฌธ์ ๋ค
1. "User denied transaction signature"
์์ธ: ์ฌ์ฉ์๊ฐ ๋ฉํ๋ง์คํฌ์์ ์๋ช
์ ๊ฑฐ๋ถํจ
ํด๊ฒฐ: ์๋ฌ ํธ๋ค๋ง์ผ๋ก ์น์ ํ ์๋ด ๋ฉ์์ง ํ์
2. "Invalid signature"
์์ธ: ์๋ช
๊ฒ์ฆ ์คํจ (์๋ชป๋ ๋ฉ์์ง๋ ์ฃผ์)
ํด๊ฒฐ: ๋ฉ์์ง ํ์ ํ์ธ, ์ฃผ์ ๋์๋ฌธ์ ํต์ผ
3. "Nonce mismatch"
์์ธ: ์๋ฒ์ ํด๋ผ์ด์ธํธ์ nonce๊ฐ ์ผ์นํ์ง ์์
ํด๊ฒฐ: ์ธ์
ํ์ธ, nonce ์์ฑ/์ ์ฅ ๋ก์ง ์ ๊ฒ
4. "ENS resolution failed"
์์ธ: ENS ์ด๋ฆ์ด ๋ฑ๋ก๋์ง ์์๊ฑฐ๋ ๋คํธ์ํฌ ์ค๋ฅ
ํด๊ฒฐ: ์๋ฌ ์ฒ๋ฆฌ ํ ์ฃผ์๋ง์ผ๋ก ์งํ, ์ฌ์๋ ๋ก์ง ์ถ๊ฐ
5. "Network mismatch"
์์ธ: ๋ฉํ๋ง์คํฌ๊ฐ ๋ค๋ฅธ ๋คํธ์ํฌ์ ์ฐ๊ฒฐ๋จ
ํด๊ฒฐ: ๋คํธ์ํฌ ์ ํ ์์ฒญ ๋๋ ์๋ด ๋ฉ์์ง
6. "Rate limit exceeded"
์์ธ: Infura/Alchemy API ํธ์ถ ํ๋ ์ด๊ณผ
ํด๊ฒฐ: ์บ์ฑ ๊ฐํ, ์ ๋ฃ ํ๋ ๊ณ ๋ ค, ์ฌ๋ฌ ํ๋ก๋ฐ์ด๋ ์ฌ์ฉ
๐ ๋๋ฒ๊น ํ
// ํ๋ก ํธ์๋ ๋๋ฒ๊น
console.log('Provider:', window.ethereum);
console.log('Accounts:', await ethereum.request({ method: 'eth_accounts' }));
console.log('ChainId:', await ethereum.request({ method: 'eth_chainId' }));
console.log('Message to sign:', message);
console.log('Signature:', signature);
// ๋ฐฑ์๋ ๋๋ฒ๊น
(Laravel Log)
\Log::debug('Web3 Auth Debug', [
'wallet_address' => $walletAddress,
'message' => $message,
'signature' => $signature,
'nonce' => $nonce,
'verification_result' => $isValid
]);
๐ก ๋๋ฒ๊น ๊ฟํ: ๋ธ๋ผ์ฐ์ ๊ฐ๋ฐ์ ๋๊ตฌ์ Network ํญ์์ API ์์ฒญ/์๋ต์ ์์ธํ ํ์ธํ์ธ์! ํนํ ์๋ช ๊ฒ์ฆ ์คํจ ์ ์์ฒญ ๋ฐ๋์ ์๋ต์ ๋น๊ตํด๋ณด๋ฉด ๋ฌธ์ ๋ฅผ ์ฝ๊ฒ ์ฐพ์ ์ ์์ด์ ใ ใ
๐ ์ถ๊ฐ ํ์ต ์๋ฃ
๋ ๊น์ด ๊ณต๋ถํ๊ณ ์ถ๋ค๋ฉด ์ด๋ฐ ์๋ฃ๋ค์ ์ฐธ๊ณ ํด๋ณด์ธ์! ๊ณ์ ๋ฐ์ ํ๋ Web3 ์ํ๊ณ๋ฅผ ๋ฐ๋ผ๊ฐ๋ ค๋ฉด ๊พธ์คํ ํ์ต์ด ํ์ํ๋ต๋๋ค ๐
๐ ์ถ์ฒ ๋ฆฌ์์ค
๊ณต์ ๋ฌธ์
โข ENS ๊ณต์ ๋ฌธ์: docs.ens.domains
โข Ethers.js ๋ฌธ์: docs.ethers.org
โข Web3.php ๋ฌธ์: github.com/web3p/web3.php
โข Laravel ๋ฌธ์: laravel.com/docs
ํํ ๋ฆฌ์ผ & ๊ฐ์ด๋
โข Ethereum.org ๊ฐ๋ฐ์ ๊ฐ์ด๋
โข OpenZeppelin ๋ณด์ ๊ฐ์ด๋
โข Alchemy University ๋ฌด๋ฃ ๊ฐ์ข
์ปค๋ฎค๋ํฐ
โข Ethereum Stack Exchange
โข Laravel ํ๊ตญ ์ปค๋ฎค๋ํฐ
โข Web3 ๊ฐ๋ฐ์ ๋์ค์ฝ๋
โข ์ฌ๋ฅ๋ท ๊ฐ๋ฐ์ ํฌ๋ผ (๊ณง ์คํ ์์ ! ใ
ใ
)
๐ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์... ์ฌ๊ธฐ๊น์ง ์ค๋๋ผ ๊ณ ์ ๋ง์ผ์ จ์ด์! ใ ใ ใ ๋ผ๋ผ๋ฒจ์์ ENS ๋ก๊ทธ์ธ์ ๊ตฌํํ๋ ์ ๊ณผ์ ์ ๋ค๋ค๋ดค๋๋ฐ, ์๊ฐ๋ณด๋ค ๋ณต์กํ์ง๋ง ํ ๋ฒ ๊ตฌํํด๋์ผ๋ฉด ์ ๋ง ๋ฉ์ง ๊ธฐ๋ฅ์ด ๋์ฃ ๐
Web3๋ ์์ง ๋ฐ์ ์ค์ธ ๊ธฐ์ ์ด๋ผ ๊ณ์ ์๋ก์ด ํ์ค๊ณผ ๋ฒ ์คํธ ํ๋ํฐ์ค๊ฐ ๋์ค๊ณ ์์ด์. EIP-4361 (Sign-In with Ethereum) ๊ฐ์ ์๋ก์ด ํ์ค๋ ๋์์ผ๋ ๊ด์ฌ ์์ผ๋ฉด ์ฐพ์๋ณด์ธ์!
๐ฏ ํต์ฌ ์์ฝ
โ
ENS ๋ก๊ทธ์ธ์ ๋น๋ฐ๋ฒํธ ์๋ ์์ ํ ์ธ์ฆ ๋ฐฉ์
โ
๋ฉํ๋ง์คํฌ ์๋ช
โ ์๋ฒ ๊ฒ์ฆ โ ์ธ์
์์ฑ ์์
โ
Nonce์ ํ์์คํฌํ๋ก ์ฌ์ ๊ณต๊ฒฉ ๋ฐฉ์ง
โ
ENS ์กฐํ ๊ฒฐ๊ณผ๋ ๋ฐ๋์ ์บ์ฑ
โ
์๋ฌ ํธ๋ค๋ง๊ณผ ์ฌ์ฉ์ ๊ฒฝํ์ด ์ค์
โ
HTTPS์ ๋ณด์ ์ค์ ์ ํ์
โ
ํ
์คํธ๋ท์์ ์ถฉ๋ถํ ๊ฒ์ฆ ํ ๋ฐฐํฌ
์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ Web3 ๊ธฐ์ ์ ๋์ ํ๋ฉด ์ฌ์ฉ์๋ค์๊ฒ ์๋ก์ด ๊ฒฝํ์ ์ ๊ณตํ ์ ์์ด์. ํนํ ํฌ๋ฆฌ์์ดํฐ ์ด์ฝ๋ ธ๋ฏธ์ ๋ธ๋ก์ฒด์ธ์ ๊ฒฐํฉ์ ์์ผ๋ก ๋์ฑ ์ค์ํด์ง ๊ฑฐ์์!
์ด ๊ธ์ด ์ฌ๋ฌ๋ถ์ ํ๋ก์ ํธ์ ๋์์ด ๋์์ผ๋ฉด ์ข๊ฒ ๋ค์ ใ ใ ๊ถ๊ธํ ์ ์ด๋ ์ถ๊ฐ๋ก ์๊ณ ์ถ์ ๋ด์ฉ์ด ์๋ค๋ฉด ์ฌ๋ฅ๋ท ์ปค๋ฎค๋ํฐ์์ ์ธ์ ๋ ๋ฌผ์ด๋ณด์ธ์! ํจ๊ป ์ฑ์ฅํ๋ ๊ฐ๋ฐ์ ์ปค๋ฎค๋ํฐ๋ฅผ ๋ง๋ค์ด๊ฐ์ ๐
๐ ๋ณด๋์ค ํ: ์ด ๊ธ์์ ๋ค๋ฃฌ ์ฝ๋๋ค์ GitHub์ ์คํ์์ค๋ก ๊ณต๊ฐํ ์์ ์ด์์! ์ค์ ๋์ํ๋ ์ ์ฒด ํ๋ก์ ํธ๋ฅผ ๋ณด๊ณ ์ถ๋ค๋ฉด ์ฌ๋ฅ๋ท ๊ฐ๋ฐ์ ํ์ด์ง๋ฅผ ์ฃผ๋ชฉํด์ฃผ์ธ์ ใ ใ
Happy Coding! ๐จโจ
- Web3 ์๋๋ฅผ ํจ๊ป ๋ง๋ค์ด๊ฐ๋ ๊ฐ๋ฐ์ ์ฌ๋ฌ๋ถ์ ์์ํฉ๋๋ค -
๐ผ ์ฌ๋ฅ๋ท์์ ์ฌ๋ฌ๋ถ์ ๊ฐ๋ฐ ์ฌ๋ฅ์ ๊ณต์ ํ๊ณ
Web3 ํ๋ก์ ํธ๋ฅผ ํจ๊ป ๋ง๋ค์ด๋ณด์ธ์!
๋ธ๋ก์ฒด์ธ ๊ฐ๋ฐ๋ถํฐ ํ๋ก ํธ์๋, ๋ฐฑ์๋๊น์ง
๋ค์ํ ์ฌ๋ฅ์ด ๋ชจ์ด๋ ๊ณณ, ์ฌ๋ฅ๋ท์
๋๋ค ๐
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.