Skip to content

Commit

Permalink
Public address from private key (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie Revett authored Sep 18, 2017
1 parent 64302a9 commit 4f24886
Show file tree
Hide file tree
Showing 14 changed files with 655 additions and 187 deletions.
48 changes: 43 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,45 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this
project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 1.1.0 - 2017-08-19
## v1.2.0 - 2017-08-19

### Added

- [Elliptic curve](https://en.wikipedia.org/wiki/Elliptic_curve) implementation in utility package.
- Base58 encoding support.
- Migrated `neo.WIF` struct into `neo.PrivateKey` struct.
- Derive a public NEO address from a private key (WIF):

```golang
privateKey, err := neo.NewPrivateKeyFromWIF("L1QqQJnpBwbsPGAuutuzPTac8piqvbR1HRjrY5qHup48TBCBFe4g")
if err != nil {
log.Fatal(err)
}

publicAddress, err := privateKey.PublicAddress()
if err != nil {
log.Fatal(err)
}

log.Println(publicAddress)
```

## v1.1.2 - 2017-08-12

### Changed

- TCP connections made by `client.Ping()` are now closed to stop memory leaks from happening.

## v1.1.1 - 2017-08-12

### Changed

- **@eramus** fixed:
- closing response body in wrong place.
- made Base58 decode much more efficient and clean.
- Slack URI in README was updated.

## v1.1.0 - 2017-08-19

### Added

Expand All @@ -24,7 +62,7 @@ if err != nil {
log.Println(privateKey.Value)
```

## 1.0.1 - 2017-08-19
## v1.0.1 - 2017-08-19

### Added

Expand All @@ -34,20 +72,20 @@ log.Println(privateKey.Value)

- Logo in README to new CoZ logo.

## 1.0.0 - 2017-08-16
## v1.0.0 - 2017-08-16

### Changed

- Added badges to README.

## 0.2.0 - 2017-08-16
## v0.2.0 - 2017-08-16

### Added

- Existing code from original repo.
- Full CI job.

## 0.1.0 - 2017-08-16
## v0.1.0 - 2017-08-16

### Added

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.2
1.2.0
8 changes: 6 additions & 2 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 18 additions & 53 deletions neo/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@ func TestClient(t *testing.T) {
t.Run("NewClient()", func(t *testing.T) {
client := neo.NewClient(nodeURI)
assert.Equal(t, nodeURI, client.NodeURI)
assert.IsType(t, neo.Client{}, client)
})

t.Run(".GetBestBlockHash()", func(t *testing.T) {
t.Run("HappyCase", func(t *testing.T) {
client := neo.NewClient(nodeURI)

blockHash, err := client.GetBestBlockHash()
assert.Nil(t, err)
assert.NotEqual(t, "", blockHash)
})

t.Run("SadCase", func(t *testing.T) {
// TODO
assert.NoError(t, err)
assert.NotEmpty(t, blockHash)
})
})

Expand All @@ -36,19 +33,15 @@ func TestClient(t *testing.T) {
for _, testBlock := range testBlocks {
t.Run(testBlock.id, func(t *testing.T) {
block, err := client.GetBlockByHash(testBlock.hash)
assert.Nil(t, err)
assert.NoError(t, err)

assert.Equal(t, testBlock.hash, block.Hash)
assert.Equal(t, testBlock.index, block.Index)
assert.Equal(t, testBlock.merkleRoot, block.Merkleroot)
assert.Equal(t, testBlock.numberOfTransactions, len(block.Transactions))
assert.Len(t, block.Transactions, testBlock.numberOfTransactions)
})
}
})

t.Run("SadCase", func(t *testing.T) {
// TODO
})
})

t.Run(".GetBlockByIndex()", func(t *testing.T) {
Expand All @@ -58,32 +51,24 @@ func TestClient(t *testing.T) {
for _, testBlock := range testBlocks {
t.Run(testBlock.id, func(t *testing.T) {
block, err := client.GetBlockByIndex(testBlock.index)
assert.Nil(t, err)
assert.NoError(t, err)

assert.Equal(t, testBlock.index, block.Index)
assert.Equal(t, testBlock.hash, block.Hash)
assert.Equal(t, testBlock.merkleRoot, block.Merkleroot)
assert.Equal(t, testBlock.numberOfTransactions, len(block.Transactions))
assert.Len(t, block.Transactions, testBlock.numberOfTransactions)
})
}
})

t.Run("SadCase", func(t *testing.T) {
// TODO
})
})

t.Run(".GetBlockCount()", func(t *testing.T) {
t.Run("HappyCase", func(t *testing.T) {
client := neo.NewClient(nodeURI)

blockCount, err := client.GetBlockCount()
assert.Nil(t, err)
assert.NotEqual(t, 0, blockCount)
})

t.Run("SadCase", func(t *testing.T) {
// TODO
assert.NoError(t, err)
assert.NotEmpty(t, blockCount)
})
})

Expand All @@ -94,27 +79,19 @@ func TestClient(t *testing.T) {
expectedBlockHash := "3f0b498c0d57f73c674a1e28045f5e9a0991f9dac214076fadb5e6bafd546170"

blockHash, err := client.GetBlockHash(blockIndex)
assert.Nil(t, err)
assert.NotEqual(t, "", blockHash)
assert.NoError(t, err)
assert.NotEmpty(t, blockHash)
assert.Equal(t, expectedBlockHash, blockHash)
})

t.Run("SadCase", func(t *testing.T) {
// TODO
})
})

t.Run(".GetConnectionCount()", func(t *testing.T) {
t.Run("HappyCase", func(t *testing.T) {
client := neo.NewClient(nodeURI)

blockCount, err := client.GetConnectionCount()
assert.Nil(t, err)
assert.NotEqual(t, 0, blockCount)
})

t.Run("SadCase", func(t *testing.T) {
// TODO
assert.NoError(t, err)
assert.NotEmpty(t, blockCount)
})
})

Expand All @@ -125,17 +102,13 @@ func TestClient(t *testing.T) {
for _, testTransaction := range testTransactions {
t.Run(testTransaction.id, func(t *testing.T) {
transaction, err := client.GetTransaction(testTransaction.hash)
assert.Nil(t, err)
assert.NoError(t, err)

assert.Equal(t, testTransaction.hash, transaction.ID)
assert.Equal(t, testTransaction.size, transaction.Size)
})
}
})

t.Run("SadCase", func(t *testing.T) {
// TODO
})
})

t.Run(".GetTransactionOutput()", func(t *testing.T) {
Expand All @@ -147,29 +120,21 @@ func TestClient(t *testing.T) {
transactionOutput, err := client.GetTransactionOutput(
testTransactionOutput.hash, testTransactionOutput.index,
)
assert.Nil(t, err)
assert.NoError(t, err)

assert.Equal(t, testTransactionOutput.asset, transactionOutput.Asset)
assert.Equal(t, testTransactionOutput.value, transactionOutput.Value)
})
}
})

t.Run("SadCase", func(t *testing.T) {
// TODO
})
})

t.Run(".GetUnconfirmedTransactions()", func(t *testing.T) {
t.Run("HappyCase", func(t *testing.T) {
client := neo.NewClient(nodeURI)

_, err := client.GetUnconfirmedTransactions()
assert.Nil(t, err)
})

t.Run("SadCase", func(t *testing.T) {
// TODO
assert.NoError(t, err)
})
})

Expand All @@ -178,7 +143,7 @@ func TestClient(t *testing.T) {
client := neo.NewClient(nodeURI)

ok := client.Ping()
assert.Equal(t, true, ok)
assert.True(t, ok)
})

t.Run("SadCase", func(t *testing.T) {
Expand All @@ -201,7 +166,7 @@ func TestClient(t *testing.T) {
client := neo.NewClient(testCase.uri)

ok := client.Ping()
assert.Equal(t, false, ok)
assert.False(t, ok)
})
}
})
Expand Down
26 changes: 26 additions & 0 deletions neo/fixtures_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
package neo_test

var (
testAccounts = []struct {
privateKey string
privateKeyBase64 string
publicAddress string
wif string
}{
{
privateKey: "7d128a6d096f0c14c3a25a2b0c41cf79661bfcb4a8cc95aaaea28bde4d732344",
privateKeyBase64: "fRKKbQlvDBTDolorDEHPeWYb/LSozJWqrqKL3k1zI0Q=",
publicAddress: "ALq7AWrhAueN6mJNqk6FHJjnsEoPRytLdW",
wif: "L1QqQJnpBwbsPGAuutuzPTac8piqvbR1HRjrY5qHup48TBCBFe4g",
},
{
privateKey: "dc5e273f370113018217c876056011dad0c897f6eca074bf741807f35ed271d2",
privateKeyBase64: "3F4nPzcBEwGCF8h2BWAR2tDIl/bsoHS/dBgH817ScdI=",
publicAddress: "AVzgMjviERgZSCVoerzaGYhZhKoecd9RXk",
wif: "L4c5RVHp3FyG7duisGHpSCBzEqnTUqvYw4Bv6hnwCgbDTsLYgt9o",
},
{
privateKey: "07fbee0481bb32441e9fca5d52c66e2554c06591c7f747e5d77bcb6217d1952d",
privateKeyBase64: "B/vuBIG7MkQen8pdUsZuJVTAZZHH90fl13vLYhfRlS0=",
publicAddress: "AN2SiiLndiLsX9sYyVYmn3LYyjgozfUnb4",
wif: "KwVEM6nK44RvgsohK5zxYAgRbut9mfGYaTcb7jkqBBfnApCLRJys",
},
}

testBlocks = []struct {
hash string
id string
Expand Down
Loading

0 comments on commit 4f24886

Please sign in to comment.