Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Commit

Permalink
Move hashing into subpackage
Browse files Browse the repository at this point in the history
  • Loading branch information
nullstyle committed Oct 26, 2015
1 parent c686494 commit 2289777
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 37 deletions.
4 changes: 2 additions & 2 deletions build/main.go
Expand Up @@ -8,7 +8,7 @@
package build

import (
"github.com/stellar/go-stellar-base"
"github.com/stellar/go-stellar-base/hash"
"github.com/stellar/go-stellar-base/xdr"
)

Expand Down Expand Up @@ -64,5 +64,5 @@ type Network struct {
}

func (n *Network) ID() [32]byte {
return stellarbase.Hash([]byte(n.Passphrase))
return hash.Hash([]byte(n.Passphrase))
}
4 changes: 2 additions & 2 deletions build/transaction.go
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/hex"
"fmt"

"github.com/stellar/go-stellar-base"
"github.com/stellar/go-stellar-base/hash"
"github.com/stellar/go-stellar-base/xdr"
)

Expand Down Expand Up @@ -66,7 +66,7 @@ func (b *TransactionBuilder) Hash() ([32]byte, error) {
return [32]byte{}, err
}

return stellarbase.Hash(txBytes.Bytes()), nil
return hash.Hash(txBytes.Bytes()), nil
}

// HashHex returns the hex-encoded hash of this builder's transaction
Expand Down
2 changes: 1 addition & 1 deletion hashing.go → hash/main.go
@@ -1,4 +1,4 @@
package stellarbase
package hash

import (
"crypto/sha256"
Expand Down
38 changes: 38 additions & 0 deletions hash/main_test.go
@@ -0,0 +1,38 @@
package hash

import (
"encoding/hex"
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)

func TestHash(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Package: github.com/stellar/go-stellar-base/hash")
}

type HashCase struct {
Msg string
Hash string
}

var _ = DescribeTable("Hash()",
func(c HashCase) {
sig := Hash([]byte(c.Msg))
actual := hex.EncodeToString(sig[:])

Expect(actual).To(Equal(c.Hash))
},

Entry("hello world", HashCase{
"hello world",
"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9",
}),
Entry("this is a message", HashCase{
"this is a message",
"cee86e2a6c441f1e308d16a3db20a8fa8fae2a45730b48ca2c0c61e159af7e78",
}),
)
31 changes: 0 additions & 31 deletions hashing_test.go

This file was deleted.

3 changes: 2 additions & 1 deletion transaction_test.go
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/base64"
"fmt"

"github.com/stellar/go-stellar-base/hash"
"github.com/stellar/go-stellar-base/xdr"
)

Expand Down Expand Up @@ -69,7 +70,7 @@ func ExampleLowLevelTransaction() {
panic(err)
}

txHash := Hash(txBytes.Bytes())
txHash := hash.Hash(txBytes.Bytes())
signature := spriv.Sign(txHash[:])

ds := xdr.DecoratedSignature{
Expand Down

0 comments on commit 2289777

Please sign in to comment.