From ef6605471033b59052f179a50ee0cbee9a5e483e Mon Sep 17 00:00:00 2001 From: Daniel Bourdrez <3641580+bytemare@users.noreply.github.com> Date: Sat, 15 Jun 2024 15:36:41 +0200 Subject: [PATCH] Use hex values for JSON instead of raw bytes (#61) Signed-off-by: bytemare <3641580+bytemare@users.noreply.github.com> --- .github/licence-header.tmpl | 2 +- element.go | 4 ++-- scalar.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/licence-header.tmpl b/.github/licence-header.tmpl index cb152e4..4d3a906 100644 --- a/.github/licence-header.tmpl +++ b/.github/licence-header.tmpl @@ -1,6 +1,6 @@ SPDX-License-Identifier: MIT -Copyright (C) 2020-2023 Daniel Bourdrez. All Rights Reserved. +Copyright (C) 2024 Daniel Bourdrez. All Rights Reserved. This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree or at diff --git a/element.go b/element.go index b1cdc61..3b3a6d3 100644 --- a/element.go +++ b/element.go @@ -148,12 +148,12 @@ func (e *Element) DecodeHex(h string) error { // MarshalJSON marshals the element into valid JSON. func (e *Element) MarshalJSON() ([]byte, error) { - return e.Encode(), nil + return []byte(e.Hex()), nil } // UnmarshalJSON unmarshals the input into the element. func (e *Element) UnmarshalJSON(data []byte) error { - return e.Decode(data) + return e.DecodeHex(string(data)) } // MarshalBinary returns the compressed byte encoding of the element. diff --git a/scalar.go b/scalar.go index e2b7316..b1c25e0 100644 --- a/scalar.go +++ b/scalar.go @@ -180,12 +180,12 @@ func (s *Scalar) DecodeHex(h string) error { // MarshalJSON marshals the scalar into valid JSON. func (s *Scalar) MarshalJSON() ([]byte, error) { - return s.Encode(), nil + return []byte(s.Hex()), nil } // UnmarshalJSON unmarshals the input into the scalar. func (s *Scalar) UnmarshalJSON(data []byte) error { - return s.Decode(data) + return s.DecodeHex(string(data)) } // MarshalBinary implements the encoding.BinaryMarshaler interface.