Code Monkey home page Code Monkey logo

dart-bip340's Introduction

bip340 Pub

Implements basic signing and verification functions for the BIP-340 Schnorr Signature Scheme.

It passes the tests 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.
  1. 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.
  1. 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.

dart-bip340's People

Contributors

5antoshernandez avatar fiatjaf avatar ravipatelgit avatar ryzizub avatar vincenzopalazzo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dart-bip340's Issues

Verify error

  String public =
      '0000a0fa65fcccd99e6fd32fc7870339af40f4a94703ea30999fc5c091daa222';
  String message =
      '3518d08e684f4b94a68367a060a9075dc0b5d1058f87bcc6b6bc9e676b9f2c71';
  String sig =
    '637d91a9f93fd4a6b71ed3a542a9159ed58dc63bfaa319d834f59f158851e28803f54c9e89c26edcf1942819fd4571bc891874318a84d3e387755d4cf113ed38';

const result  = bip340.verify(public, message, sig);
result  === false

The is an error and I think it's because my account number starts with 0000. When I switched to another account, verification succeeded.

However, when I switched to a different library, there was no error: bip-schnorr.

This library will return the correct validation results.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.