secp: update (#138)
This commit is contained in:
parent
303ec297da
commit
2b823bde68
|
@ -49,11 +49,11 @@ type
|
||||||
var secpContext {.threadvar.}: SkContext
|
var secpContext {.threadvar.}: SkContext
|
||||||
## Thread local variable which holds current context
|
## Thread local variable which holds current context
|
||||||
|
|
||||||
proc illegalCallback(message: cstring, data: pointer) {.cdecl.} =
|
proc illegalCallback(message: cstring, data: pointer) {.cdecl, raises: [].} =
|
||||||
let ctx = cast[SkContext](data)
|
let ctx = cast[SkContext](data)
|
||||||
ctx.error = $message
|
ctx.error = $message
|
||||||
|
|
||||||
proc errorCallback(message: cstring, data: pointer) {.cdecl.} =
|
proc errorCallback(message: cstring, data: pointer) {.cdecl, raises: [].} =
|
||||||
let ctx = cast[SkContext](data)
|
let ctx = cast[SkContext](data)
|
||||||
ctx.error = $message
|
ctx.error = $message
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ proc init*(key: var SkPublicKey, data: openarray[byte]): bool =
|
||||||
return false
|
return false
|
||||||
let res = secp256k1_ec_pubkey_parse(ctx.context, addr key,
|
let res = secp256k1_ec_pubkey_parse(ctx.context, addr key,
|
||||||
cast[ptr cuchar](unsafeAddr data[0]),
|
cast[ptr cuchar](unsafeAddr data[0]),
|
||||||
length)
|
csize_t(length))
|
||||||
result = (res == 1) and (len(ctx.error) == 0)
|
result = (res == 1) and (len(ctx.error) == 0)
|
||||||
|
|
||||||
proc init*(key: var SkPublicKey, data: string): bool =
|
proc init*(key: var SkPublicKey, data: string): bool =
|
||||||
|
@ -155,7 +155,7 @@ proc init*(sig: var SkSignature, data: openarray[byte]): bool =
|
||||||
if length >= 0:
|
if length >= 0:
|
||||||
let res = secp256k1_ecdsa_signature_parse_der(ctx.context, addr sig,
|
let res = secp256k1_ecdsa_signature_parse_der(ctx.context, addr sig,
|
||||||
cast[ptr cuchar](unsafeAddr data[0]),
|
cast[ptr cuchar](unsafeAddr data[0]),
|
||||||
csize(length))
|
csize_t(length))
|
||||||
result = (res == 1) and (len(ctx.error) == 0)
|
result = (res == 1) and (len(ctx.error) == 0)
|
||||||
|
|
||||||
proc init*(sig: var SkSignature, data: string): bool =
|
proc init*(sig: var SkSignature, data: string): bool =
|
||||||
|
@ -264,7 +264,7 @@ proc toBytes*(key: SkPublicKey, data: var openarray[byte]): int =
|
||||||
## Procedure returns number of bytes (octets) needed to store
|
## Procedure returns number of bytes (octets) needed to store
|
||||||
## Secp256k1 public key.
|
## Secp256k1 public key.
|
||||||
let ctx = getContext()
|
let ctx = getContext()
|
||||||
var length = csize(len(data))
|
var length = csize_t(len(data))
|
||||||
result = SkRawPublicKeySize
|
result = SkRawPublicKeySize
|
||||||
if len(data) >= SkRawPublicKeySize:
|
if len(data) >= SkRawPublicKeySize:
|
||||||
discard secp256k1_ec_pubkey_serialize(ctx.context,
|
discard secp256k1_ec_pubkey_serialize(ctx.context,
|
||||||
|
@ -281,13 +281,13 @@ proc toBytes*(sig: SkSignature, data: var openarray[byte]): int =
|
||||||
let ctx = getContext()
|
let ctx = getContext()
|
||||||
var buffer: array[72, byte]
|
var buffer: array[72, byte]
|
||||||
let pdata = cast[ptr cuchar](addr buffer[0])
|
let pdata = cast[ptr cuchar](addr buffer[0])
|
||||||
var plength = csize(len(buffer))
|
var plength = csize_t(len(buffer))
|
||||||
discard secp256k1_ecdsa_signature_serialize_der(ctx.context, pdata,
|
discard secp256k1_ecdsa_signature_serialize_der(ctx.context, pdata,
|
||||||
addr plength,
|
addr plength,
|
||||||
unsafeAddr sig)
|
unsafeAddr sig)
|
||||||
result = plength
|
result = int(plength)
|
||||||
if len(data) >= plength:
|
if len(data) >= result:
|
||||||
copyMem(addr data[0], addr buffer[0], plength)
|
copyMem(addr data[0], addr buffer[0], result)
|
||||||
|
|
||||||
proc getBytes*(key: SkPrivateKey): seq[byte] {.inline.} =
|
proc getBytes*(key: SkPrivateKey): seq[byte] {.inline.} =
|
||||||
## Serialize Secp256k1 `private key` and return it.
|
## Serialize Secp256k1 `private key` and return it.
|
||||||
|
|
Loading…
Reference in New Issue