mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-05 10:51:41 +00:00
fix: Refactor crypto
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// Copyright Coinbase, Inc. All Rights Reserved.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
package mina
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/onsonr/sonr/crypto/core/curves/native/pasta/fp"
|
||||
"github.com/onsonr/sonr/crypto/core/curves/native/pasta/fq"
|
||||
)
|
||||
|
||||
// Signature is a Mina compatible signature either for payment or delegation
|
||||
type Signature struct {
|
||||
R *fp.Fp
|
||||
S *fq.Fq
|
||||
}
|
||||
|
||||
func (sig Signature) MarshalBinary() ([]byte, error) {
|
||||
var buf [64]byte
|
||||
rx := sig.R.Bytes()
|
||||
s := sig.S.Bytes()
|
||||
copy(buf[:32], rx[:])
|
||||
copy(buf[32:], s[:])
|
||||
return buf[:], nil
|
||||
}
|
||||
|
||||
func (sig *Signature) UnmarshalBinary(input []byte) error {
|
||||
if len(input) != 64 {
|
||||
return fmt.Errorf("invalid byte sequence")
|
||||
}
|
||||
var buf [32]byte
|
||||
copy(buf[:], input[:32])
|
||||
rx, err := new(fp.Fp).SetBytes(&buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
copy(buf[:], input[32:])
|
||||
s, err := new(fq.Fq).SetBytes(&buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sig.R = rx
|
||||
sig.S = s
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user