-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from fullstack-development/backend-integration
Backend integration
- Loading branch information
Showing
12 changed files
with
91 additions
and
36 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Ext.Seriaization.Key where | ||
|
||
import Contract.Prelude | ||
|
||
import Contract.Monad (liftContractM, Contract) | ||
import Ctl.Internal.Serialization.Hash (ed25519KeyHashToBech32, ed25519KeyHashFromBech32) | ||
import Ctl.Internal.Types.Aliases (Bech32String) | ||
import Ctl.Internal.Types.PubKeyHash (PaymentPubKeyHash(..), PubKeyHash(..)) | ||
|
||
pkhToBech32 ∷ PaymentPubKeyHash → Maybe Bech32String | ||
pkhToBech32 pkh = ed25519KeyHashToBech32 "addr_vkh" (unwrap $ unwrap pkh) | ||
|
||
pkhFromBech32 ∷ Bech32String → Maybe PaymentPubKeyHash | ||
pkhFromBech32 pkhStr = (PubKeyHash >>> PaymentPubKeyHash) <$> ed25519KeyHashFromBech32 pkhStr | ||
|
||
pkhToBech32M ∷ PaymentPubKeyHash → Contract Bech32String | ||
pkhToBech32M pkh = liftContractM "Impossible to serialize pkh" $ pkhToBech32 pkh | ||
|
||
pkhFromBech32M ∷ Bech32String → Contract PaymentPubKeyHash | ||
pkhFromBech32M pkhStr = liftContractM "Impossible to deserialize pkh" $ pkhFromBech32 pkhStr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Test.Unit.Serialization (suite) where | ||
|
||
import Prelude | ||
|
||
import Ctl.Internal.Serialization.Hash (Ed25519KeyHash, ed25519KeyHashFromBytes) | ||
import Ctl.Internal.Test.TestPlanM (TestPlanM) | ||
import Ctl.Internal.Types.ByteArray (hexToByteArrayUnsafe) | ||
import Ctl.Internal.Types.PubKeyHash (PaymentPubKeyHash(..), PubKeyHash(..)) | ||
import Effect.Aff (Aff) | ||
import Mote (test) | ||
import Partial.Unsafe (unsafePartial) | ||
import Test.Spec.Assertions (shouldEqual) | ||
import Data.Maybe (fromJust, maybe) | ||
import Effect.Class (liftEffect) | ||
import Effect.Exception (throw) | ||
import Ext.Seriaization.Key (pkhFromBech32, pkhToBech32) | ||
|
||
pk :: Ed25519KeyHash | ||
pk = unsafePartial $ fromJust $ ed25519KeyHashFromBytes $ | ||
hexToByteArrayUnsafe | ||
"49d49d1715768d0b9fb498e60a7515e390c744330b91f4a1f6329afa" | ||
|
||
pkh ∷ PaymentPubKeyHash | ||
pkh = PaymentPubKeyHash $ PubKeyHash pk | ||
|
||
suite :: TestPlanM (Aff Unit) Unit | ||
suite = | ||
test "Pkh serialization tests" do | ||
bech32Pkh <- maybe (liftEffect $ throw "Can't serialize pkh to Bech32") pure $ pkhToBech32 pkh | ||
resultPkh <- maybe (liftEffect $ throw "Can't deserialize pkh from Bech32") pure $ pkhFromBech32 bech32Pkh | ||
resultPkh `shouldEqual` pkh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters