Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nbd-wtf/dart-bip340

naïve implementation of BIP-340 Schnorr Signatures in Dart
https://github.com/nbd-wtf/dart-bip340

bitcoin nostr schnorr schnorr-signatures taproot

Last synced: about 1 month ago
JSON representation

naïve implementation of BIP-340 Schnorr Signatures in Dart

Awesome Lists containing this project

README

        

bip340 [![Pub](https://img.shields.io/pub/v/bip340.svg?style=flat)](https://pub.dev/packages/bip340)
======

Implements basic signing and verification functions for the [BIP-340](https://bips.xyz/340) Schnorr Signature Scheme.

It passes the [tests](https://github.com/bitcoin/bips/blob/master/bip-0340/test-vectors.csv) attached to the BIP (`dart test` to run that), but no guarantees are made of anything and _this is not safe cryptography_, do not use to store Bitcoins.

Provides these functions:

1. `String sign(String privateKey, String message, String aux)`

Generates a schnorr signature using the BIP-340 scheme.

* `privateKey` must be 32-bytes lowercase hex-encoded, i.e., 64 characters.
* `message` must also be lowercase hex-encoded (a hash of the _actual_ message).
* `aux ` must be 32-bytes random bytes, generated at signature time.
* Returns the signature as a string of 64 bytes hex-encoded, i.e., 128 characters.

2. `bool verify(String publicKey, String message, String signature)`

Verifies a schnorr signature using the BIP-340 scheme.

* `publicKey` must be 32-bytes lowercase hex-encoded, i.e., 64 characters (if you have a pubkey with 33 bytes just remove the first one).
* `message` must also be lowercase hex-encoded (a hash of the _actual_ message).
* `signature` must be 64-bytes lowercase hex-encoded, i.e., 128 characters.
* Returns true if the signature is valid, false otherwise.

3. `String getPublicKey(String privateKey)`

Produces the public key from a private key

* `privateKey` must be a 32-bytes hex-encoded string, i.e. 64 characters.
* Returns a public key as also 32-bytes hex-encoded.

Made for integration with [Nostr](https://github.com/fiatjaf/nostr).