Commit Graph

5 Commits

Author SHA1 Message Date
jangko 206e5360b8
Get rid of ecdhRaw and export ecdh with custom hash func 2023-04-20 10:31:00 +07:00
Gruruya 6e18455a63
Enable and expose Schnorrsig (#44)
* Enable Schnorrsig module in wrapper

The extrakeys module is a dependency for Schnorrsig, so that's enabled as well.

* Add {.bycopy.} pragma

* Add Schnorrsig interface to `abi.nim`

Multikey interface is a dependency the for schnorrsig, so it was added
as well.

* Add tests for Schnorr signing

* Fix schnorr magic const declaration on 1.6 and below

* Remove unnecessary {.bycopy.} pragmas

Done under the impression that {.bycopy.} is not necessary when only
passing the object to C via ptr.

* Make SkKeyPair a wrapper around secp256k1_keypair

* Add more helper procs for new SkKeyPair

* Small fixes

* Re-order

* Rework patch. Implement Schnorr signing and undo breaking changes.

* Reduce code duplication

* Fix type

* Remove accidental extra indentation

* Add `default` {.error.} proc for SkSchnorrSignature

* Remove extra test

* Add from/to raw/hex

* Comments

* Add low-level test for `secp256k1_keypair`

* Fix errors on Nim 1.2

* Comment

* Allow passing a `Rng`/`FoolproofRng` to `signSchnorr` for improved security

* Comments

* Correct `noncefp` to be a pointer in `extraparams` object

* Remove unneeded {.bycopy.}

Co-authored-by: Jacek Sieka <arnetheduck@gmail.com>

* Don't check the RNG for Schnorr sig using private key requirements.

* Add comment detailing that `signSchnorr` without an `rng` is discouraged

* Remove non-`rng` signSchnorr variant from tests

* Rename `signSchnorr` without `rng` to `signSchnorrUnsafe`

* Unify `schnorrSig` implementations and add `array[32, bytes]` variant

* Fix on Nim 1.2

* Make `signSchnorr` accept `Opt[array[32, byte]]` rather than `[array[32,byte]]`

* Remove unused template param

* Inline `signSchnorr Rng` procs

* Remove `nimble.lock`, was breaking tests on Nim >1.6

Was causing
`Error: cannot open file: stew/byteutils`

* Correct template parameter naming

* Consistently apply {.noinit.} pragma

* `{.noinit.}` random byte array

* Revert "`{.noinit.}` random byte array"

This reverts commit a3f99817d9.

* Correct template pragmas

* Explicitly declare `noncefp` as `nil`

* Create and export `xonly_pubkey` wrapping type

* Complete implementation of `SkXOnlyPublicKey`

* Correct comment

* Add tests for 'SkXOnlyPublicKey`

* Correct conversion proc name

* Correct conversion proc name cont.

---------

Co-authored-by: Jacek Sieka <arnetheduck@gmail.com>
2023-04-11 10:17:03 +02:00
Jacek Sieka bf6cc94a3c
use external rng instead of nimcrypto (#23)
* use external rng instead of nimcrypto

allows passing in different RNG's to generate keys

* pass in array of random data to random keygen function

* back to a proc

* docs

* gcsafe rng callback needed

* introduce foolproofrng that can't fail

* silence compiler warning

* hint at random not being good enough in defect
2020-07-06 15:07:29 +02:00
Jacek Sieka 5701a60143
use requiredInit (#22)
* use requiredInit

Use requiredInit on keys - this simplifies error handling by providing
more compile-time guarantees through type.

Loophole: `clear` will leave an invalid key type in memory, not
guaranteed by type - it requires an explicit action to produce, so it's
somewhat better than the current situation where by default, keys are
invalid, but it's not watertight.

something like a `sink` would be needed which would have to guarantee
that `clear` is the last use of the instance.

* close requiresinit loophole

* remove clear for public stuff

* fix side effects

`secp256k1_context_no_precomp` is constant actually

* document nosideeffect

* document nosideeffect

* document fix
2020-06-22 16:08:21 +02:00
Jacek Sieka 306289244c
add convenience api (#21)
fixes #19
2020-04-17 07:43:30 +02:00