Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. //src/wallet.ts
  2.  
  3. // 개인키 의 위치를 설정한다.
  4. const privateKeyLocation = 'node/wallet/private_key';
  5.  
  6. // 개인키가 생성되는 과정이다.
  7. const generatePrivatekey = (): string => {
  8. const keyPair = EC.genKeyPair();
  9. const privateKey = keyPair.getPrivate();
  10. return privateKey.toString(16);
  11. };
  12.  
  13. // 개인키가 지갑에 저장되는 과정이다.
  14. const initWallet = () => {
  15. //이미 개인키가 존재한다면 덮어쓰지는 않는다.
  16. if (existsSync(privateKeyLocation)) {
  17. return;
  18. }
  19. const newPrivateKey = generatePrivatekey();
  20.  
  21. writeFileSync(privateKeyLocation, newPrivateKey);
  22. console.log('new wallet with private key created');
  23. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement