Bitcoin Forum
May 21, 2024, 04:51:01 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: WIF Checksum Checking  (Read 533 times)
Aurik (OP)
Newbie
*
Offline Offline

Activity: 24
Merit: 3


View Profile
February 07, 2017, 02:35:29 AM
 #1

Hi there, im not a programmer, so i need your help to update this code for me, as it is not working anymore.
Would be really nice if someone could invest a couple of minutes, as this should not take you too long.
Written in Go:

-------------------------------------
*START*
-------------------------------------
package main

import (
   "fmt"
   "github.com/conformal/btcutil"
   "github.com/conformal/btcwire"
)

func main() {
   step1 := "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ"
   fmt.Printf("1 - Wallet import format: %s\n", step1)

   step2 := btcutil.Base58Decode(step1)
   fmt.Printf("2 - Converting WIF as Base58 string to byte array: %x\n", step2)

   step3 := step2[:len(step2)-4]
   fmt.Printf("3 - Dropping last 4 checksum bytes from 2: %x\n", step3)

   step5 := btcwire.DoubleSha256(step3)
   fmt.Printf("4/5 - Double SHA-256 hash of 3: %x\n", step5)

   fmt.Printf("6 - First 4 bytes of 5, this is the calculated checksum: %x\n", step5[:4])

   step7 := step2[len(step2)-4:]
   fmt.Printf("7 - Take the last 4 bytes of 2, this is the original checksum: %x\n", step7)
}


And the result of running that program:

1 - Wallet import format: 5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ
2 - Converting WIF as Base58 string to byte array: 800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d507a5b8d
3 - Dropping last 4 checksum bytes from 2: 800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d
4/5 - Double SHA-256 hash of 3: 507a5b8dfed0fc6fe8801743720cedec06aa5c6fca72b07c49964492fb98a714
6 - First 4 bytes of 5, this is the calculated checksum: 507a5b8d
7 - Take the last 4 bytes of 2, this is the original checksum: 507a5b8d

-------------------------------------
*END*
-------------------------------------
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3402
Merit: 6641


Just writing some code


View Profile WWW
February 07, 2017, 03:17:00 AM
 #2

That looks correct. What's not working about it?

Aurik (OP)
Newbie
*
Offline Offline

Activity: 24
Merit: 3


View Profile
February 07, 2017, 02:18:54 PM
Last edit: February 07, 2017, 02:41:18 PM by Aurik
 #3

Seems like the Library at github.com/conformal/btcutil changed something.
First off,   "github.com/btcsuite/btcutil" seems to be correct now, but then again its not working.
Can you confirm that this is working just this way for you (on windows?) I know, windows sucks, but
as i said im not a programmer so i have to work with what i have Smiley

Edit: concrete, i get this error:
.\test.go:12: undefined: btcutil.Base58Decode

Edit2: If i change "btcutil.Base58Decode" to "btcutli.DecodeWIF" I get the error
.\test.go:12: multiple-value btcutil.DecodeWIF() in single-value context
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3402
Merit: 6641


Just writing some code


View Profile WWW
February 07, 2017, 02:47:46 PM
 #4

I am not familiar with go, I just looked at the logic.

It looks like you should be using btcutil.base58.Decode()

Aurik (OP)
Newbie
*
Offline Offline

Activity: 24
Merit: 3


View Profile
February 07, 2017, 03:02:43 PM
 #5

Tried that too, was not working.
But ive got it now, it is  step2 := base58.Decode(step1) and u have to include  "github.com/conformal/btcutil/base58" instead.

Next problem: the wire-package was moved to the the btcd package, so
step5 := btcwire.DoubleSha256(step3)
fmt.Printf("4/5 - Double SHA-256 hash of 3: %x\n", step5)

isnt working anymore. Im looking for the DoubleSha256 func in the btcd/wire dictionary, but i cant find it...
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3402
Merit: 6641


Just writing some code


View Profile WWW
February 07, 2017, 03:11:30 PM
 #6

I think this is what you are looking for: https://github.com/btcsuite/btcd/blob/ab0f30c00d17bb7766c06174d77661443df08973/chaincfg/chainhash/hashfuncs.go

Aurik (OP)
Newbie
*
Offline Offline

Activity: 24
Merit: 3


View Profile
February 07, 2017, 03:21:53 PM
 #7

Seems correct, gonna check it out now. Thanks so far Smiley

Edit 1: Yes, it is working! Thank you very much again!!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!