34 lines
778 B
Go
34 lines
778 B
Go
|
|
package mpc
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"math/big"
|
||
|
|
|
||
|
|
"github.com/sonr-io/crypto/core/curves"
|
||
|
|
)
|
||
|
|
|
||
|
|
func GetECDSAPoint(pubKey []byte) (*curves.EcPoint, error) {
|
||
|
|
crv := curves.K256()
|
||
|
|
x := new(big.Int).SetBytes(pubKey[1:33])
|
||
|
|
y := new(big.Int).SetBytes(pubKey[33:])
|
||
|
|
ecCurve, err := crv.ToEllipticCurve()
|
||
|
|
if err != nil {
|
||
|
|
return nil, fmt.Errorf("error converting curve: %v", err)
|
||
|
|
}
|
||
|
|
return &curves.EcPoint{X: x, Y: y, Curve: ecCurve}, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func DeserializeSignature(sigBytes []byte) (*curves.EcdsaSignature, error) {
|
||
|
|
if len(sigBytes) != 64 {
|
||
|
|
return nil, fmt.Errorf("invalid signature length: expected 64 bytes, got %d", len(sigBytes))
|
||
|
|
}
|
||
|
|
|
||
|
|
r := new(big.Int).SetBytes(sigBytes[:32])
|
||
|
|
s := new(big.Int).SetBytes(sigBytes[32:])
|
||
|
|
|
||
|
|
return &curves.EcdsaSignature{
|
||
|
|
R: r,
|
||
|
|
S: s,
|
||
|
|
}, nil
|
||
|
|
}
|