Compute pubkey from privkey, instead of keeping together, initPrivateKey (#13)
* Compute pubkey from privkey, instead of keeping together * Added initPrivateKey
This commit is contained in:
parent
07bd05aae4
commit
f22ae0a827
|
@ -17,7 +17,6 @@ type
|
|||
|
||||
PrivateKey* = object
|
||||
Fraw_key: array[32, byte]
|
||||
Fpublic_key: PublicKey # This is exported publicly through public_key
|
||||
|
||||
type
|
||||
Scalar256 = distinct array[32, byte]
|
||||
|
@ -53,7 +52,6 @@ template genAccessors(name: untyped, fieldType, objType: typedesc): untyped =
|
|||
|
||||
genAccessors(raw_key, array[64, byte], PublicKey)
|
||||
genAccessors(raw_key, array[32, byte], PrivateKey)
|
||||
genAccessors(public_key, PublicKey, PrivateKey)
|
||||
|
||||
|
||||
## If we hide the fields we need to provide a custom `==` proc
|
||||
|
|
|
@ -30,9 +30,11 @@ else:
|
|||
# ################################
|
||||
# Initialization
|
||||
|
||||
proc initPrivateKey*(data: array[32, byte]): PrivateKey {.noInit, inline.} =
|
||||
result.raw_key = data
|
||||
|
||||
proc initPrivateKey*(hexString: string): PrivateKey {.noInit.} =
|
||||
hexToByteArrayBE(hexString, result.raw_key)
|
||||
result.public_key = private_key_to_public_key(result)
|
||||
|
||||
proc initPublicKey*(hexString: string): PublicKey {.noInit.} =
|
||||
var b: array[65, byte]
|
||||
|
@ -60,6 +62,9 @@ proc verify_msg*(key: PublicKey, message: string, sig: Signature): bool {.inline
|
|||
# # ################################
|
||||
# # Private key interface
|
||||
|
||||
proc public_key*(key: PrivateKey): PublicKey {.inline.} =
|
||||
private_key_to_public_key(key)
|
||||
|
||||
proc sign_msg*(key: PrivateKey, message: openarray[byte]): Signature {.inline.} =
|
||||
let message_hash = keccak256.digest(message)
|
||||
ecdsa_sign(key, message_hash)
|
||||
|
|
|
@ -8,11 +8,12 @@
|
|||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
import ./datatypes
|
||||
export PublicKey, PrivateKey, Signature, public_key, raw_key, `==`
|
||||
|
||||
import ./datatypes_interface
|
||||
export datatypes_interface
|
||||
|
||||
export PublicKey, PrivateKey, Signature, public_key, raw_key, `==`
|
||||
|
||||
when defined(backend_native):
|
||||
import ttmath
|
||||
export ttmath
|
||||
|
|
Loading…
Reference in New Issue