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

Signature's native JSON marshalling does not encode instances into base64 format #1

@alessio

Description

@alessio

Signature concrete types should define their own MarshalJSON() and UnmarshalJSON() methods as currently marshalling objects does not work as expected. In particular, json.Marshal() returns a stringified array of integers; byte arrays should be marshalled into base64 strings instead. The following simple program may be used to reproduce the issue:

package main

import (
	"encoding/json"
	"fmt"

	"github.com/tendermint/go-crypto"
)

func main() {
	var sig1 crypto.Signature

	privKey := crypto.GenPrivKeyEd25519()
	sig1 = privKey.Sign([]byte("sample string"))
	jsonBytes := mustMarshal(sig1)
	fmt.Printf("%q\n", string(jsonBytes))
}

func mustMarshal(v interface{}) []byte {
	ret, err := json.Marshal(v)
	if err != nil {
		panic(err)
	}
	return ret
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions