Giter VIP home page Giter VIP logo

haskoin-core's Introduction

Haskoin Core

Haskoin Core is a library of Bitcoin and Bitcoin Cash functions written in Haskell featuring:

  • Hashing functions (SHA-256, RIPEMD-160)
  • Base58 support
  • CashAddr support
  • Bech32 suport
  • BIP32 extended key derivation and parsing (m/1'/2/3)
  • BIP39 mnemonic keys
  • ECDSA secp256k1 cryptographic primitives
  • Script parsing
  • Building and signing of standard transactions (regular, multisig, p2sh, segwit)
  • Parsing and manipulation of all Bitcoin and Bitcoin Cash protocol messages
  • Bloom filters and partial merkle trees (used in SPV wallets)
  • Comprehensive test suite

Contributing

All code is formatted with Ormolu. Convenience formatting script available at scripts/format

haskoin-core's People

Contributors

alexfmpe avatar benma avatar darthdeus avatar gambolingpangolin avatar hudon avatar ilyasridhuan avatar jprupp avatar lornap avatar mhuesch avatar np avatar ottoallmendinger avatar pavel-main avatar pernas avatar plaprade avatar runeksvendsen avatar sha49 avatar tphyahoo avatar werehamster avatar wraithm avatar wyager avatar

Stargazers

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

Watchers

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

haskoin-core's Issues

Arbitrary DerivPath instance doesn't account for mixed paths

instance Arbitrary ArbitraryHardPath where
    arbitrary =
        ArbitraryHardPath <$> (go =<< listOf genIndex)
      where
        go []     = return Deriv
        go (i:is) = (:| i) <$> go is

As a side note, I think the above is easier

foldl' (:|) Deriv

but of course, we still don't have mixed path with that either.

In my #200 rethink, I made this type of testing code easier by tagging path indexes as hard or soft, something like

data Bip32PathIndex = Bip32HardIndex KeyIndex | Bip32SoftIndex KeyIndex

You would then have Arbitrary instance for Bip32PathIndex, generate a random list of these, and get the hard path from that.

I think I then started using hard/soft index tags in more places in the code, and it was felt this made things unwieldy compared with current approach. I'm considering to try again but striking a more delicate balance.

instance Arbitrary ArbitraryDerivPath

is also affected.

Fix compiler warnings (-Wall) in Evaluator.hs

Network/Haskoin/Script/Evaluator.hs:154:11: Warning:
    This binding for `encode' shadows the existing binding
      imported from `Data.Binary' at Network/Haskoin/Script/Evaluator.hs:52:21-26

Network/Haskoin/Script/Evaluator.hs:238:1: Warning:
    Defined but not used: `rejectSignature'

Network/Haskoin/Script/Evaluator.hs:289:10: Warning:
    This binding for `stack' shadows the existing binding
      defined at Network/Haskoin/Script/Evaluator.hs:94:5

Network/Haskoin/Script/Evaluator.hs:318:1: Warning:
    Defined but not used: `peekStack'

Network/Haskoin/Script/Evaluator.hs:322:5: Warning:
    This binding for `stack' shadows the existing binding
      defined at Network/Haskoin/Script/Evaluator.hs:94:5

There are also some more in the tests to fix.

Possible to create an altcoin using haskcoin?

Hey folks,

I asked this question in IRC some time ago and didn't get an answer. I'm still interested in figuring this out, in particular I'd like to mess with the mining hash function in addition to all the normal parameters. Would I be able to do that with haskoin? If so, could someone write up a brief howto?

Read instances

Write Read instances for data types that have custom Show instances, such that read . show = id

IPv4 addresses serialization glitch (?)

To get correct serialized representation of address for bitcoin protocol, I had to reverse (change endianness) serialized IPv4 address, despite its encoded ByteString output is already in correct endianness. Meanwhile, to add to the confusion, prefix and port number must be left unchanged. This is seen from following function to convert from standard SockAddr:

-- make NetworkAddress from SockAddr
fromSockAddr :: SockAddr -> NetworkAddress
fromSockAddr a = case a of
    --convert to IPv6 mapped IPV4, big endian
    --https://en.bitcoin.it/wiki/Protocol_specification#Network_address
    SockAddrInet pn ha -> let 
        ips = BSL.reverse $ encode ha --WHY this must be reversed?
        Just prefix = hexToBS "0000ffff"
        lower = decode $ BSL.concat [toLazyBS prefix,ips] :: Word64
        ws = (0,lower) :: (Word64,Word64)
        in NetworkAddress 1 ws (fromIntegral pn)
    SockAddrInet6 pn fi ha sid -> let
        ws = decode $ encode ha :: (Word64,Word64)
        in NetworkAddress 1 ws (fromIntegral pn)

Maybe I'm making a mistake due to being a haskell newbie, but IMO the format (Word64,Word64) for NetworkAddress input isn't very well chosen and may cause headaches/bugs in future. I'd suggest to use (Word8, Word8....) instead.

number of transactions excessively high

When syncing the testnet on perra:

Nov 10 22:18:58 perra hw[3905]: Reason: Received an invalid merkle block: extractMatches: number of transactions excessively high
Nov 10 22:18:58 perra hw[3905]: @(hasko_79ftBTTz0e50fQW0XBG2LI:Network.Haskoin.Node.Peer ./Network/Haskoin/Node/Peer.hs:661:15)

Dependency issues in GHC 7.10

GHC 7.10 isn't supported by LTS Haskell, so I try to use a Stackage nightly from https://www.stackage.org/nightly/cabal.config

Of course, I then fall into that altogether unpleasant place known as Cabal hell:

mlg-ell:haskoin mattleon$ cabal install
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: haskoin-0.2.0 (user goal)
next goal: time (dependency of haskoin-0.2.0)
rejecting: time-1.5.0.1/installed-30e... (conflict: haskoin => time>=1.4 &&
<1.5)
rejecting: time-1.5.0.1, 1.5, 1.4.2, 1.4.1, 1.4.0.2, 1.4.0.1, 1.4, 1.3,
1.2.0.5, 1.2.0.4, 1.2.0.3, 1.2.0.2, 1.2.0.1, 1.2, 1.1.4, 1.1.3, 1.1.2.4,
1.1.2.3, 1.1.2.2, 1.1.2.1, 1.1.2.0, 1.0 (global constraint requires installed
instance)
Dependency tree exhaustively searched.

For giggles, I tried --allow-newer as well. It gets surprisingly far and then chokes:

[ 4 of 44] Compiling Network.Haskoin.Script.Types ( Network/Haskoin/Script/Types.hs, dist/build/Network/Haskoin/Script/Types.o )

Network/Haskoin/Script/Types.hs:77:10:
    No instance for (GHC.Generics.Generic PushDataType)
      arising from a use of ‘Control.DeepSeq.$gdmrnf’
    In the expression: Control.DeepSeq.$gdmrnf
    In an equation for ‘rnf’: rnf = Control.DeepSeq.$gdmrnf
    In the instance declaration for ‘NFData PushDataType’
cabal: Error: some packages failed to install:
haskoin-0.2.0 failed during the building phase. The exception was:
ExitFailure 1

Name overlap: coinValue

Ambiguous occurrence `coinValue'
    It could refer to either `Network.Haskoin.Transaction.coinValue',
                             imported from `Network.Haskoin.Transaction' at script/hw.hs:109:1-34
                             (and originally defined in `haskoin-0.0.2.1:Network.Haskoin.Transaction.Builder')
                          or `Network.Haskoin.Stratum.coinValue',
                             imported from `Network.Haskoin.Stratum' at script/hw.hs:110:1-30
                             (and originally defined in `haskoin-0.0.2.1:Network.Haskoin.Stratum.Types')

Wrongly handling DER-encoded length of data

Currently the byte count that an integer value can have as per DER in FieldN is set to be the value of the first octet in the stream. According to DER if the first octet's MSB is 1, the rest of the first octet encodes the number of subsequent octets encoding the length of the integer. If we are to have a maximum size of 32 bytes for FieldN, then we should make sure that the first octet is no larger. This should ensure that deserialization fails in an expected manner for garbage data.

A similar wrong interpretation of the length octet exists in signature deserialization code.

Merge YAML data structures from configuration file

In order to be able to change parameters deep inside YAML data structures in the configuration file, the YAML must merge with default instead of overwriting completely, like Yesod configuration does.

Control.Monad.Error deprecated

It looks like the Control.Monad.Error is being deprecated. We will have to move to Control.Monad.Except.

Network/Haskoin/Script/Evaluator.hs:31:1: Warning:
    Module `Control.Monad.Error' is deprecated:
      Use Control.Monad.Except instead

Network/Haskoin/Script/Evaluator.hs:76:10: Warning:
    In the use of type constructor or class `Error'
    (imported from Control.Monad.Error, but defined in transformers-0.4.1.0:Control.Monad.Trans.Error):
    Deprecated: "Use Control.Monad.Trans.Except instead"

Network/Haskoin/Script/Evaluator.hs:76:10: Warning:
    In the use of type constructor or class `Error'
    (imported from Control.Monad.Error, but defined in transformers-0.4.1.0:Control.Monad.Trans.Error):
    Deprecated: "Use Control.Monad.Trans.Except instead"

Network/Haskoin/Script/Evaluator.hs:77:5: Warning:
    In the use of `noMsg'
    (imported from Control.Monad.Error, but defined in transformers-0.4.1.0:Control.Monad.Trans.Error):
    Deprecated: "Use Control.Monad.Trans.Except instead"

Network/Haskoin/Script/Evaluator.hs:78:5: Warning:
    In the use of `strMsg'
    (imported from Control.Monad.Error, but defined in transformers-0.4.1.0:Control.Monad.Trans.Error):
    Deprecated: "Use Control.Monad.Trans.Except instead"

Network/Haskoin/Script/Evaluator.hs:78:28: Warning:
    In the use of `noMsg'
    (imported from Control.Monad.Error, but defined in transformers-0.4.1.0:Control.Monad.Trans.Error):
    Deprecated: "Use Control.Monad.Trans.Except instead"

Network/Haskoin/Script/Evaluator.hs:122:21: Warning:
    In the use of type constructor or class `ErrorT'
    (imported from Control.Monad.Error, but defined in transformers-0.4.1.0:Control.Monad.Trans.Error):
    Deprecated: "Use Control.Monad.Trans.Except instead"

Network/Haskoin/Script/Evaluator.hs:132:43: Warning:
    In the use of `runErrorT'
    (imported from Control.Monad.Error, but defined in transformers-0.4.1.0:Control.Monad.Trans.Error):
    Deprecated: "Use Control.Monad.Trans.Except instead"

Rename some bip32 types

rename:

HardPath -> AllHardPath

create new new at-least-one hard segment path, and make this new type called HardPath.

per discussion in #200 .

Haskoin Faucet ZeroMQ API hung

Today the faucet's ZeroMQ API hung. The logs do not show any anomaly. I presume that the ZeroMQ API green thread stopped running.

scripts need to be decoded at runtime

a funny thing happend parsing the test suite from the BitcoinQt client

> runTest
Canonical Valid Script Test Cases:
  sig: [0]  pubKey: [IF 0xfd ELSE 1 ENDIF] : [Failed]
can't parse key: "IF 0xfd ELSE 1 ENDIF" error: byte decode error: demandInput: not enough bytes
  sig: [0]  pubKey: [IF 0xfe ELSE 1 ENDIF] : [Failed]
can't parse key: "IF 0xfe ELSE 1 ENDIF" error: byte decode error: Get: Invalid public key encoding

It turns out that the byte sequences 0xfd (OP_PUBKEYHASH) and 0xfd (OP_PUBKEY) inside an unexecuted IF branch are valid and ignored. But when read in an if-branch that is executed, we need to push the subsequent N bytes on the stack.

This prevents us from deserializing the byte sequence statically, meaning we can't use this instance

instance Binary Script where
    get = 
        Script <$> getScriptOps
      where
        getScriptOps = do
            empty <- isEmpty
            if empty 
                then return [] 
                else liftM2 (:) get getScriptOps

    put (Script ops) = forM_ ops put

bip32 public key derivations (starting with capital M) aren't handled correctly

From Network.Haskoin.Crypto.ExtendedKeys.Units.derivePrvPathVectors

, ( xprv, "m/8'", hardSubKey xprv $ XKeyHardIndex 8 )
, ( xprv, "M/8'", hardSubKey xprv $ XKeyHardIndex 8 ) 

this test passes if behavior is identical for M as for m.

I believe the convention is for M to derive a public key. It's a bit sketchy in the bip32 spec but

https://github.com/GemHQ/money-tree has this, and the current repo also has in

Network.Haskoin.Crypto.ExtendedKeys.parrsePath:

pEnd = case x of
    ""  -> Just Deriv
    "m" -> Just DerivPrv
    "M" -> Just DerivPub
    _   -> Nothing

So I think the above test needs fixing.

Right?

Better JSON instance for OutPoint

I found myself feeding an OutPoint in JSON form to an API based on Haskoin that I wrote, and I used the provided JSON instances. I noticed that I must provide a concatenation of the transaction ID with swapped endianness and the output index as eight hexadecimal digits. Not ideal.

Tests do not build

cabal install --enable-tests

tests/Network/Haskoin/Script/Tests.hs:198:10:
    Not in scope: `runProgram'

tests/Network/Haskoin/Script/Tests.hs:290:33:
    Not in scope: `runProgram'

tests/Network/Haskoin/Script/Tests.hs:312:10:
    Not in scope: `runProgram'

Connections do not die

If the blockchain has been synced and the network connection is removed, Haskoin will not disconnect peers. Also, when the connection returns, peers will not be reconnected.

Allow QuickCheck 2.8.1

When installing haskoin after following instructions on the Stackage site to install Haskell in Ubuntu, I must issue --force-reinstalls because QuickCheck is affected by haskoin.

The version of QuickCheck present in the user’s GHC installation depends on the installation of alex and happy that is performed as the last step of Stackage instructions.

Upgrade deepseq to >=1.4?

I am attempting to write an implementation of the BIP-70 Payment Protocol, and would like to take advantage of some of the Haskoin types in my implementation. In the process, I've discovered that the protobuf library (which I need for serialization of the Payment Protocol messages) relies on a more recent version of deepseq than haskoin is using. Would you accept a pull request that upgrades the deepseq version?

Log file is not appended to

When starting a detached hw instance, any existing log file will not be deleted, truncated, or appended to, but instead it will be overwritten. This leads to tools such as tail to show the previous contents of the log file at the end.

Bump dependency version upper limits

Hi

I am using the nightly stackage and GHC 7.10.1. To satisify the stackage nightly dependencies, a few dependency versions need to be bumped.

The relevant stackage versions are:

  • deepseq-1.4.1.1
  • QuickCheck-2.8.1
  • either-4.4.1

I submitted a pull request.

Use typed responses in dispatchers

When dispatching requests, the library will convert to Data.Aeson.Value early instead of using a data type for API responses. It would be good to have that strongly typed.

Getting started

I would like to start hacking and contribute to this project but i can't find any specs for bitcoin protocol? can u give any pointers to any resource. I mean is there an rfc? thanx.

Crashing when connecting to Bitcoin XT node

After syncing the faucet database from my computer to the node running the faucet, I started getting crashes at the start of hw. These crashes stopped when I synced a fresh database and removed the Bitcoin XT node from the list of nodes to connect to, letting it use its hardcoded list instead.

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.