File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ package key
33import (
44"crypto/ecdsa"
55"crypto/rand"
6+ "errors"
7+ "math/big"
68
79"github.com/CodeChain-io/codechain-sdk-go/crypto"
810"github.com/CodeChain-io/codechain-sdk-go/primitives"
@@ -61,3 +63,17 @@ func CreatePlatformAddress(key EcdsaKey, networkID string) (a primitives.Platfor
6163
6264return primitives .PlatformAddressFromAccountID (hash , networkID )
6365}
66+
67+ func ToECDSA (privateKey []byte ) (* EcdsaKey , error ) {
68+ priv := new (EcdsaKey )
69+ priv .PublicKey .Curve = crypto .S256 ()
70+ priv .D = new (big.Int ).SetBytes (privateKey )
71+
72+ priv .PublicKey .X , priv .PublicKey .Y = priv .PublicKey .Curve .ScalarBaseMult (privateKey )
73+
74+ if priv .PublicKey .X == nil {
75+ return nil , errors .New ("Invalid private key" )
76+ }
77+
78+ return priv , nil
79+ }
You can’t perform that action at this time.
0 commit comments