Chang-Wu Chen
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# Homework 1 ## 作業繳交 :::danger :warning: 注意 - Deadline: 10/30 (before 11:59pm) - How to submit? Register an account on https://github.com/ and push your code and the answer there. For question 2, please attach your source code. - Last, submit your repo url to the coursework via https://classroom.google.com/u/0/c/MTE2MzEyMzM4NjRa. ::: ## 作業環境 > 不限程式語言 1. 安裝 Node.js 2. 安裝下列套件 ```javascript $ npm install ethereumjs-wallet $ npm install js-sha3 ``` 3. 測試是否執行成功 開一個檔案將下列程式碼存在 `key.js` ```javascript= // npm-library const Wallet = require('ethereumjs-wallet'); const keccak256 = require('js-sha3').keccak256; // keypair const wallet = Wallet.generate(); // privKey const privKey = wallet.getPrivateKey(); console.log("privKey:", privKey); // pubKey const pubKey = wallet.getPublicKey(); console.log("pubKey:", pubKey); // address let address = wallet.getAddressString(); console.log("address:", address); ``` 執行 `key.js`,若看到下列畫面表示成功 ``` $ node key.js privKey: <Buffer c7 49 b3 89 eb c3 28 3f 2e 52 5f fe 46 93 70 ed 37 64 85 1a 24 81 6d 56 54 cd 9d 99 f2 c1 2e f6> pubKey: <Buffer 30 92 f7 ed ac aa 49 e0 f1 74 ea 63 53 ce be 65 aa 3f 73 32 18 51 62 cc 00 2f 23 9b 35 86 58 83 d7 bc c6 fd 49 69 b8 80 45 91 32 fe 6d c1 9d fa 6d 64 ... > address: 0x759c946e5306e7e6498f4286055a931fe7b08882 ``` - 註:Windows 10 作業系統建置 Node.js 開發環境可參考此[連結](/c/S1V4HngYX/%2FUzEjDQFdTQuEjhtVdaNcXg)。 --- ## 作業描述 #### (20%) 1. Please compare hash function and cryptographic hash function and give an example. #### (80%) 2. Peter is a noob in cryptocurrency and would like to get some Ethers. First step for him is to have an Ethereum account. He decides to generate an account and manages the wallet himself so he can understand the principles behind. From the class, he knows the account is created by the following steps: 1. Create a keypair of private/public key 2. public_key = ECDSA(private_key) 3. public_key_hash = Keccak-256(public_key) 4. address = `'0x'` + last 20 bytes of public_key_hash #### Reference - [Create Full Ethereum Wallet, Keypair and Address](https://kobl.one/blog/create-full-ethereum-keypair-and-address/) - [How are ethereum addresses generated?](https://ethereum.stackexchange.com/questions/3542/how-are-ethereum-addresses-generated) The following is the sample code to create an address and a pair of private/public key. ```javascript= const Wallet = require('ethereumjs-wallet'); const keccak256 = require('js-sha3').keccak256; // keypair const wallet = Wallet.generate(); // privKey const privKey = wallet.getPrivateKey(); console.log("privKey:", privKey); // pubKey const pubKey = wallet.getPublicKey(); console.log("pubKey:", pubKey); // address let address = wallet.getAddressString(); console.log("address:", address); ``` The output is like this: ``` $ node key.js privKey: <Buffer c7 49 b3 89 eb c3 28 3f 2e 52 5f fe 46 93 70 ed 37 64 85 1a 24 81 6d 56 54 cd 9d 99 f2 c1 2e f6> pubKey: <Buffer 30 92 f7 ed ac aa 49 e0 f1 74 ea 63 53 ce be 65 aa 3f 73 32 18 51 62 cc 00 2f 23 9b 35 86 58 83 d7 bc c6 fd 49 69 b8 80 45 91 32 fe 6d c1 9d fa 6d 64 ... > address: 0x759c946e5306e7e6498f4286055a931fe7b08882 ``` #### (30%) a. Can you print the private/public key with hex string representation? Please give us an example. For example, the following is the example of the private/public keys in hex string format. ``` privKey: ff1140aabc074af4b6d84b74a0b9ba8bc00c18ad239d2b44208dcf6973a890cf pubKey: 7b77b92d1a55ef612b93c6ac02d013c82ecf164eb6e59e9d0a1313c3dd511c0d7c00a0a78aca1befb5c5b7a2487e942b1916560394abee519db6585c16bad9a3 account: 0x013e06a5bd9e5d12edcec119d5816c37caa8e3c8 ``` #### (20%) b. In addition, if we don’t want to use the getAddressString() to get the address, how can we obtain the address by hashing the public key? ```javascript= /***** address *****/ // step 2: public_key_hash = Keccak-256(public_key) Your code // step 3: address = ‘0x’ + last 20 bytes of public_key_hash Your code console.log("address:", address); ``` #### (30%) c. There is a file called Keystore that is used to encrypt the private key and save in a JSON file. Can you generate a Keystore with the password "nccu"? You can find the details about Keystore below. ```jsonld= {"address":"c2d7cf95645d33006175b78989035c7c9061d3f9", "crypto":{ "cipher":"aes-128-ctr", "ciphertext":"0f6d343b2a34fe571639235fc16250823c6fe3bc30525d98c41dfdf21a97aedb", "cipherparams":{ "iv":"cabce7fb34e4881870a2419b93f6c796" }, "kdf":"scrypt", "kdfparams":{ "dklen":32, "n":262144, "p":1, "r":8, "salt":"1af9c4a44cf45fe6fb03dcc126fa56cb0f9e81463683dd6493fb4dc76edddd51" }, "mac":"5cf4012fffd1fbe41b122386122350c3825a709619224961a16e908c2a366aa6" }, "id":"eddd71dd-7ad6-4cd3-bc1a-11022f7db76c", "version":3 } ``` - [Accounts, Addresses, Public And Private Keys, And Tokens]( https://theethereum.wiki/w/index.php/Accounts,_Addresses,_Public_And_Private_Keys,_And_Tokens) - [科普 | 什么是以太坊私钥储存(Keystore)文件?](https://ethfans.org/posts/what-is-an-ethereum-keystore-file) - [What is an Ethereum keystore file?](https://medium.com/@julien.maffre/what-is-an-ethereum-keystore-file-86c8c5917b97) ## Resources - https://github.com/ethereum/go-ethereum/tree/master/crypto (Golang) - https://github.com/vkobel/ethereum-generate-wallet (Python) - https://github.com/ethereum/eth-account (Python) - https://github.com/ethereumjs/ethereumjs-wallet (JavaScript) - https://github.com/emn178/js-sha3 (JavaScript) - https://github.com/pubkey/eth-crypto/blob/master/README.md (JavaScript) ## Bonus (總成績加分) - What is HD Wallet, BIP32, BIP39 and BIP44? (+2%) - What is RFC 6979 for? (+2%) > Write an article, specify detailed background and problem statement as well as the scheme on how to address the problem. And publish the article on the Medium or somewhere.

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully