โ ํ์ค ์ค๋ช
- BIP-39๋ ๋๋ชจ๋ ๋ฌธ๊ตฌ(mnemonic phrase)์ ์ ํ์ ํจ์คํ๋ ์ด์ฆ(passphrase)๋ฅผ ์ฌ์ฉํ์ฌ **512๋นํธ ์๋(seed)**๋ฅผ ์์ฑํฉ๋๋ค.
- ์ง๊ฐ ๋ณต๊ตฌ ์ ์ฌ์ฉํ๋ “๋จ์ด ๋ฆฌ์คํธ”๋ ์ด ๋จ๊ณ์ ํด๋นํฉ๋๋ค.
๐งฉ wallet-core ๋ด๋ถ ๋์
- ํ์ผ:
HDWallet.cpp
cppCopyEditHDWallet::HDWallet(const std::string& mnemonic, const std::string& passphrase) {
const auto seed = mnemonicToSeed(mnemonic, passphrase);
this->seed = Data(seed.begin(), seed.end());
}
- ๋ด๋ถ ํจ์
mnemonicToSeed๋Trezor-crypto๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ:
cppCopyEditmnemonic_to_seed(mnemonic.c_str(), passphrase.c_str(), seed, nullptr);
๐งญ BIP-44: ๊ณ์ธต์ ํค ํ์ (HD Wallet)
โ ํ์ค ์ค๋ช
- ๊ฒฝ๋ก ๊ตฌ์กฐ:
m / purpose' / coin_type' / account' / change / address_index - BIP-44๋ ๋ชฉ์ (Purpose) =
44'๋ฅผ ๊ณ ์ ํ๋ฉฐ, ๋ค์ํ ์ฝ์ธ์ ์ง์ํ๊ธฐ ์ํ coin_type ํ๋๋ฅผ ํฌํจํฉ๋๋ค.
์: ์ด๋๋ฆฌ์ ์ฃผ์: m/44'/60'/0'/0/0
๐งฉ wallet-core ๋ด๋ถ ๋์
- ํ์ผ:
DerivationPath.cpp๋ฐCoin.cpp
cppCopyEditauto path = DerivationPath("m/44'/60'/0'/0/0");
PrivateKey privKey = hdWallet.getKey(path);
auto pubKey = privKey.getPublicKey(TWPublicKeyTypeSECP256k1);
auto address = Ethereum::Address(pubKey);
getKey(path)๋ ์๋๋ฅผ ๊ธฐ๋ฐ์ผ๋ก HMAC-SHA512 ํ์์ ํตํด private key๋ฅผ ์ ๋ํฉ๋๋ค.
๐ BIP-84: Native SegWit (๋นํธ์ฝ์ธ ์ ์ฉ)
โ ํ์ค ์ค๋ช
- ๊ฒฝ๋ก ๊ตฌ์กฐ:
m/84'/0'/0'/0/0 - Bech32 (bc1…) ์ฃผ์ ํฌ๋งท์ ์์ฑํ๋ฉฐ, ๋นํธ์ฝ์ธ์ ์ธ๊ทธ์(segwit) ๊ธฐ๋ฅ์ ์ต๋ํ ํ์ฉํ๋ ๋ฐฉ์.
๐งฉ wallet-core ๋ด๋ถ ๋์
- ๋นํธ์ฝ์ธ ๊ณ์ด ์ฝ์ธ์
Coin.cpp์ coinType ๋ณdefaultDerivationPath์ ์๊ฐ ์์ต๋๋ค:
cppCopyEdit// BIP84 - Native Segwit
if (coin == TWCoinTypeBitcoin) {
return DerivationPath("m/84'/0'/0'/0/0");
}
- ์ค์ ์ฃผ์ ์์ฑ์ ๋ค์์ฒ๋ผ ์ฒ๋ฆฌ:
cppCopyEditauto privKey = wallet.getKey(coin, derivationPath);
auto pubKey = privKey.getPublicKey(TWPublicKeyTypeSECP256k1);
auto addr = Bitcoin::Bech32Address(pubKey, HRP); // bc1q...
๐ ํต์ฌ ๊ด๋ จ ํ์ผ ์ ๋ฆฌ
| ๊ธฐ๋ฅ | ๊ฒฝ๋ก | ์ค๋ช |
|---|---|---|
| BIP-39 ์๋ ์์ฑ | HDWallet.cpp, TrezorCrypto/mnemonic.c | ๋๋ชจ๋ โ ์๋ |
| BIP-44 ๊ฒฝ๋ก ํ์ฑ | DerivationPath.cpp | ๊ฒฝ๋ก ๋ฌธ์์ด โ ์ซ์ ๋ฐฐ์ด |
| ํค ํ์ (44, 84 ๊ณตํต) | HDWallet::getKey(...) | ์๋ โ private key |
| ์ฃผ์ ์์ฑ | Coin.cpp, Bitcoin/Address.*, Ethereum/Address.* | pubkey โ address |
| ์ฝ์ธ๋ณ ๊ฒฝ๋ก ์ง์ | Coin.cpp | BIP-44 vs BIP-84 ๋ฑ ์ ์ฉ |
๐ง ์์ฝ ํ๋ฆ๋
csharpCopyEdit[Mnemonic (BIP-39)]
โ
[Seed: 512bit]
โ
[DerivationPath (BIP-44/84)]
โ
[Private Key]
โ
[Public Key]
โ
[Address: Coin-specific format]
๋ต๊ธ ๋จ๊ธฐ๊ธฐ