diff --git a/main.go b/main.go index fd79343..ae9bec0 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,5 @@ func main() { w := wallet.MakeWallet() w.Address() - //cli := cli.CommandLine{} - //cli.CreateWallet() + //fmt.Print(wallet.ValidateAddress("1Dg9RoRcMYtcyj3dhXooFyjJubERMXRRwC")) } diff --git a/tmp/blocks/000000.vlog b/tmp/blocks/000000.vlog index 0b5801d..18e5008 100644 Binary files a/tmp/blocks/000000.vlog and b/tmp/blocks/000000.vlog differ diff --git a/tmp/blocks/000012.sst b/tmp/blocks/000012.sst deleted file mode 100644 index 9e99554..0000000 Binary files a/tmp/blocks/000012.sst and /dev/null differ diff --git a/tmp/blocks/000014.sst b/tmp/blocks/000014.sst new file mode 100644 index 0000000..dbdb241 Binary files /dev/null and b/tmp/blocks/000014.sst differ diff --git a/tmp/blocks/MANIFEST b/tmp/blocks/MANIFEST index 9cceafe..4127088 100644 Binary files a/tmp/blocks/MANIFEST and b/tmp/blocks/MANIFEST differ diff --git a/tmp/wallets.data b/tmp/wallets.data index 7924cd6..7c606c1 100644 Binary files a/tmp/wallets.data and b/tmp/wallets.data differ diff --git a/wallet/wallet.go b/wallet/wallet.go index 5fb3d58..611239b 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -1,6 +1,7 @@ package wallet import ( + "bytes" "crypto/ecdsa" "crypto/elliptic" "crypto/rand" @@ -10,8 +11,8 @@ import ( ) const ( - chechksumLength = 4 - version = byte(0x00) // 0 ın 16 lık gosterımıdır + checksumLength = 4 + version = byte(0x00) // 0 ın 16 lık gosterımıdır ) type Wallet struct { @@ -54,7 +55,7 @@ func PublicKeyHash(pubKey []byte) []byte { func Checksum(payload []byte) []byte { firstHash := sha256.Sum256(payload) // payload hash kodu olusturulur secondHash := sha256.Sum256(firstHash[:]) // firstHash hash kodu olusturulur - return secondHash[:chechksumLength] // checksum kodu olusturulur + return secondHash[:checksumLength] // checksum kodu olusturulur } // Address fonksiyonu, bir adres olusturur @@ -67,3 +68,30 @@ func (w Wallet) Address() []byte { return address } + +/* + + Address : 14LErwM2aHhdsDym6PKyutyG9ZSm51UHXc + FullHash : 002348bd9e7a51b7aba9766a7c62d502079020802bc6c767 + [version] : 00 + [pubKeyHash] : 2348bd9e7a51b7aba9766a7c62d50207902080 + [checksum] : 2bc6c767 + + address alınır ve addresi base58 ıle decode edılır ve pubKey elde edilir + + fullhasın ilk karakterını sokup alın bu surum karakterıdır burada versıon 00 oldu + + ardından pubkeyhash kısmınıda cıkarın ve elımızde checkSum kalır 1bc6c767 + +*/ + +// ValidateAddress fonksiyonu, bir adresin gecerli olup olmadıgını kontrol eder +func ValidateAddress(address string) bool { + pubKeyHash := Base58Decode([]byte(address)) // adresi byte dizisine dönüştürülür + actualChecksum := pubKeyHash[len(pubKeyHash)-checksumLength:] // checksum kodu alınır + version := pubKeyHash[0] // version kodu alınır + pubKeyHash = pubKeyHash[1 : len(pubKeyHash)-checksumLength] // version ve checksum kodu silinir + targetChecksum := Checksum(append([]byte{version}, pubKeyHash...)) // checksum kodu olusturulur + + return bytes.Compare(actualChecksum, targetChecksum) == 0 // checksum kodu karsılastırılır +}