Skip to content

Commit 720fc94

Browse files
author
AJ ONeal
committed
fix: switch to Dash pubkeyhash algo
1 parent 1587b82 commit 720fc94

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

dashmsg.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/anaskhan96/base58check"
1616
secp256k1crypto "github.com/ethereum/go-ethereum/crypto"
1717
"github.com/ethereum/go-ethereum/crypto/secp256k1"
18+
"golang.org/x/crypto/ripemd160"
1819
)
1920

2021
var (
@@ -184,11 +185,23 @@ func PublicKeyToAddress(magicVersion string, pub ecdsa.PublicKey) string {
184185
magicVersion = CheckVersionTest
185186
}
186187

187-
pubKeyHash := secp256k1crypto.PubkeyToAddress(pub).Bytes()
188+
b := elliptic.Marshal(secp256k1crypto.S256(), pub.X, pub.Y)
189+
b[0] = byte(0x03)
190+
b = b[0:33]
191+
//fmt.Fprintf(os.Stderr, "PubKey Bytes: %d %v\n", len(b), hex.EncodeToString(b))
192+
193+
hash1 := sha256.Sum256(b)
194+
md := ripemd160.New()
195+
_, _ = md.Write(hash1[:])
196+
hash2 := md.Sum(nil)
197+
pubKeyHash := hash2[:]
198+
199+
//pubKeyHash := secp256k1crypto.PubkeyToAddress(pub).Bytes()
188200
pubKeyHashHex := hex.EncodeToString(pubKeyHash)
189201
addr, _ := base58check.Encode(magicVersion, pubKeyHashHex)
190-
//fmt.Println("PubKeyHash Bytes:", pubKeyHash)
191-
//fmt.Println("PubKeyHash:", addr)
202+
//fmt.Fprintf(os.Stderr, "PubKeyHash Bytes: %v\n", pubKeyHash)
203+
//fmt.Fprintf(os.Stderr, "PubKeyHash Hex: %q\n", pubKeyHashHex)
204+
//fmt.Fprintf(os.Stderr, "PubKeyHash: %q\n", addr)
192205

193206
return addr
194207
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ go 1.17
55
require (
66
github.com/anaskhan96/base58check v0.0.0-20181220122047-b05365d494c4
77
github.com/ethereum/go-ethereum v1.10.16
8+
golang.org/x/crypto v0.0.0-20220313003712-b769efc7c000
89
)
910

1011
require (
1112
github.com/btcsuite/btcd v0.20.1-beta // indirect
12-
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
1313
golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 // indirect
1414
)

staticcheck.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# I like my yoda conditions ST1017
2-
checks = ["all", "-ST1017", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-ST1023"]
2+
# We need ripe160 for Dash SA1019
3+
checks = ["all", "-SA1019", "-ST1017", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-ST1023"]
34
initialisms = ["ACL", "API", "ASCII", "CPU", "CSS", "DNS",
45
"EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID",
56
"IP", "JSON", "QPS", "RAM", "RPC", "SLA",

0 commit comments

Comments
 (0)