[10/02] ICT COG 블록체인 테크니컬 트랙 1

장 창영·2021년 10월 18일
0
post-thumbnail

1. Geth 환경구축

1-1. 홈페이지 접속

1-2. MacOS 설치

1-3. MacOS 터미널 실행

sudo cp ~/Downloads/geth-darwin-amd64-1.10.10-bb74230f/geth /usr/local/bin/

2. Geth로 구축한 노드의 디렉터리 구조

2-1. 노드구동

geth --datadir $PWD

Initialised chain configuration config="{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Byzantium: 4370000 Constantinople: 7280000 Petersburg: 7280000 Istanbul: 9069000, Muir Glacier: 9200000, Berlin: 12244000, London: 12965000, Engine: ethash}"
London: IP1559에서 추가된 트랜잭션 사용가능
Engine: ethash(POW) / qlicue(POA)

신뢰? 데이터를 정확히 전달
TCP: 신뢰보장 o / 속도느림
UDP: 신뢰보장 x / 속도빠름

2-2. 디렉터리 구조

geth: 블록체인에서 생성되는 모든 데이터 관리
keystone: 해당 노드에서 생성되는 키스토어 파일 관리

2-3. 계정생성

2-4. 키스토어 파일

3. 이더리움 계정이해

3-1. 키스토어 파일 목적

geth --datadir $PWD account new

3-2. 키스토어 파일 생성원리(암호화)


프라이빗키 중요 -> 보안은 어떻게?

키스토어 파일!
키스토어 파일 + 비밀번호 -> 프라이빗키!

두 개의 알고리즘 = aes: 프라이빗키를 복구 + scrypt: 비밀번호를 암호화!

입력한 키스토어 패스-워드 암호화

KeyStore비밀번호 + KDF(파라미터) -SCRYPT알고리즘-> Derived Key

암호화된 패스-워드로 private key 암호화

암호화된 결과를 이용하여 MAC 생성

3-3. 키스토어 파일 생성원리(복호화)

입력받은 패스-워드를 이용하여 derived key 생성

derived key와 키스토어파일의 cipher text를 이용하여 Mac 생성

키스토어에 적힌 mac과 비교

private key 복구

프라이빗키 = 할당된 주소(지갑)의 소유권
지갑을 생성 x / 생성된 지갑에 할당 o
-> state 변화 = 지갑 생성 x, 트랜잭션 o

3-4. Question

Q: KeyStore 파일에 Scrypt 결과값은 저장하지 않을까?

A: Scrypt의 결과값은 Private Key를 복호화하는데 사용하는 키

Q: Scrypt를 KeyStore 파일에서 사용하는 이유?

A: Scrypt는 현존하는 단방향 해시함수 중 가장 강력한 알고리즘 중 하나.
알고리즘 자체가 결과값을 생성할 때 메모리 오버헤드를 갖도록 설계되어 bruteforce(0부터 하나씩 넣기)공격이 힘들게 설계.

3-5. mnemonic

하나의 지갑으로 여러개의 계정 관리? mnemonic
마스터노드/account/.../
master seed가 동일하면 동일한 private key, address

니모닉 생성 후 하나의 private key, address 생성

const bip39 = require("bip39");
const { hdkey } = require("ethereumjs-wallet");

const mnemonic = bip39.generateMnemonic();
console.log(`mnemonic is : "${mnemonic}"`);
 
(async () => {
	const seed = await bip39.mnemonicToSeed(mnemonic); // seed === entropy
    const rootKey = hdkey.fromMasterSeed(seed);
	const hardenedKey = rootKey.derivePath("m/44'/60'/0'/0");
	const childKey = hardenedKey.deriveChild(0); // 값조정 가능
 	const wallet = childKey.getWallet();
    const address = wallet.getAddress();
 	const privateKey = wallet.getPrivateKey();
 	console.log(`seed is ${seed.toString('hex')}`)
    
 	console.log(`======== rootKey =======`)
 	console.log(rootKey)
    
 	console.log(`======= childKey =======`)
 	console.log(childKey)
    
 	console.log(`======= wallet is =======`)
 	console.log(wallet)
    
 	console.log(`address is ${address.toString("hex")}`);
    console.log(`privateKey is ${privateKey.toString("hex")}`);
})()

니모닉 생성 후 10개의 private key, address 생성

여기서 생성된 니모닉으로 타 지갑에서 사용하면 동일한 계정생성

const bip39 = require("bip39");
const { hdkey } = require("ethereumjs-wallet");

const mnemonic = bip39.generateMnemonic();
console.log(`mnemonic is : "${mnemonic}"`);

(async () => {
	const seed = await bip39.mnemonicToSeed(mnemonic); // seed === entropy
 	const rootKey = hdkey.fromMasterSeed(seed);
 	const hardenedKey = rootKey.derivePath("m/44'/60'/0'/0");
 	console.log(`seed is ${seed.toString('hex')}`)
 
 	for (let i = 0; i < 10; i++) {
 		console.log(i)
 		const childKey = hardenedKey.deriveChild(i); // 값조정 가능
 		const wallet = childKey.getWallet();
        const address = wallet.getAddress();
 		const privateKey = wallet.getPrivateKey();
 
 		console.log(`<CHILDKEY>`)
		 console.log(childKey)
 
 		console.log(`<WALLET IS>`)
		console.log(wallet)
 
 		console.log(`[address] ${address.toString("hex")}`);
 		console.log(`[privateKey] ${privateKey.toString("hex")}`);
 		console.log('============')
 } })()

앞의 코드를 활용하여 니모닉 생성 후 3개의 private key, address 생성

생성된 니모닉을 metamask에서 사용한 후 생성된 계정 주소 비교

0개의 댓글

관련 채용 정보