web3-bignum (empty) → 1.0.0.0
raw patch · 6 files changed
+596/−0 lines, 6 filesdep +basedep +cerealdep +hspecsetup-changed
Dependencies added: base, cereal, hspec, hspec-contrib, hspec-discover, hspec-expectations, memory, memory-hexstring, scale, wide-word
Files
- LICENSE +211/−0
- Setup.hs +2/−0
- src/Data/BigNum.hs +141/−0
- tests/Data/BigNum/Test/BigNumSpec.hs +165/−0
- tests/Spec.hs +1/−0
- web3-bignum.cabal +76/−0
+ LICENSE view
@@ -0,0 +1,211 @@+ Apache License+ Version 2.0, January 2004+ http://www.apache.org/licenses/++TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION++1. Definitions.++ "License" shall mean the terms and conditions for use, reproduction,+ and distribution as defined by Sections 1 through 9 of this document.++ "Licensor" shall mean the copyright owner or entity authorized by+ the copyright owner that is granting the License.++ "Legal Entity" shall mean the union of the acting entity and all+ other entities that control, are controlled by, or are under common+ control with that entity. For the purposes of this definition,+ "control" means (i) the power, direct or indirect, to cause the+ direction or management of such entity, whether by contract or+ otherwise, or (ii) ownership of fifty percent (50%) or more of the+ outstanding shares, or (iii) beneficial ownership of such entity.++ "You" (or "Your") shall mean an individual or Legal Entity+ exercising permissions granted by this License.++ "Source" form shall mean the preferred form for making modifications,+ including but not limited to software source code, documentation+ source, and configuration files.++ "Object" form shall mean any form resulting from mechanical+ transformation or translation of a Source form, including but+ not limited to compiled object code, generated documentation,+ and conversions to other media types.++ "Work" shall mean the work of authorship, whether in Source or+ Object form, made available under the License, as indicated by a+ copyright notice that is included in or attached to the work+ (an example is provided in the Appendix below).++ "Derivative Works" shall mean any work, whether in Source or Object+ form, that is based on (or derived from) the Work and for which the+ editorial revisions, annotations, elaborations, or other modifications+ represent, as a whole, an original work of authorship. For the purposes+ of this License, Derivative Works shall not include works that remain+ separable from, or merely link (or bind by name) to the interfaces of,+ the Work and Derivative Works thereof.++ "Contribution" shall mean any work of authorship, including+ the original version of the Work and any modifications or additions+ to that Work or Derivative Works thereof, that is intentionally+ submitted to Licensor for inclusion in the Work by the copyright owner+ or by an individual or Legal Entity authorized to submit on behalf of+ the copyright owner. For the purposes of this definition, "submitted"+ means any form of electronic, verbal, or written communication sent+ to the Licensor or its representatives, including but not limited to+ communication on electronic mailing lists, source code control systems,+ and issue tracking systems that are managed by, or on behalf of, the+ Licensor for the purpose of discussing and improving the Work, but+ excluding communication that is conspicuously marked or otherwise+ designated in writing by the copyright owner as "Not a Contribution."++ "Contributor" shall mean Licensor and any individual or Legal Entity+ on behalf of whom a Contribution has been received by Licensor and+ subsequently incorporated within the Work.++2. Grant of Copyright License. Subject to the terms and conditions of+ this License, each Contributor hereby grants to You a perpetual,+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable+ copyright license to reproduce, prepare Derivative Works of,+ publicly display, publicly perform, sublicense, and distribute the+ Work and such Derivative Works in Source or Object form.++3. Grant of Patent License. Subject to the terms and conditions of+ this License, each Contributor hereby grants to You a perpetual,+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable+ (except as stated in this section) patent license to make, have made,+ use, offer to sell, sell, import, and otherwise transfer the Work,+ where such license applies only to those patent claims licensable+ by such Contributor that are necessarily infringed by their+ Contribution(s) alone or by combination of their Contribution(s)+ with the Work to which such Contribution(s) was submitted. If You+ institute patent litigation against any entity (including a+ cross-claim or counterclaim in a lawsuit) alleging that the Work+ or a Contribution incorporated within the Work constitutes direct+ or contributory patent infringement, then any patent licenses+ granted to You under this License for that Work shall terminate+ as of the date such litigation is filed.++4. Redistribution. You may reproduce and distribute copies of the+ Work or Derivative Works thereof in any medium, with or without+ modifications, and in Source or Object form, provided that You+ meet the following conditions:++ (a) You must give any other recipients of the Work or+ Derivative Works a copy of this License; and++ (b) You must cause any modified files to carry prominent notices+ stating that You changed the files; and++ (c) You must retain, in the Source form of any Derivative Works+ that You distribute, all copyright, patent, trademark, and+ attribution notices from the Source form of the Work,+ excluding those notices that do not pertain to any part of+ the Derivative Works; and++ (d) If the Work includes a "NOTICE" text file as part of its+ distribution, then any Derivative Works that You distribute must+ include a readable copy of the attribution notices contained+ within such NOTICE file, excluding those notices that do not+ pertain to any part of the Derivative Works, in at least one+ of the following places: within a NOTICE text file distributed+ as part of the Derivative Works; within the Source form or+ documentation, if provided along with the Derivative Works; or,+ within a display generated by the Derivative Works, if and+ wherever such third-party notices normally appear. The contents+ of the NOTICE file are for informational purposes only and+ do not modify the License. You may add Your own attribution+ notices within Derivative Works that You distribute, alongside+ or as an addendum to the NOTICE text from the Work, provided+ that such additional attribution notices cannot be construed+ as modifying the License.++ You may add Your own copyright statement to Your modifications and+ may provide additional or different license terms and conditions+ for use, reproduction, or distribution of Your modifications, or+ for any such Derivative Works as a whole, provided Your use,+ reproduction, and distribution of the Work otherwise complies with+ the conditions stated in this License.++5. Submission of Contributions. Unless You explicitly state otherwise,+ any Contribution intentionally submitted for inclusion in the Work+ by You to the Licensor shall be under the terms and conditions of+ this License, without any additional terms or conditions.+ Notwithstanding the above, nothing herein shall supersede or modify+ the terms of any separate license agreement you may have executed+ with Licensor regarding such Contributions.++6. Trademarks. This License does not grant permission to use the trade+ names, trademarks, service marks, or product names of the Licensor,+ except as required for reasonable and customary use in describing the+ origin of the Work and reproducing the content of the NOTICE file.++7. Disclaimer of Warranty. Unless required by applicable law or+ agreed to in writing, Licensor provides the Work (and each+ Contributor provides its Contributions) on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or+ implied, including, without limitation, any warranties or conditions+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A+ PARTICULAR PURPOSE. You are solely responsible for determining the+ appropriateness of using or redistributing the Work and assume any+ risks associated with Your exercise of permissions under this License.++8. Limitation of Liability. In no event and under no legal theory,+ whether in tort (including negligence), contract, or otherwise,+ unless required by applicable law (such as deliberate and grossly+ negligent acts) or agreed to in writing, shall any Contributor be+ liable to You for damages, including any direct, indirect, special,+ incidental, or consequential damages of any character arising as a+ result of this License or out of the use or inability to use the+ Work (including but not limited to damages for loss of goodwill,+ work stoppage, computer failure or malfunction, or any and all+ other commercial damages or losses), even if such Contributor+ has been advised of the possibility of such damages.++9. Accepting Warranty or Additional Liability. While redistributing+ the Work or Derivative Works thereof, You may choose to offer,+ and charge a fee for, acceptance of support, warranty, indemnity,+ or other liability obligations and/or rights consistent with this+ License. However, in accepting such obligations, You may act only+ on Your own behalf and on Your sole responsibility, not on behalf+ of any other Contributor, and only if You agree to indemnify,+ defend, and hold each Contributor harmless for any liability+ incurred by, or claims asserted against, such Contributor by reason+ of your accepting any such warranty or additional liability.++END OF TERMS AND CONDITIONS++APPENDIX: How to apply the Apache License to your work.++ To apply the Apache License to your work, attach the following+ boilerplate notice, with the fields enclosed by brackets "[]"+ replaced with your own identifying information. (Don't include+ the brackets!) The text should be enclosed in the appropriate+ comment syntax for the file format. We also recommend that a+ file or class name and description of purpose be included on the+ same "printed page" as the copyright notice for easier+ identification within third-party archives.++Copyright 2016-2021 Aleksandr Krupenkin ++Licensed under the Apache License, Version 2.0 (the "License");+you may not use this file except in compliance with the License.+You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++Unless required by applicable law or agreed to in writing, software+distributed under the License is distributed on an "AS IS" BASIS,+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+See the License for the specific language governing permissions and+limitations under the License.++ NOTE+ +Individual files contain the following tag instead of the full license+text.++ SPDX-License-Identifier: Apache-2.0++This enables machine processing of license information based on the SPDX+License Identifiers that are here available: http://spdx.org/licenses/
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Data/BigNum.hs view
@@ -0,0 +1,141 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE OverloadedStrings #-}++-- |+-- Module : Data.BigNum+-- Copyright : Aleksandr Krupenkin 2016-2021+-- License : Apache-2.0+--+-- Maintainer : mail@akru.me+-- Stability : experimental+-- Portability : unportable+--+-- Big numbers and codecs for Haskell Web3 library.+--++module Data.BigNum (Word256, Word128, H160, h160, H256, h256, H512, h512) where++import Codec.Scale ()+import Codec.Scale.Class (Decode (..), Encode (..))+import Data.ByteArray (ByteArrayAccess, Bytes,+ convert)+import qualified Data.ByteArray as A (length)+import Data.ByteArray.HexString.Convert (FromHex (..), ToHex (..),+ fromBytes)+import Data.Maybe (fromJust)+import Data.Serialize.Get (getByteString)+import Data.Serialize.Put (putByteString)+import Data.String (IsString (..))+import Data.WideWord.Word128 (Word128 (..))+import Data.WideWord.Word256 (Word256 (..))++instance Encode Word128 where+ put (Word128 l h)= put h >> put l++instance Decode Word128 where+ get = flip Word128 <$> get <*> get++instance Encode Word256 where+ put (Word256 lx hx l h) = do+ put h+ put l+ put hx+ put lx++instance Decode Word256 where+ get = do+ h <- get+ l <- get+ hx <- get+ lx <- get+ return (Word256 lx hx l h)++-- | 20 byte of data.+newtype H160 = H160 Bytes+ deriving (Eq, Ord, ByteArrayAccess)++-- | Convert any 20 byte array into H160 type, otherwise returns Nothing.+h160 :: ByteArrayAccess a => a -> Maybe H160+h160 ba+ | A.length ba == 20 = Just $ H160 (convert ba)+ | otherwise = Nothing++instance FromHex H160 where+ fromHex bs+ | A.length bs == 20 = Right $ H160 (convert bs)+ | otherwise = Left ("wrong length: " ++ show (A.length bs))++instance ToHex H160 where+ toHex = fromBytes++instance Show H160 where+ show = show . toHex++instance IsString H160 where+ fromString = either error id . fromHex . fromString++instance Encode H160 where+ put = putByteString . convert++instance Decode H160 where+ get = (fromJust . h160) <$> getByteString 20++-- | 32 byte of data.+newtype H256 = H256 Bytes+ deriving (Eq, Ord, ByteArrayAccess)++-- | Convert any 32 byte array into H256 type, otherwise returns Nothing.+h256 :: ByteArrayAccess a => a -> Maybe H256+h256 ba+ | A.length ba == 32 = Just $ H256 (convert ba)+ | otherwise = Nothing++instance FromHex H256 where+ fromHex bs+ | A.length bs == 32 = Right $ H256 (convert bs)+ | otherwise = Left ("wrong length: " ++ show (A.length bs))++instance ToHex H256 where+ toHex = fromBytes++instance Show H256 where+ show = show . toHex++instance IsString H256 where+ fromString = either error id . fromHex . fromString++instance Encode H256 where+ put = putByteString . convert++instance Decode H256 where+ get = (fromJust . h256) <$> getByteString 32++-- | 64 byte of data.+newtype H512 = H512 Bytes+ deriving (Eq, Ord, ByteArrayAccess)++-- | Convert any 64 byte array into H512 type, otherwise returns Nothing.+h512 :: ByteArrayAccess a => a -> Maybe H512+h512 ba+ | A.length ba == 64 = Just $ H512 (convert ba)+ | otherwise = Nothing++instance FromHex H512 where+ fromHex bs+ | A.length bs == 64 = Right $ H512 (convert bs)+ | otherwise = Left ("wrong length: " ++ show (A.length bs))++instance ToHex H512 where+ toHex = fromBytes++instance Show H512 where+ show = show . toHex++instance IsString H512 where+ fromString = either error id . fromHex . fromString++instance Encode H512 where+ put = putByteString . convert++instance Decode H512 where+ get = (fromJust . h512) <$> getByteString 64
+ tests/Data/BigNum/Test/BigNumSpec.hs view
@@ -0,0 +1,165 @@+{-# LANGUAGE OverloadedStrings #-}++-- |+-- Module : Data.BigNum.Test.BigNumSpec+-- Copyright : Aleksandr Krupenkin 2016-2021+-- License : Apache-2.0+--+-- Maintainer : mail@akru.me+-- Stability : experimental+-- Portability : unportable+--++module Data.BigNum.Test.BigNumSpec where++import Codec.Scale (decode, encode)+import Control.Monad (forM_)+import Data.ByteArray.HexString (HexString)+import Data.WideWord.Word128 (Word128)+import Data.WideWord.Word256 (Word256)+import Test.Hspec++import Data.BigNum (H160, H256, H512)++u128_TEST_VECTORS :: [(Word128, HexString)]+u128_TEST_VECTORS =+ [ (112009765980327865299926170522124675408, "0x50e91990a464634b4fe24828d64b4454")+ , (284084896039402088792232799153441440599, "0x5783434bc168dc9331cef7fcc3c2b8d5")+ , (259870372860522542774055759705813848487, "0xa791e84af817d01353bcae32993681c3")+ , (12195993515186872808127827346567397926, "0x26025bf77f3914a9da0759c0e7dc2c09")+ , (120025979845686107711254958532305515398, "0x867322183592cf181bfd17c7b1294c5a")+ , (219406308864564522421661310403439556264, "0xa8f6fcd0af3848558244edc0361e10a5")+ , (257335103778365857895651839673319875231, "0x9fe2f88b84b84d90e69d81962ef098c1")+ , (68063227844806979300641114110617889264, "0xf0a9ee1480f359800fba8b7a38803433")+ , (216514484839331230802109899459159104812, "0x2c9d37bee2fc84f8353ba10f482ce3a2")+ , (178182877230765595416853642944570021919, "0x1f587d791c7dacaddc9cfd3b1dc60c86")+ , (290335692238486144820126784978954757396, "0x1425c4fd2f1831eac24a9ef4cf9e6cda")+ , (165504207802320373299850049582381567447, "0xd78d3e18fb99c252d9f20af572f3827c")+ , (47856636672191714454008687982296341606, "0x669c2e67a9bea69ff13aef9d5bda0024")+ , (19215563179501177476867447612060366546, "0xd276ae113fdcf62025309b0669c8740e")+ , (246485718903164524585854064597022275963, "0x7bf9c3072aaa0ad131067568356c6fb9")+ , (197733884573414826455307878816376246254, "0xee4ff5745a481cb00cf2d6d63229c294")+ , (149607475627327219754848974470897887087, "0x6f67a69790aa6b881db0546b0a5a8d70")+ , (174701307382434508318829001328589289972, "0xf4399c820a79a567d4f390c2773f6e83")+ , (72595801292461450864588564249737801167, "0xcfaddd2c4b20d8921f24745d58719d36")+ , (68514076502642919617157448984759680837, "0x45bf3cc99096452a982b6990c6548b33")+ , (216419667485302883317463919550598457261, "0xada77bf03e963b0fd16727cd6ce9d0a2")+ , (116229821064613393178522103562599386123, "0x0bccdb74c7f7a3c2afb443bd9d0c7157")+ , (135932484144247690375718666021027537778, "0x72633955ae336d73c58605dbe7a44366")+ , (30075132366243141139951812090788233488, "0x10c1c6c0cf467e0fe1630a4a8242a016")+ , (110760648836374947274219482463927908576, "0xe0b8c1e1f3221e3cbc6b4b439bb95353")+ , (6493109780355214426871710723177871150, "0x2e7712cb1d7b9819004830580787e204")+ , (155255127434882774479428817682909336706, "0x8294132da02c8966a7b450e5c50ccd74")+ , (249558934561135206340751629864009659619, "0xe3f46e4bfe10c0cbcac4d861704dbfbb")+ , (221130490312110890453383188394454522854, "0xe69bb71f38105bc2ff3c3b27ec2e5ca6")+ , (330501820625969513409631107753191338114, "0x82f05ac2614f264cae56d056d655a4f8")+ , (223256840663930369967277834345880002356, "0x349ff07d428288010a9f53c416b4f5a7")+ , (117046551608311569426455411751697532077, "0xad4480fbf4dceacc06bbc6798a580e58")+ ]++u256_TEST_VECTORS :: [(Word256, HexString)]+u256_TEST_VECTORS =+ [ (115246322816974817869522522728228591410688, "0x009e4a73c70170d062c7cfaacc68b2ad52010000000000000000000000000000")+ , (135938608309138943912299509830613133361152, "0x00003bcac38e0e88ff4be1b553a2d77c8f010000000000000000000000000000")+ , (162382544235100656091613459421755842104320, "0x000c62040d9eb5402b77a94756700c33dd010000000000000000000000000000")+ , (87401399458010888206718906820085474987520, "0x000e25d50cdf0ebc4288bb79603d81d900010000000000000000000000000000")+ , (138984606683918062873256075229427703132672, "0x00b2865449543d0bc4aee7630795657098010000000000000000000000000000")+ , (80840810280826333065693090387807395201024, "0x00402505c662fed033657fec8eb9dd91ed000000000000000000000000000000")+ , (111243980175912604792124852175079091625472, "0x005e221ba2a0291b64cadf565f41abea46010000000000000000000000000000")+ , (68346726659358296375267195304703356056576, "0x00342cd4bdd4aae9d473a64f56bf5cdac8000000000000000000000000000000")+ , (106449215354720188380210893871836123739136, "0x00b469f4f9e50e3c9692eca70c247dd338010000000000000000000000000000")+ , (78137755955119804750893895610892995805184, "0x0040900a46fc58e6681fea1beb6550a0e5000000000000000000000000000000")+ , (37198705638330423439614376452234760232960, "0x002001f5e1b489daa201e473ae1b32516d000000000000000000000000000000")+ , (44433624903109480313359576650777141679616, "0x0096d7f1e43651f716e5dc15b5df249482000000000000000000000000000000")+ , (148514051583354372738620167945095771152896, "0x0062a572ce8903fc0bb00b5c21e98d71b4010000000000000000000000000000")+ , (60014954218248357909848828065675948796928, "0x002cff0f0bf45b444adacc7a76be3b5eb0000000000000000000000000000000")+ , (115991051230925873672644713804764031319040, "0x007ca1f34f6509f519e1fe0979e2f7dd54010000000000000000000000000000")+ , (128993277087652314984111615353153713316352, "0x00a2db3ff8e4ce7452a7afa42c7fc1137b010000000000000000000000000000")+ , (79341042577632633961867710129661883276800, "0x005e51f8c00556a267f89b85cff89029e9000000000000000000000000000000")+ , (107155234040248837193602796138479639672832, "0x0038b9433d32cd48b3b6ab8fc264a3e63a010000000000000000000000000000")+ , (9692096688234458500324617381072327939072, "0x0014383881662b212547f6856fec857b1c000000000000000000000000000000")+ , (153508611663790194252674464693195110905856, "0x0078e84497d0ae7ee3b3c51745310b1fc3010000000000000000000000000000")+ , (82797952396630935803342482248562500762624, "0x00fcc41b53fdb9f05f5023d7e0954152f3000000000000000000000000000000")+ , (42485067285891128074395084374077297656832, "0x00042093afeaf2b88943f460d85336da7c000000000000000000000000000000")+ , (86450357619452627268531966540825354464768, "0x006e167391f2a026579817c9853e050efe000000000000000000000000000000")+ , (66917117614349947545091673512474456381440, "0x0058f0bdece2a5fa4d8e9b97800fd8a6c4000000000000000000000000000000")+ , (41855199301039963483087569366097332165632, "0x005c7e1023c40c3df8c71c308d2a5a007b000000000000000000000000000000")+ , (79447692753915387681092309048730281646080, "0x00184905865a4f806b933431790ccd79e9000000000000000000000000000000")+ , (64972869997286725725114985545674517793792, "0x004c362af3a5b3855e591bde0d9727f0be000000000000000000000000000000")+ , (142291599105260490990206148836714458533888, "0x00500eb253aef52349907156b8274d28a2010000000000000000000000000000")+ , (131059754944904136287166865738657526588416, "0x00246ac6cc16ea922048cd18bea7662681010000000000000000000000000000")+ , (86851548177794395407641645798830201528832, "0x00624a9b253533261c8d6a1936bcd73bff000000000000000000000000000000")+ , (119121986710264787758595765725140587452416, "0x00187946fbafb3f21928d1c1bf1f6c115e010000000000000000000000000000")+ , (75287059147291008379624862024819049134592, "0x007a9e91c390ec87c0b8e9c1e529b03fdd000000000000000000000000000000")+ ]++h160_TEST_VECTORS :: [(H160, HexString)]+h160_TEST_VECTORS =+ [ ("0x52908400098527886E0F7030069857D2E4169EE7", "0x52908400098527886E0F7030069857D2E4169EE7")+ , ("0x8617E340B3D01FA5F11F306F4090FD50E238070D", "0x8617E340B3D01FA5F11F306F4090FD50E238070D")+ , ("0xde709f2102306220921060314715629080e2fb77", "0xde709f2102306220921060314715629080e2fb77")+ , ("0x27b1fdb04752bbc536007a920d24acb045561c26", "0x27b1fdb04752bbc536007a920d24acb045561c26")+ , ("0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed", "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed")+ , ("0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359", "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359")+ , ("0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB", "0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB")+ , ("0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb", "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb")+ ]++h256_TEST_VECTORS :: [(H256, HexString)]+h256_TEST_VECTORS =+ [ ("0xfe700a084ea8882a6661724f3f3277ef5ea9df17cd5291f80c492e537b868518", "0xfe700a084ea8882a6661724f3f3277ef5ea9df17cd5291f80c492e537b868518")+ , ("0xabeedc76bd314edcca6c7fedc0414d05a4979bbd8e17fd4f5d300a9afd953b24", "0xabeedc76bd314edcca6c7fedc0414d05a4979bbd8e17fd4f5d300a9afd953b24")+ , ("0xf1555b382428aeadafa3b9cf4bbd4811d1dac92941c1d741078923844e867c33", "0xf1555b382428aeadafa3b9cf4bbd4811d1dac92941c1d741078923844e867c33")+ , ("0xd959976b19068248aa287290ae7f1c363fcab571c1775dfa16291ecf97d38e11", "0xd959976b19068248aa287290ae7f1c363fcab571c1775dfa16291ecf97d38e11")+ , ("0x2fd7571b66c46c901984e148071b8fe30a5a65cc4a08c3f98b4a753abce3e40b", "0x2fd7571b66c46c901984e148071b8fe30a5a65cc4a08c3f98b4a753abce3e40b")+ , ("0xb09d4a38b291296c08a1b369ca898bfe594fa64bcc942ee5ce18511edb9bbd42", "0xb09d4a38b291296c08a1b369ca898bfe594fa64bcc942ee5ce18511edb9bbd42")+ , ("0x9afd0350d2b7c8d3972478bf76c9c782d587ff3918524ed5de7753cf75386253", "0x9afd0350d2b7c8d3972478bf76c9c782d587ff3918524ed5de7753cf75386253")+ , ("0xebaf4fcbaa6375fa7b6e5fc96166c34ee774221f2f641fdc1b13300306a54b66", "0xebaf4fcbaa6375fa7b6e5fc96166c34ee774221f2f641fdc1b13300306a54b66")+ , ("0x49f7d9bda63d100a60e72b3b5df09f7b19bbe4bf7bb8fd6009ab3bf74c38b4f5", "0x49f7d9bda63d100a60e72b3b5df09f7b19bbe4bf7bb8fd6009ab3bf74c38b4f5")+ , ("0x71b4b1615d1c35332d222abd08008c881aa28975e0f4088ba412fcd6b506eb30", "0x71b4b1615d1c35332d222abd08008c881aa28975e0f4088ba412fcd6b506eb30")+ , ("0xc850252c4c0a14ca0a55bc04077b998139d741ac3ed88db628e02468f3fcc3e6", "0xc850252c4c0a14ca0a55bc04077b998139d741ac3ed88db628e02468f3fcc3e6")+ , ("0x0ae755268da527700201a1b042655f3fde1d9f4bfe990be1998b683d3d5c6597", "0x0ae755268da527700201a1b042655f3fde1d9f4bfe990be1998b683d3d5c6597")+ , ("0xf8caf1ee78b44e90d5dfd99cdcbe0f3b0d45b7d964ce93f60ecfa9af0dc4d1ee", "0xf8caf1ee78b44e90d5dfd99cdcbe0f3b0d45b7d964ce93f60ecfa9af0dc4d1ee")+ , ("0xb9ccbe3823df8602145555f2c6e2e33cfc1cad5c6e053f929c68324a3627d59a", "0xb9ccbe3823df8602145555f2c6e2e33cfc1cad5c6e053f929c68324a3627d59a")+ ]++h512_TEST_VECTORS :: [(H512, HexString)]+h512_TEST_VECTORS =+ [ ("0xfe700a084ea8882a6661724f3f3277ef5ea9df17cd5291f80c492e537b868518fe700a084ea8882a6661724f3f3277ef5ea9df17cd5291f80c492e537b868518", "0xfe700a084ea8882a6661724f3f3277ef5ea9df17cd5291f80c492e537b868518fe700a084ea8882a6661724f3f3277ef5ea9df17cd5291f80c492e537b868518")+ , ("0xabeedc76bd314edcca6c7fedc0414d05a4979bbd8e17fd4f5d300a9afd953b24abeedc76bd314edcca6c7fedc0414d05a4979bbd8e17fd4f5d300a9afd953b24", "0xabeedc76bd314edcca6c7fedc0414d05a4979bbd8e17fd4f5d300a9afd953b24abeedc76bd314edcca6c7fedc0414d05a4979bbd8e17fd4f5d300a9afd953b24")+ , ("0xf1555b382428aeadafa3b9cf4bbd4811d1dac92941c1d741078923844e867c33f1555b382428aeadafa3b9cf4bbd4811d1dac92941c1d741078923844e867c33", "0xf1555b382428aeadafa3b9cf4bbd4811d1dac92941c1d741078923844e867c33f1555b382428aeadafa3b9cf4bbd4811d1dac92941c1d741078923844e867c33")+ , ("0xd959976b19068248aa287290ae7f1c363fcab571c1775dfa16291ecf97d38e11d959976b19068248aa287290ae7f1c363fcab571c1775dfa16291ecf97d38e11", "0xd959976b19068248aa287290ae7f1c363fcab571c1775dfa16291ecf97d38e11d959976b19068248aa287290ae7f1c363fcab571c1775dfa16291ecf97d38e11")+ , ("0x2fd7571b66c46c901984e148071b8fe30a5a65cc4a08c3f98b4a753abce3e40b2fd7571b66c46c901984e148071b8fe30a5a65cc4a08c3f98b4a753abce3e40b", "0x2fd7571b66c46c901984e148071b8fe30a5a65cc4a08c3f98b4a753abce3e40b2fd7571b66c46c901984e148071b8fe30a5a65cc4a08c3f98b4a753abce3e40b")+ , ("0xb09d4a38b291296c08a1b369ca898bfe594fa64bcc942ee5ce18511edb9bbd42b09d4a38b291296c08a1b369ca898bfe594fa64bcc942ee5ce18511edb9bbd42", "0xb09d4a38b291296c08a1b369ca898bfe594fa64bcc942ee5ce18511edb9bbd42b09d4a38b291296c08a1b369ca898bfe594fa64bcc942ee5ce18511edb9bbd42")+ , ("0x9afd0350d2b7c8d3972478bf76c9c782d587ff3918524ed5de7753cf753862539afd0350d2b7c8d3972478bf76c9c782d587ff3918524ed5de7753cf75386253", "0x9afd0350d2b7c8d3972478bf76c9c782d587ff3918524ed5de7753cf753862539afd0350d2b7c8d3972478bf76c9c782d587ff3918524ed5de7753cf75386253")+ , ("0xebaf4fcbaa6375fa7b6e5fc96166c34ee774221f2f641fdc1b13300306a54b66ebaf4fcbaa6375fa7b6e5fc96166c34ee774221f2f641fdc1b13300306a54b66", "0xebaf4fcbaa6375fa7b6e5fc96166c34ee774221f2f641fdc1b13300306a54b66ebaf4fcbaa6375fa7b6e5fc96166c34ee774221f2f641fdc1b13300306a54b66")+ , ("0x49f7d9bda63d100a60e72b3b5df09f7b19bbe4bf7bb8fd6009ab3bf74c38b4f549f7d9bda63d100a60e72b3b5df09f7b19bbe4bf7bb8fd6009ab3bf74c38b4f5", "0x49f7d9bda63d100a60e72b3b5df09f7b19bbe4bf7bb8fd6009ab3bf74c38b4f549f7d9bda63d100a60e72b3b5df09f7b19bbe4bf7bb8fd6009ab3bf74c38b4f5")+ , ("0x71b4b1615d1c35332d222abd08008c881aa28975e0f4088ba412fcd6b506eb3071b4b1615d1c35332d222abd08008c881aa28975e0f4088ba412fcd6b506eb30", "0x71b4b1615d1c35332d222abd08008c881aa28975e0f4088ba412fcd6b506eb3071b4b1615d1c35332d222abd08008c881aa28975e0f4088ba412fcd6b506eb30")+ , ("0xc850252c4c0a14ca0a55bc04077b998139d741ac3ed88db628e02468f3fcc3e6c850252c4c0a14ca0a55bc04077b998139d741ac3ed88db628e02468f3fcc3e6", "0xc850252c4c0a14ca0a55bc04077b998139d741ac3ed88db628e02468f3fcc3e6c850252c4c0a14ca0a55bc04077b998139d741ac3ed88db628e02468f3fcc3e6")+ , ("0x0ae755268da527700201a1b042655f3fde1d9f4bfe990be1998b683d3d5c65970ae755268da527700201a1b042655f3fde1d9f4bfe990be1998b683d3d5c6597", "0x0ae755268da527700201a1b042655f3fde1d9f4bfe990be1998b683d3d5c65970ae755268da527700201a1b042655f3fde1d9f4bfe990be1998b683d3d5c6597")+ , ("0xf8caf1ee78b44e90d5dfd99cdcbe0f3b0d45b7d964ce93f60ecfa9af0dc4d1eef8caf1ee78b44e90d5dfd99cdcbe0f3b0d45b7d964ce93f60ecfa9af0dc4d1ee", "0xf8caf1ee78b44e90d5dfd99cdcbe0f3b0d45b7d964ce93f60ecfa9af0dc4d1eef8caf1ee78b44e90d5dfd99cdcbe0f3b0d45b7d964ce93f60ecfa9af0dc4d1ee")+ , ("0xb9ccbe3823df8602145555f2c6e2e33cfc1cad5c6e053f929c68324a3627d59ab9ccbe3823df8602145555f2c6e2e33cfc1cad5c6e053f929c68324a3627d59a", "0xb9ccbe3823df8602145555f2c6e2e33cfc1cad5c6e053f929c68324a3627d59ab9ccbe3823df8602145555f2c6e2e33cfc1cad5c6e053f929c68324a3627d59a")+ ]++spec :: Spec+spec = parallel $ do+ describe "SCALE tests" $ do+ it "u128 test vectors" $ forM_ u128_TEST_VECTORS $ \(x, l) -> do+ encode x `shouldBe` l+ decode l `shouldBe` Right x++ it "u256 test vectors" $ forM_ u256_TEST_VECTORS $ \(x, l) -> do+ encode x `shouldBe` l+ decode l `shouldBe` Right x++ it "H160 test vectors" $ forM_ h160_TEST_VECTORS $ \(x, l) -> do+ encode x `shouldBe` l+ decode l `shouldBe` Right x++ it "H256 test vectors" $ forM_ h256_TEST_VECTORS $ \(x, l) -> do+ encode x `shouldBe` l+ decode l `shouldBe` Right x++ it "H512 test vectors" $ forM_ h512_TEST_VECTORS $ \(x, l) -> do+ encode x `shouldBe` l+ decode l `shouldBe` Right x
+ tests/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
+ web3-bignum.cabal view
@@ -0,0 +1,76 @@+cabal-version: 1.12+name: web3-bignum+version: 1.0.0.0+license: Apache-2.0+license-file: LICENSE+copyright: (c) Aleksandr Krupenkin 2016-2021+maintainer: mail@akru.me+author: Aleksandr Krupenkin+homepage: https://github.com/airalab/hs-web3#readme+bug-reports: https://github.com/airalab/hs-web3/issues+synopsis: Fixed size big integers for Haskell Web3 library.+description:+ This package implements codec instances and other helper functions.++category: Network+build-type: Simple++source-repository head+ type: git+ location: https://github.com/airalab/hs-web3++library+ exposed-modules: Data.BigNum+ hs-source-dirs: src+ other-modules: Paths_web3_bignum+ default-language: Haskell2010+ ghc-options:+ -funbox-strict-fields -Wduplicate-exports -Whi-shadowing+ -Widentities -Woverlapping-patterns -Wpartial-type-signatures+ -Wunrecognised-pragmas -Wtyped-holes -Wincomplete-patterns+ -Wincomplete-uni-patterns -Wmissing-fields -Wmissing-methods+ -Wmissing-exported-signatures -Wmissing-monadfail-instances+ -Wmissing-signatures -Wname-shadowing -Wunused-binds+ -Wunused-top-binds -Wunused-local-binds -Wunused-pattern-binds+ -Wunused-imports -Wunused-matches -Wunused-foralls -Wtabs++ build-depends:+ base >4.11 && <4.15,+ cereal >0.5 && <0.6,+ memory >0.14 && <0.16,+ memory-hexstring ==1.0.*,+ scale ==1.0.*,+ wide-word >0.1 && <0.2++test-suite tests+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ hs-source-dirs: tests src+ other-modules:+ Data.BigNum.Test.BigNumSpec+ Data.BigNum+ Paths_web3_bignum++ default-language: Haskell2010+ ghc-options:+ -funbox-strict-fields -Wduplicate-exports -Whi-shadowing+ -Widentities -Woverlapping-patterns -Wpartial-type-signatures+ -Wunrecognised-pragmas -Wtyped-holes -Wincomplete-patterns+ -Wincomplete-uni-patterns -Wmissing-fields -Wmissing-methods+ -Wmissing-exported-signatures -Wmissing-monadfail-instances+ -Wmissing-signatures -Wname-shadowing -Wunused-binds+ -Wunused-top-binds -Wunused-local-binds -Wunused-pattern-binds+ -Wunused-imports -Wunused-matches -Wunused-foralls -Wtabs -threaded+ -rtsopts -with-rtsopts=-N++ build-depends:+ base >4.11 && <4.15,+ cereal >0.5 && <0.6,+ hspec >=2.4.4 && <2.8,+ hspec-contrib >=0.4.0 && <0.6,+ hspec-discover >=2.4.4 && <2.8,+ hspec-expectations >=0.8.2 && <0.9,+ memory >0.14 && <0.16,+ memory-hexstring ==1.0.*,+ scale ==1.0.*,+ wide-word >0.1 && <0.2