比特币钱包中并不像普通帐户那样真的有钱,而是公私钥的集合。先来定义钱包(wallet)的结构: ```go type Wallet struct { PrivateKey ecdsa.PrivateKey PublicKey []byte } type Wallets struct { Wallets map[string]*Wallet } func NewWallet() *Wallet { private, public := newKeyPair() wallet := Wallet{private, public} return &wallet } func newKeyPair() (ecdsa.PrivateKey, []byte) { curve := elliptic.P256() private, err := ecdsa.GenerateKey(curve, rand.Reader) pubKey := append(private.PublicKey.X.Bytes(), private.PublicKey.Y.Bytes()...) return *private, pubKey } ``` 可见钱包中除了密钥对,其它什么也没有。现在需要Wallets类型来维护这起集合。 ```go //运算地址 func (w Wallet) GetAddress() []byte { pubKeyHash := HashPubKey(w.PublicKey) versionedPayload := append([]byte{version}, pubKeyHash...) checksum := checksum(versionedPayload) fullPayload := append(versionedPayload, checksum...) address := Base58Encode(fullPayload) return address } func HashPubKey(pubKey []byte) []byte { publicSHA256 := sha256.Sum256(pubKey) RIPEMD160Hasher := ripemd160.New() _, err := RIPEMD160Hasher.Write(publicSHA256[:]) publicRIPEMD160 := RIPEMD160Hasher.Sum(nil) return publicRIPEMD160 } func checksum(payload []byte) []byte { firstSHA := sha256.Sum256(payload) secondSHA := sha256.Sum256(firstSHA[:]) return secondSHA[:addressChecksumLen] } ``` `GetAddress()`把公钥进行一系列转换,得到地址,如果公开,别人就可以向它转帐了。转换的地址步骤如下: 1. 获取公钥,使用RIPEMD160(SHA256(PubKey))执行两次hash算法。 2. 给hash加上地址生成算法版本 3. 使用SHA256(SHA256(payload))hash计算第2步的结果,得到的hash值前4bytes就是校验码。 4. 把校验码附加到version+PubKeyHash组合。 5. 使用Base58编码version+PubKeyHash+checksum组合 ![address.jpg](https://ipfs.ilark.io/ipfs/QmfHPFL2nTh8JMADp65m2sBKP8N64vEDXY3eozMcAZ45zZ) 最后,算出了一个真正的比特币地址。如果你在不连网的情况下在本地运算,得到的公私钥对就是常说的冷钱包。它具有最高的安全性。如果你把私钥放到了服务器上以进行一些自动转账的功能,比如交易所,这就是热钱包。如果服务器被黑客成功攻击,私钥被泄露,比特币就成别人的了!所以,才有很多人说,私钥即一切!
author | lemooljiang |
---|---|
permlink | kndzdlpe |
category | hive-105017 |
json_metadata | {"tags":["cn","cn-reader","blockchain","bitcoin","wallet"],"dapp":"larkBlog","format":"markdown"} |
created | 2022-08-30 12:09:27 |
last_update | 2022-08-31 04:09:09 |
depth | 0 |
children | 2 |
last_payout | 2022-09-06 12:09:27 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 4.730 HBD |
curator_payout_value | 4.713 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1,768 |
author_reputation | 378,633,553,904,979 |
root_title | "实现地址 / go实现简易区块链 #6" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 116,166,223 |
net_rshares | 13,327,824,505,309 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
abit | 0 | 6,646,479,632,525 | 30% | ||
boatymcboatface | 0 | 141,303,005,180 | 8% | ||
kingscrown | 0 | 17,509,363,353 | 8% | ||
theshell | 0 | 37,849,617,712 | 8% | ||
mangou007 | 0 | 620,198,366 | 20% | ||
lemooljiang | 0 | 6,949,401,778 | 100% | ||
ace108 | 0 | 708,812,183,144 | 25% | ||
laoyao | 0 | 14,665,852,024 | 30% | ||
midnightoil | 0 | 51,730,020,654 | 30% | ||
xiaohui | 0 | 4,580,733,466 | 30% | ||
oflyhigh | 0 | 918,227,846,077 | 30% | ||
randomblock1 | 0 | 1,057,484,629 | 16.5% | ||
bert0 | 0 | 1,993,518,895 | 20% | ||
rivalhw | 0 | 1,639,077,602,507 | 100% | ||
helene | 0 | 297,333,286,050 | 30% | ||
dapeng | 0 | 96,080,390,657 | 100% | ||
lucknie | 0 | 140,875,069 | 100% | ||
dumping | 0 | 107,318,319 | 100% | ||
da-dawn | 0 | 62,197,247,382 | 23% | ||
laodr | 0 | 3,655,243,026 | 100% | ||
htliao | 0 | 5,345,092,983 | 35% | ||
exec | 0 | 79,238,781,183 | 30% | ||
alphacore | 0 | 2,004,280,390 | 2.01% | ||
joeyarnoldvn | 0 | 494,478,040 | 1.47% | ||
catwomanteresa | 0 | 146,077,764,493 | 50% | ||
liangfengyouren | 0 | 3,422,479,511 | 50% | ||
idx | 0 | 5,489,154,224 | 30% | ||
cn-reader | 0 | 17,501,535,308 | 50% | ||
tvb | 0 | 6,717,242,015 | 50% | ||
karja | 0 | 3,941,699,628 | 10% | ||
tipu | 0 | 1,787,589,282,180 | 7% | ||
kimzwarch | 0 | 14,873,819,685 | 4% | ||
yellowbird | 0 | 2,244,279,216 | 100% | ||
fatman | 0 | 8,322,852,631 | 2% | ||
votehero | 0 | 3,814,276,097 | 0.9% | ||
blc | 0 | 4,290,187,383 | 100% | ||
hqy | 0 | 3,842,144,425 | 100% | ||
metten | 0 | 134,017,849 | 100% | ||
cn-book | 0 | 399,141,456 | 100% | ||
cn-movie | 0 | 190,280,957 | 100% | ||
vivia | 0 | 720,819,587 | 100% | ||
xiaoli | 0 | 454,524,732 | 100% | ||
atongis | 0 | 29,906,865,760 | 5% | ||
tresor | 0 | 50,680,281,620 | 20% | ||
archisteem | 0 | 1,261,332,139 | 7.5% | ||
longer | 0 | 531,238,819 | 1.75% | ||
julian2013 | 0 | 45,643,252,084 | 50% | ||
voter002 | 0 | 3,911,252,242 | 10.2% | ||
pet.society | 0 | 14,215,778,622 | 6% | ||
memeteca | 0 | 5,352,677,819 | 20% | ||
wherein | 0 | 20,932,615,330 | 30% | ||
cnstm | 0 | 39,163,087,478 | 30% | ||
mia-cc | 0 | 855,571,015 | 7% | ||
src3 | 0 | 1,993,887,248 | 2.5% | ||
projectdignity | 0 | 2,193,983,572 | 100% | ||
kryptogames | 0 | 23,742,003,692 | 7% | ||
bcm | 0 | 574,502,381 | 5.25% | ||
starnote | 0 | 333,279,216 | 100% | ||
moochain.net | 0 | 335,733,005 | 100% | ||
bnk | 0 | 5,986,311,388 | 20% | ||
reward.app | 0 | 111,372,233,416 | 33% | ||
sevenoh-fiveoh | 0 | 735,891,205 | 3.5% | ||
philipmak | 0 | 1,443,975,373 | 50% | ||
ilark | 0 | 218,842,823,906 | 100% | ||
polkallen | 0 | 368,467,821 | 1% | ||
xtipu | 0 | -31,494,628 | -7% |
@tipu curate
author | annepink |
---|---|
permlink | re-lemooljiang-2022830t215026744z |
category | hive-105017 |
json_metadata | {"tags":["cn","cn-reader","blockchain","bitcoin","wallet"],"app":"ecency/3.0.26-vision","format":"markdown+html"} |
created | 2022-08-30 13:50:27 |
last_update | 2022-08-30 13:50:27 |
depth | 1 |
children | 1 |
last_payout | 2022-09-06 13:50:27 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 12 |
author_reputation | 789,929,037,264,292 |
root_title | "实现地址 / go实现简易区块链 #6" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 116,168,519 |
net_rshares | 0 |
<a href="https://tipu.online/hive_curator?annepink" target="_blank">Upvoted 👌</a> (Mana: 0/37) <a href="https://peakd.com/hive/@reward.app/reward-app-quick-guide-updated" target="_blank">Liquid rewards</a>.
author | tipu |
---|---|
permlink | re-re-lemooljiang-2022830t215026744z-20220830t135034z |
category | hive-105017 |
json_metadata | "{"app": "beem/0.24.26"}" |
created | 2022-08-30 13:50:33 |
last_update | 2022-08-30 13:50:33 |
depth | 2 |
children | 0 |
last_payout | 2022-09-06 13:50:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 215 |
author_reputation | 55,206,712,148,211 |
root_title | "实现地址 / go实现简易区块链 #6" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 116,168,523 |
net_rshares | 0 |