Skip to content
This repository was archived by the owner on Jul 15, 2018. It is now read-only.

Use go-data for nice json un/marshaling#3

Merged
ebuchman merged 7 commits intodevelopfrom
feature/go-data
Feb 24, 2017
Merged

Use go-data for nice json un/marshaling#3
ebuchman merged 7 commits intodevelopfrom
feature/go-data

Conversation

@ethanfrey
Copy link
Contributor

Another approach to solve #1

This uses wrapping structs to allow json unmarshalling of interfaces with minimal boilerplate code (which I hope to auto-generate one day). The default behavior with wire.BinaryBytes() and wire.JSONBytes() is not changed at all.

If you use the encoding/json library, we get nice handling of the three interfaces, PubKey, PrivKey and Signature. You must just store them in a wrapping struct: PubKeyS, PrivKeyS or SignatureS. Please take a look at the tests.

We use go-data to export all byte slices (and with custom JSONMarshal also the byte arrays) as hex strings. However this is flexible, and you can set the byte encoding to use hex, base64 or base58 in the main entry of your program and it will affect the encoding of all types that make use of data.Bytes or data.Encoder.

Example default encodings are for public keys are:

{
	"type": "ed25519",
	"data": "345347cee043dc6d6f70b0ae9a3fc5a8c977006fd13000680b1e2afecd0475d5"
}

{
	"type": "secp256k1",
	"data": "989f04749bcc689f6dec7489cc227bc3e2fbc4c37067df8750e0791d2e6297c106e244fc635ecd1696698dfd8d49efa752bb3ad7ff8c7fd23b79743cce8476b8"
}

If you use crypto.PubKeyS in your structs, you can cleanly Unmarshal this json into usable PubKey's as well.

@alessio
Copy link
Contributor

alessio commented Feb 23, 2017

:+1

@ethanfrey ethanfrey requested a review from ebuchman February 23, 2017 16:03
Copy link
Contributor

@ebuchman ebuchman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool

signature.go Outdated
const (
SignatureTypeEd25519 = byte(0x01)
SignatureTypeSecp256k1 = byte(0x02)
SignatureNameEd25519 = "ed25519"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about just one NameEd25519 instead of duplicating names for each type?

@ethanfrey
Copy link
Contributor Author

Okay, I unified all the types and names with one variable per algorithm in 0e92dd5

I think this is what you wanted with your comment bucky. If you like it, me too. If not, I can just revert the change.

@ebuchman ebuchman merged commit 562b4cc into develop Feb 24, 2017
@ebuchman ebuchman deleted the feature/go-data branch February 24, 2017 00:14
liamsi added a commit to liamsi/go-crypto that referenced this pull request Jun 12, 2018
� This is the 1st commit message:

Release/0.8.0 (tendermint#127)

https://github.com/Liamsi/go-crypto/blob/8e31aebe2bc23037b9cc11892f3ec4515bbf5991/CHANGELOG.md#080

fix tests, move encoding to encode_test.go, include an example

Ledger integration, WIP

Fix testcases, all looks OK

Prevent unnecessary signatures, improve error messages

Bugfix

Update to new Ledger API in progress

Update to latest upstream, debugging information

� This is the commit message tendermint#2:

Clarify function names

� This is the commit message tendermint#3:

Add ed25519, tests will fail until ed25519 verification fix

Implement PubKeyLedgerEd25519

Pin to an upstream revision

Remove Ledger ed25519 support, for now

Move TODOs to tendermint#114

Move from tmlibs #213 (tendermint#115)

* move from tmlibs 213
* expose KVPair, simpleproofsfrommap returns keys

update ed25519 address scheme (tendermint#112)

make PubKeyEd25519.Address() returns the first 20 bytes of the hash of the raw 32-byte pubkey, no amino required

forgot PrivKeyLedgerSecp256k1

version bump (tendermint#128)

version bump
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants