Skip to content

Commit

Permalink
Sign the commit tx and introduce external key
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch authored and ffakenz committed Jun 5, 2023
1 parent d55cdd8 commit fbe67b0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
5 changes: 5 additions & 0 deletions hydra-cluster/config/credentials/external.sk
@@ -0,0 +1,5 @@
{
"type": "PaymentSigningKeyShelley_ed25519",
"description": "Payment Signing Key",
"cborHex": "582021f918463acee21132aae1c6f508d0c578c5e02010de42347182d46cce301825"
}
5 changes: 5 additions & 0 deletions hydra-cluster/config/credentials/external.vk
@@ -0,0 +1,5 @@
{
"type": "PaymentVerificationKeyShelley_ed25519",
"description": "Payment Verification Key",
"cborHex": "58205818e6c7dcb7248bfe6167b7132570160b0fba9f30c1468f95750a4cdc1f28d1"
}
2 changes: 2 additions & 0 deletions hydra-cluster/src/Hydra/Cluster/Fixture.hs
Expand Up @@ -48,6 +48,7 @@ data Actor
| Bob
| Carol
| Faucet
| External
deriving (Eq, Show)

actorName :: Actor -> String
Expand All @@ -56,6 +57,7 @@ actorName = \case
Bob -> "bob"
Carol -> "carol"
Faucet -> "faucet"
External -> "external"

-- | A network known to the hydra-cluster. That means we have configuration
-- files to connect to at least these networks.
Expand Down
13 changes: 8 additions & 5 deletions hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Expand Up @@ -30,6 +30,7 @@ import HydraNode (EndToEndLog (..), input, output, send, waitFor, waitForAllMatc
import Network.HTTP.Req
import Test.Hspec.Expectations (shouldBe)
import Test.QuickCheck (generate)
import Hydra.Chain.Direct.Wallet (signWith)

restartedNodeCanObserveCommitTx :: Tracer IO EndToEndLog -> FilePath -> RunningNode -> TxId -> IO ()
restartedNodeCanObserveCommitTx tracer workDir cardanoNode hydraScriptsTxId = do
Expand Down Expand Up @@ -148,6 +149,9 @@ singlePartyCommitsFromExternal ::
singlePartyCommitsFromExternal tracer workDir node@RunningNode{networkId} hydraScriptsTxId =
(`finally` returnFundsToFaucet tracer node Alice) $ do
refuelIfNeeded tracer node Alice 25_000_000
refuelIfNeeded tracer node External 25_000_000
-- these keys should mimic external wallet keys needed to sign and submit the commit tx
(externalVk, externalSk) <- keysFor External
-- Start hydra-node on chain tip
tip <- queryTip networkId nodeSocket
let contestationPeriod = UnsafeContestationPeriod 100
Expand All @@ -160,8 +164,7 @@ singlePartyCommitsFromExternal tracer workDir node@RunningNode{networkId} hydraS
send n1 $ input "Init" []
headId <- waitMatch 600 n1 $ headIsInitializingWith (Set.fromList [alice])
utxo <- generate $ do
(vk, _sk) <- genKeyPair
txOut <- genOutput vk
txOut <- genOutput externalVk
txIn <- genTxIn
pure $ UTxO.singleton (txIn, txOut)

Expand All @@ -181,9 +184,9 @@ singlePartyCommitsFromExternal tracer workDir node@RunningNode{networkId} hydraS

let DraftedCommitTx commitTx = responseBody response

-- submit the received draft commit tx using cardano-cli
-- TODO: sign Tx before submit
submitTransaction networkId nodeSocket commitTx
-- sign the received draft commit tx using external key
let signedCommitTx = signWith externalSk commitTx
submitTransaction networkId nodeSocket signedCommitTx

waitFor tracer 600 [n1] $
output "HeadIsOpen" ["utxo" .= utxo, "headId" .= headId]
Expand Down
4 changes: 1 addition & 3 deletions hydra-node/exe/hydra-node/Main.hs
@@ -1,11 +1,10 @@
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE TypeApplications #-}

module Main where

import Hydra.Prelude

import Hydra.API.Server (utxo, withAPIServer)
import Hydra.API.Server (withAPIServer)
import Hydra.Cardano.Api (serialiseToRawBytesHex)
import Hydra.Chain (HeadParameters (..))
import Hydra.Chain.CardanoClient (QueryPoint (..), queryGenesisParameters)
Expand Down Expand Up @@ -155,4 +154,3 @@ main = do
identifyNode :: RunOptions -> RunOptions
identifyNode opt@RunOptions{verbosity = Verbose "HydraNode", nodeId} = opt{verbosity = Verbose $ "HydraNode-" <> show nodeId}
identifyNode opt = opt

1 change: 0 additions & 1 deletion hydra-node/src/Hydra/API/Server.hs
Expand Up @@ -265,7 +265,6 @@ runAPIServer host port party tracer history chain callback headStatusP snapshotU
Left err -> respond $ responseLBS status400 [] (show err)
Right commitTx -> do
let encodedRestOutput = Aeson.encode commitTx
traceShowM commitTx
respond $ responseLBS status200 [] encodedRestOutput
_ -> do
traceWith tracer $
Expand Down

0 comments on commit fbe67b0

Please sign in to comment.