๐Ÿง‘๐Ÿปโ€๐Ÿ’ป Mnemonic ์ง€๊ฐ‘ ๊ฐœ๋ฐœ๊ธฐ

ZEKEยท2022๋…„ 2์›” 8์ผ
0
post-thumbnail

>>> Github์ฃผ์†Œ Github_MnemonicWallet

๐Ÿ“Œ ๊ฐœ๋ฐœ๋ชฉํ‘œ

์˜ค๋Š˜์€ eth-lightwallet๋ชจ๋“ˆ์— ์žˆ๋Š” ๋‚ด์žฅํ•จ์ˆ˜๋ฅผ ํ† ๋Œ€๋กœ node.js๋ฅผ ์ด์šฉํ•œ ์„œ๋ฒ„๊ฐœ๋ฐœ๊ณผ react๋ฅผ ์ด์šฉํ•œ client๊ฐœ๋ฐœ๋กœ ๊ธฐ๋ณธ ๋‹ˆ๋ชจ๋‹‰์ง€๊ฐ‘ ๊ฐœ๋ฐœ์— ํ•„์š”ํ•œ ๋ถ€๋ถ„์„ ์„œ๋ฒ„๋ฅผ ํ†ตํ•ด ์‘๋‹ต๋ฐ›๊ณ  ์ง€๊ฐ‘์ฃผ์†Œ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ํ™”๋ฉด์„ ์™„์„ฑํ•ด๋ณผ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๐Ÿ“Œ ๋‹ˆ๋ชจ๋‹‰ ์ดํ•ดํ•˜๊ธฐ

๋ธ”๋ก์ฒด์ธ์—์„œ๋Š” ํ•˜๋‚˜์˜ ์‹œ๋“œํ‚ค(seed key)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฌ๋Ÿฌ ๊ณ„์ •์„ ์ƒ์„ฑํ•ด ๋‚ด๋Š” ์ง€๊ฐ‘๋“ค์ด ์กด์žฌํ•˜๋Š”๋ฐ ์ด๋ฅผ ๊ณ„์ธต์  ๊ฒฐ์ • ์ง€๊ฐ‘์ด๋ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ์ค‘ ๋‹ˆ๋ชจ๋‹‰์€ ํ•ด์‹ฑ๋˜์–ด ๊ธฐ์–ต๋˜๊ธฐ ์–ด๋ ค์šด ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง„ ์‹œ๋“œํ‚ค๋ฅผ ๊ธฐ์–ตํ•˜๊ธฐ ์‰ฝ๋„๋ก ์ž„์˜์˜ ์˜๋‹จ์–ด๋กœ ์น˜ํ™˜ํ•˜์—ฌ ์ƒ์„ฑํ•ด์ฃผ๋Š” ๊ฒƒ์„ ๋งํ•ฉ๋‹ˆ๋‹ค. ๋‹ˆ๋ชจ๋‹‰์œผ๋กœ ์‹œ๋“œ๊ฐ’์„ ์ƒ์„ฑํ•˜๋ฉด ์ƒ์„ฑํ•œ ์‹œ๋“œ๊ฐ’์—์„œ ํŒŒ์ƒํ•˜์—ฌ ์—ฌ๋Ÿฌ ๊ณ„์ •์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

๐Ÿ“Œ ๊ฐœ๋ฐœ๋‹จ๊ณ„

๊ฐœ๋ฐœ์…‹ํŒ…

  1. ๊ณตํ†ต
mkdir MnemonicWallet
mkdir server
creaete-react-app client
  1. client
cd client 
npm intall axios
  1. server
cd server
npm init
npm install express
npm install cors
npm install nodemon
npm install eth-lightwallet
touch index.js
mkdir routes
cd routes
touch index.js
cd ..
mkdir controllers
cd controllers
touch index.js

๊ฐœ๋ฐœ๊ณผ์ • ์ƒ๊ฐํ•ด๋ณด๊ธฐ

eth-lightwallet_GitํŽ˜์ด์ง€ ์™€ eth-ligthwallet_npm ์ฐธ๊ณ ํ•˜์—ฌ ๊ฐœ๋ฐœ๊ณผ์ • ์ƒ๊ฐํ•ด๋ณด๊ธฐ

  1. client
  • ์‘๋‹ต ๋ฐ›์€ ๋‹ˆ๋ชจ๋‹‰ ์ฝ”๋“œ ์ถœ๋ ฅ
  • ๋‹ˆ๋ชจ๋‹‰์ฝ”๋“œ ์ž…๋ ฅํ•˜๊ณ  ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ์‹œ ์ƒ์„ฑ๋œ ์ง€๊ฐ‘ ์ถœ๋ ฅ
  1. server
    routes์—์„œ ์ƒˆ๋กœ์šด mnemonic์ƒ์„ฑ์„ ์œ„ํ•œ ์—”ํŠธํฌ์ธํŠธ newmnemonic๊ณผ ์ƒˆ๋กœ์šด ๊ณ„์ • ์ƒ์„ฑ ์œ„ํ•œ newwallet์œผ๋กœ ๋ถ„๊ธฐํ•˜๊ธฐ

  2. ํด๋”๊ตฌ์กฐ

์ฃผ์š”์ฝ”๋“œ

  1. client
    ํด๋ผ์ด์–ธํŠธ์—์„œ server๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด๋Š” ์ฝ”๋“œ๋กœ ๊ฐ๊ฐ Mnemonic ๋ฌธ์žฅ๊ณผ ์ƒ์„ฑ๋œ ๊ณ„์ •์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
// newMnemonic
axios
.post("http://localhost:4000/wallet/newmnemonic", {
  headers: {
    "Content-Type": "application/json",
  },
  withCredentials: true,
})
  .then((res) => {
  setNewMnemonic(res.data);
});

// newWallet
axios
.post(
  "http://localhost:4000/wallet/newwallet",
  {
    mnemonic: newMnemonic,
    pwd: pwd,
  },
  {
    headers: {
      "Content-Type": "application/json",
    },
    withCredentials: true,
  }
)
  .then((res) => {
  setAddress(res.data.address);
  setKeystore(res.data.keystore);
});
  1. server
    ํ•ด๋‹น ์—”๋“œํฌ์ธํŠธ๋กœ ์š”์ฒญ์ด ์˜ค๋ฉด eth-lightwallet ์ด์šฉํ•ด์„œ ๋žœ๋คSeed๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์ƒ์„ฑ๋œ Mnemonic๊ณผ ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ password๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์ƒˆ๋กœ์šด ๊ณ„์ •์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
// newMnemonic
newmnemonic: {
    post: async (req, res) => {
      let mnimonic;
      try {
        mnemomic = lightwallet.keystore.generateRandomSeed();
        res.send(mnemomic);
      } catch (err) {
        console.log(err);
      }
    },
  }

// newWallet
newwallet: {
    post: async (req, res) => {
      const mnemonic = req.body.mnemonic;
      const password = req.body.pwd;
      console.log(mnemonic);
      try {
        lightwallet.keystore.createVault(
          {
            password: password,
            seedPhrase: mnemonic,
            hdPathString: "m/0'/0'/0'",
          },
          function (err, ks) {
            ks.keyFromPassword(password, function (err, pwDerivedKey) {
              ks.generateNewAddress(pwDerivedKey, 1);

              let address = ks.getAddresses().toString();
              let keystore = ks.serialize();

              res.json({ keystore: keystore, address: address });
            });
          }
        );
      } catch (exception) {
        console.log(` >>> newWallet ${exception}`);
      }
    },
  }

๊ฒฐ๊ณผ

์ƒ์„ฑ๋œ keystore

์›นํ™”๋ฉด ๋™์ž‘

์‹คํ–‰ ๋ฐฉ๋ฒ•

Github ์ฃผ์†Œ ํ†ตํ•ด ์‹คํ–‰ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“Œ ๊ฐœ๋ฐœํšŒ๊ณ 

KEEP

๋‹ˆ๋ชจ๋‹‰ ์ง€๊ฐ‘ ๊ฐœ๋ฐœ์„ ํ†ตํ•ด์„œ ์ผ๋‹จ ๋ชจ๋“ˆ์˜ ์†Œ์ค‘ํ•จ๊ณผ ๋งŒ๋“ค์–ด์ง„ ๋ชจ๋“ˆ๋“ค์„ ์ž˜ ์ดํ•ดํ•˜๊ณ  ๊ฐœ๋ฐœํ•˜๋Š” ๊ณผ์ •์˜ ์ค‘์š”์„ฑ๋„ ๋‹ค์‹œ๊ธˆ ๊นจ๋‹ซ๋Š” ์‹œ๊ฐ„์ด ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋ชจ๋“ˆ์„ ํ†ตํ•ด ๋‹ˆ๋ชจ๋‹‰ ์ง€๊ฐ‘์ด ์–ด๋–ค ๊ณผ์ •์œผ๋กœ ๋งŒ๋“ค์–ด ์ง€๋Š”์ง€ ์ด๋ก ์œผ๋กœ๋งŒ ํ•™์Šตํ–ˆ๋˜ ๋‚ด์šฉ์„ ์ ์šฉํ•ด ๋ณผ ์ˆ˜ ์žˆ๊ฒŒ ๋˜๋Š” ์‹œ๊ฐ„์ด์—ˆ์Šต๋‹ˆ๋‹ค.

PROBLEM

CSS๋Š” ์—ญ์‹œ ์–ด๋ ต๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.
๋ฐ์ดํ„ฐ๋ฅผ ์•„๋ฌด๋ฆฌ ์ž˜ ๊ฐ€์ ธ์™€๋„ ๊น”๋”ํ•˜๊ฒŒ ๋ณด์—ฌ์ค„ ์ˆ˜ ์—†๋‹ค๋ฉด ๋ฏธ์™„์„ฑ์˜ ๋Š๋‚Œ์ด ๋‚˜๊ฒ ๋‹ค๋ผ๋Š” ๋Š๋‚Œ์ด ๋“ค์–ด ๊ตฌ์กฐ์ ์œผ๋กœ CSS๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ์ถ”๊ฐ€์ ์ธ ํ•™์Šต์ด ํ•„์š”ํ•˜๋‹ค ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.

TRY

์ถ”๊ฐ€์ ์œผ๋กœ, keystore๋ฅผ ์›น๋ธŒ๋ผ์šฐ์ €๋ฅผ ํ†ตํ•ด ๋‹ค์šด ๋ฐ›์•„ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

profile
MAKE SOMETHING

0๊ฐœ์˜ ๋Œ“๊ธ€