Skip to content

Commit

Permalink
crypto: Rename last traces of go-crypto (tendermint#1786)
Browse files Browse the repository at this point in the history
Follow-up to tendermint#1782
  • Loading branch information
xla authored and melekes committed Jun 22, 2018
1 parent 7e3de20 commit 3e1baf6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 43 deletions.
6 changes: 3 additions & 3 deletions crypto/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# go-crypto
# crypto

go-crypto is the cryptographic package adapted for Tendermint's uses
crypto is the cryptographic package adapted for Tendermint's uses

## Importing it
`import "github.com/tendermint/tendermint/crypto"`
Expand All @@ -11,7 +11,7 @@ For Binary encoding, please refer to the [Tendermint encoding spec](https://gith

## JSON Encoding

go-crypto `.Bytes()` uses Amino:binary encoding, but Amino:JSON is also supported.
crypto `.Bytes()` uses Amino:binary encoding, but Amino:JSON is also supported.

```go
Example Amino:JSON encodings:
Expand Down
2 changes: 1 addition & 1 deletion crypto/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func init() {
RegisterAmino(cdc)
}

// RegisterAmino registers all go-crypto related types in the given (amino) codec.
// RegisterAmino registers all crypto related types in the given (amino) codec.
func RegisterAmino(cdc *amino.Codec) {
cdc.RegisterInterface((*PubKey)(nil), nil)
cdc.RegisterConcrete(PubKeyEd25519{},
Expand Down
67 changes: 32 additions & 35 deletions crypto/doc.go
Original file line number Diff line number Diff line change
@@ -1,48 +1,45 @@
/*
go-crypto is a customized/convenience cryptography package
for supporting Tendermint.
// crypto is a customized/convenience cryptography package for supporting
// Tendermint.

It wraps select functionality of equivalent functions in the
Go standard library, for easy usage with our libraries.
// It wraps select functionality of equivalent functions in the
// Go standard library, for easy usage with our libraries.

Keys:
// Keys:

All key generation functions return an instance of the PrivKey interface
which implements methods
// All key generation functions return an instance of the PrivKey interface
// which implements methods

AssertIsPrivKeyInner()
Bytes() []byte
Sign(msg []byte) Signature
PubKey() PubKey
Equals(PrivKey) bool
Wrap() PrivKey
// AssertIsPrivKeyInner()
// Bytes() []byte
// Sign(msg []byte) Signature
// PubKey() PubKey
// Equals(PrivKey) bool
// Wrap() PrivKey

From the above method we can:
a) Retrieve the public key if needed
// From the above method we can:
// a) Retrieve the public key if needed

pubKey := key.PubKey()
// pubKey := key.PubKey()

For example:
privKey, err := crypto.GenPrivKeyEd25519()
if err != nil {
...
}
pubKey := privKey.PubKey()
...
// And then you can use the private and public key
doSomething(privKey, pubKey)
// For example:
// privKey, err := crypto.GenPrivKeyEd25519()
// if err != nil {
// ...
// }
// pubKey := privKey.PubKey()
// ...
// // And then you can use the private and public key
// doSomething(privKey, pubKey)

// We also provide hashing wrappers around algorithms:

We also provide hashing wrappers around algorithms:
// Sha256
// sum := crypto.Sha256([]byte("This is Tendermint"))
// fmt.Printf("%x\n", sum)

Sha256
sum := crypto.Sha256([]byte("This is Tendermint"))
fmt.Printf("%x\n", sum)
Ripemd160
sum := crypto.Ripemd160([]byte("This is consensus"))
fmt.Printf("%x\n", sum)
*/
// Ripemd160
// sum := crypto.Ripemd160([]byte("This is consensus"))
// fmt.Printf("%x\n", sum)
package crypto

// TODO: Add more docs in here
2 changes: 1 addition & 1 deletion crypto/priv_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestReadPrivKey(t *testing.T) {
// garbage in, garbage out
garbage := []byte("hjgewugfbiewgofwgewr")
XXX This test wants to register BadKey globally to go-crypto,
XXX This test wants to register BadKey globally to crypto,
but we don't want to support that.
_, err := PrivKeyFromBytes(garbage)
require.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/p2p/peer.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ For details on peer discovery, see the [peer exchange (PEX) reactor doc](https:/
## Peer Identity

Tendermint peers are expected to maintain long-term persistent identities in the form of a public key.
Each peer has an ID defined as `peer.ID == peer.PubKey.Address()`, where `Address` uses the scheme defined in go-crypto.
Each peer has an ID defined as `peer.ID == peer.PubKey.Address()`, where `Address` uses the scheme defined in `crypto` package.

A single peer ID can have multiple IP addresses associated with it, but a node
will only ever connect to one at a time.
Expand Down
4 changes: 2 additions & 2 deletions types/protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (tm2pb) Validator(val *Validator) abci.Validator {
}

// XXX: panics on nil or unknown pubkey type
// TODO: add cases when new pubkey types are added to go-crypto
// TODO: add cases when new pubkey types are added to crypto
func (tm2pb) PubKey(pubKey crypto.PubKey) abci.PubKey {
switch pk := pubKey.(type) {
case crypto.PubKeyEd25519:
Expand Down Expand Up @@ -153,7 +153,7 @@ var PB2TM = pb2tm{}
type pb2tm struct{}

func (pb2tm) PubKey(pubKey abci.PubKey) (crypto.PubKey, error) {
// TODO: define these in go-crypto and use them
// TODO: define these in crypto and use them
sizeEd := 32
sizeSecp := 33
switch pubKey.Type {
Expand Down

0 comments on commit 3e1baf6

Please sign in to comment.