aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorÓscar Nájera <hi@oscarnajera.com>2021-07-06 20:52:13 +0200
committerÓscar Nájera <hi@oscarnajera.com>2021-07-06 20:52:13 +0200
commit92c83aae833d979a9e39cfaee109ce06d94dbb34 (patch)
treeb93dc1599d276ec63110ab7983efd73e0341a1b1
parent9dcfc927bcc76ac68b179ce0dac4a75e8b5f6d2f (diff)
downloadprogrammingbitcoin-92c83aae833d979a9e39cfaee109ce06d94dbb34.tar.gz
programmingbitcoin-92c83aae833d979a9e39cfaee109ce06d94dbb34.tar.bz2
programmingbitcoin-92c83aae833d979a9e39cfaee109ce06d94dbb34.zip
Implement monoid for ECPoint
-rw-r--r--ecc.hs7
1 files changed, 7 insertions, 0 deletions
diff --git a/ecc.hs b/ecc.hs
index 0bdbf02..5bc5d8a 100644
--- a/ecc.hs
+++ b/ecc.hs
@@ -104,6 +104,12 @@ binaryExpansion m value result | m == 0 = result
scalarProduct :: (Eq a, Fractional a) => Integer -> ECPoint a -> ECPoint a
scalarProduct m ec = binaryExpansion m ec Infinity
+instance (Eq a, Fractional a) => Semigroup (ECPoint a) where
+ (<>) = add
+
+instance (Eq a, Fractional a) => Monoid (ECPoint a) where
+ mempty = Infinity
+
tre = FieldElement 3 :: FieldElement 31
cc =
let a = ECPoint tre (-7) 5 7
@@ -133,6 +139,7 @@ aPoint = ECPoint 192 105 0 7 :: ECPoint (FieldElement 223)
total = add aPoint $ add aPoint $ add aPoint $ add aPoint aPoint
totalfold=foldr add Infinity $ replicate 5 aPoint
+totalmconcat = mconcat $ replicate 5 aPoint
type S256Field = FieldElement (2 ^ 256- 2^ 32 - 977)
type S256Point = ECPoint S256Field