@@ -47,9 +47,7 @@ type CoinType = uint32
47
47
48
48
const (
49
49
CoinTypeBTC CoinType = 0x80000000
50
- CoinTypeLTC CoinType = 0x80000002
51
50
CoinTypeETH CoinType = 0x8000003c
52
- CoinTypeEOS CoinType = 0x800000c2
53
51
)
54
52
55
53
const (
@@ -307,7 +305,7 @@ func GenerateFromBytes(prvKey *btcec.PrivateKey, compress bool) (wif, address, s
307
305
}
308
306
segwitNested = addressScriptHash .EncodeAddress ()
309
307
310
- //taproot
308
+ // generate a taproot address
311
309
tapKey := txscript .ComputeTaprootKeyNoScript (prvKey .PubKey ())
312
310
addressTaproot , err := btcutil .NewAddressTaproot (schnorr .SerializePubKey (tapKey ), & chaincfg .MainNetParams )
313
311
if err != nil {
@@ -455,22 +453,32 @@ func main() {
455
453
func encodeEthereum (privateKeyBytes []byte ) (privateKey , address string ) {
456
454
_ , pubKey := btcec .PrivKeyFromBytes (privateKeyBytes )
457
455
456
+ // Public ECDSA Key
458
457
publicKey := pubKey .ToECDSA ()
458
+
459
+ // ethereum public key must be 64byte (32byte x 32byte y coordinates
460
+ // this is uncompressed ECDSA public key without 04 prefix
459
461
publicKeyBytes := append (publicKey .X .FillBytes (make ([]byte , 32 )), publicKey .Y .FillBytes (make ([]byte , 32 ))... )
460
462
461
- // Ethereum uses the last 20 bytes of the keccak256 hash of the public key
463
+ // Keccak-256 hash of the public key
462
464
hash := sha3 .NewLegacyKeccak256 ()
463
465
hash .Write (publicKeyBytes )
464
466
addr := hash .Sum (nil )
467
+
468
+ // Ethereum uses the last 20 bytes of the Keccak-256 hash of the public key
469
+ // this is ethereum address(without 0x prefix) but currently have not checksum
465
470
addr = addr [len (addr )- 20 :]
466
471
467
472
return hex .EncodeToString (privateKeyBytes ), eip55checksum (fmt .Sprintf ("0x%x" , addr ))
468
473
}
469
474
470
475
// eip55checksum implements the EIP55 checksum address encoding.
476
+ // https://github.com/ethereum/ercs/blob/master/ERCS/erc-55.md
477
+ // In English, convert the address to hex, but if the i th digit is a letter (ie. it's one of abcdef)
478
+ // print it in uppercase if the 4*i th bit of the hash of the lowercase hexadecimal address is 1 otherwise print it in lowercase.
471
479
// this function is copied from the go-ethereum library: go-ethereum/common/types.go checksumHex method
472
480
func eip55checksum (address string ) string {
473
- buf := []byte (address )
481
+ buf := []byte (strings . ToLower ( address ) )
474
482
sha := sha3 .NewLegacyKeccak256 ()
475
483
sha .Write (buf [2 :])
476
484
hash := sha .Sum (nil )
0 commit comments